This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| hyper mio 5747e07 | |
| tick 290af8617 | |
| > wrk -c 100 -d 60 -t2 http://localhost:3000 | |
| Running 1m test @ http://localhost:3000 | |
| 2 threads and 100 connections | |
| Thread Stats Avg Stdev Max +/- Stdev | |
| Latency 1.60ms 533.52us 19.86ms 96.35% | |
| Req/Sec 31.89k 4.17k 39.35k 62.83% | |
| 3808570 requests in 1.00m, 319.63MB read | |
| Requests/sec: 63450.68 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn request_start(self, head: Head, resp: &mut Response, scope: &mut Scope<C>) | |
| -> Option<Self> | |
| { | |
| res.status(hyper::status::StatusCode::Ok); | |
| res.add_header(TransferEncoding(vec![Encoding::Chunked]).unwrap(); | |
| res.done_headers().unwrap(); | |
| self | |
| } | |
| fn request_chunk(self, chunk: &[u8], resp: &mut Response, scope: &mut Scope<C>) | |
| -> Option<Self> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub trait Machine<C>: Sized { | |
| type Seed: Any+Sized; | |
| fn create(seed: Self::Seed, scope: &mut Scope<C>) | |
| -> Result<Self, Box<Error>>; | |
| fn ready(self, events: EventSet, scope: &mut Scope<C>) | |
| -> Response<Self, Self::Seed>; | |
| fn spawned(self, scope: &mut Scope<C>) | |
| -> Response<Self, Self::Seed>; | |
| fn spawn_error(self, _scope: &mut Scope<C>, error: Box<Error>) | |
| -> Option<Self>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "net/http" | |
| ) | |
| func handler(w http.ResponseWriter, r *http.Request) { | |
| fmt.Fprintf(w, "Hello World") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rotor_compose!(enum Composed/Seed <Context> { | |
| Http(HttpMachine), | |
| Dns(DnsMachine), | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Function signature is simplified a bit | |
| fn bytes_received(self, buf, ..) -> Response<..> { | |
| match self { | |
| PacketStart => (PacketLength, Bytes(4), next_timeout()) | |
| PacketLength => { | |
| let len = buf.read_u32(); | |
| (PacketEnd, Bytes(len), next_timeout()) | |
| } | |
| Packet => { | |
| parse_packet(&buf[..]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Most rotor_stream::Protocol actions: | |
| enum Expectation { Bytes(usize), Delimiter(&str) } | |
| Option<(Machine, Expectation, Deadline)> | |
| // rotor_http::Server actions: | |
| enum Mode { Buffered, Progressive } | |
| fn headers_received(..) -> Option<(Machine, Mode, Deadline)>; | |
| fn request_received(..) -> Option<Machine>; | |
| fn request_chunk(..) -> Option<Machine>; | |
| fn timeout(..) -> Option<(Machine, Deadline)>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| impl<M: Sized, N:Sized> Response<M, N> { | |
| pub fn ok(machine: M) -> Response<M, N>; | |
| pub fn spawn(machine: M, result: N) -> Response<M, N>; | |
| pub fn done() -> Response<M, N>; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn new(mut sock: S, seed: P::Seed, scope: &mut Scope<C>) | |
| -> Result<Self, Box<Error>> | |
| { | |
| try!(scope.register(&sock, | |
| EventSet::readable() | EventSet::writable(), PollOpt::edge())); | |
| // ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh -ex | |
| CONTRIBUTOR="Roman Rader <antigluk@gmail.com>" | |
| OVERLAYFS_PATCH="http:\\/\\/people.canonical.com\\/~apw\\/lp1377025-utopic\\/0001-UBUNTU-SAUCE-Overlayfs-allow-unprivileged-mounts.patch" | |
| sed -i.bak "s/# CONFIG_USER_NS is not set/CONFIG_USER_NS=y/" config | |
| sed -i.bak "s/# CONFIG_USER_NS is not set/CONFIG_USER_NS=y/" config.x86_64 | |
| sed -i.bak "/source=/,/)/s/)$/\n$OVERLAYFS_PATCH)/" PKGBUILD | |
| sed -i "s/\# add upstream patch/\# add upstream patch\n patch \-p1 \-i \"\$\{srcdir\}\/`basename $OVERLAYFS_PATCH`\"/" PKGBUILD | |
| sed -i 's/^pkgbase=linux.*$/pkgbase=linux-user-ns-enabled/' PKGBUILD |