Skip to content

Commit

Permalink
Add Rust hyper http benchmark (denoland#1043)
Browse files Browse the repository at this point in the history
* Add go net/http benchmark

* Forget about Go. Let's do Rust Hyper

* Update BUILD.gn

* Rename
  • Loading branch information
kevinkassimo authored and ry committed Oct 21, 2018
1 parent c85311d commit 86409eb
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
9 changes: 9 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ group("default") {
deps = [
":deno",
":deno_ns",
":hyper_hello",
":test_cc",
":test_rs",
]
Expand Down Expand Up @@ -137,6 +138,14 @@ rust_executable("deno_ns") {
]
}

rust_executable("hyper_hello") {
source_root = "tools/hyper_hello.rs"
extern = [
"$rust_build:hyper",
"$rust_build:ring"
]
}

rust_test("test_rs") {
source_root = "src/main.rs"
extern = main_extern
Expand Down
3 changes: 2 additions & 1 deletion tools/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ def main(argv):
# Cannot run throughput benchmark on windows because they don't have nc or
# pipe.
if os.name != 'nt':
hyper_hello_path = os.path.join(build_dir, "hyper_hello")
new_data["throughput"] = run_throughput(deno_path)
new_data["req_per_sec"] = http_benchmark(deno_path)
new_data["req_per_sec"] = http_benchmark(deno_path, hyper_hello_path)
if "linux" in sys.platform:
# Thread count test, only on linux
new_data["thread_count"] = run_thread_count_benchmark(deno_path)
Expand Down
21 changes: 16 additions & 5 deletions tools/http_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,28 @@ def deno_http_benchmark(deno_exe):
return run(deno_cmd)


def node_http_benchmark(deno_exe):
def node_http_benchmark():
node_cmd = ["node", "tools/node_http.js", ADDR.split(":")[1]]
print "http_benchmark testing NODE."
return run(node_cmd)


def http_benchmark(deno_exe):
deno_rps = deno_http_benchmark(deno_exe)
node_rps = node_http_benchmark(deno_exe)
def hyper_http_benchmark(hyper_hello_exe):
hyper_cmd = [hyper_hello_exe, ADDR.split(":")[1]]
print "http_benchmark testing RUST hyper."
return run(hyper_cmd)


return {"deno": deno_rps, "node": node_rps}
def http_benchmark(deno_exe, hyper_hello_exe):
deno_rps = deno_http_benchmark(deno_exe)
node_rps = node_http_benchmark()
hyper_http_rps = hyper_http_benchmark(hyper_hello_exe)

return {
"deno": deno_rps,
"node": node_rps,
"hyper": hyper_http_rps
}


def run(server_cmd):
Expand Down
40 changes: 40 additions & 0 deletions tools/hyper_hello.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// Adapted from https://github.com/hyperium/hyper/blob/master/examples/hello.rs

#![deny(warnings)]
extern crate hyper;

use std::env;
use hyper::{Body, Response, Server};
use hyper::service::service_fn_ok;
use hyper::rt::{self, Future};

static PHRASE: &'static [u8] = b"Hello World!";

fn main() {
let mut port: u16 = 4544;
if let Some(custom_port) = env::args().nth(1) {
port = custom_port.parse::<u16>().unwrap();
}

let addr = ([127, 0, 0, 1], port).into();

// new_service is run for each connection, creating a 'service'
// to handle requests for that specific connection.
let new_service = || {
// This is the `Service` that will handle the connection.
// `service_fn_ok` is a helper to convert a function that
// returns a Response into a `Service`.
service_fn_ok(|_| {
Response::new(Body::from(PHRASE))
})
};

let server = Server::bind(&addr)
.serve(new_service)
.map_err(|e| eprintln!("server error: {}", e));

println!("Listening on http:https://{}", addr);

rt::run(server);
}

0 comments on commit 86409eb

Please sign in to comment.