Skip to content

Instantly share code, notes, and snippets.

@tailhook
tailhook / hyper-mio.txt
Created February 1, 2016 23:49
Hyper mio/rotor tests
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
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>
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>;
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
}
rotor_compose!(enum Composed/Seed <Context> {
Http(HttpMachine),
Dns(DnsMachine),
});
// 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[..]);
// 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)>;
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>;
}
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()));
// ...
}
@tailhook
tailhook / patch_package.sh
Last active May 1, 2017 10:07
Arch vagga
#!/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