提交 86409eb8 编写于 作者: K Kevin (Kun) "Kassimo" Qian 提交者: Ryan Dahl

Add Rust hyper http benchmark (#1043)

* Add go net/http benchmark

* Forget about Go. Let's do Rust Hyper

* Update BUILD.gn

* Rename
上级 c85311dd
......@@ -13,6 +13,7 @@ group("default") {
deps = [
":deno",
":deno_ns",
":hyper_hello",
":test_cc",
":test_rs",
]
......@@ -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
......
......@@ -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)
......
......@@ -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):
......
// 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://{}", addr);
rt::run(server);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册