summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-06-08 17:33:38 +0530
committerGitHub <noreply@github.com>2022-06-08 17:33:38 +0530
commit4305bb4bd8ec3747031ee92baa8e55d50d22b47c (patch)
tree0bd15f3e8082c7865f246696ec8ce644172ab129 /cli
parent8113fac939c06b0d71a22d008c060bed3cb47d72 (diff)
chore(bench): generalized HTTP benchmarks framework (#14815)
Diffstat (limited to 'cli')
-rw-r--r--cli/bench/http.rs156
-rw-r--r--cli/bench/http/deno_http_native.js (renamed from cli/bench/deno_http_native.js)0
-rw-r--r--cli/bench/http/deno_http_native_headers.js (renamed from cli/bench/deno_http_native_headers.js)0
-rw-r--r--cli/bench/http/deno_tcp.ts (renamed from cli/bench/deno_tcp.ts)0
-rw-r--r--cli/bench/http/node_http.js (renamed from cli/bench/node_http.js)0
-rw-r--r--cli/bench/http/node_tcp.js (renamed from cli/bench/node_tcp.js)0
-rw-r--r--cli/bench/node_tcp_proxy.js69
7 files changed, 62 insertions, 163 deletions
diff --git a/cli/bench/http.rs b/cli/bench/http.rs
index b000bc285..83f8eef8b 100644
--- a/cli/bench/http.rs
+++ b/cli/bench/http.rs
@@ -25,21 +25,62 @@ pub fn benchmark(
let core_http_json_ops_exe = core_http_json_ops_exe.to_str().unwrap();
let mut res = HashMap::new();
+ let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
+ let http_dir = manifest_dir.join("bench").join("http");
+ for entry in std::fs::read_dir(http_dir.clone())? {
+ let entry = entry?;
+ let pathbuf = entry.path();
+ let path = pathbuf.to_str().unwrap();
+ let name = entry.file_name().into_string().unwrap();
+ let file_stem = pathbuf.file_stem().unwrap().to_str().unwrap();
+
+ let lua_script = http_dir.join(format!("{}.lua", file_stem));
+ let mut maybe_lua = None;
+ if lua_script.exists() {
+ maybe_lua = Some(lua_script.to_str().unwrap());
+ }
+
+ let port = get_port();
+ if name.starts_with("node") {
+ // node <path> <port>
+ res.insert(
+ name,
+ run(
+ &["node", path, &port.to_string()],
+ port,
+ None,
+ None,
+ maybe_lua,
+ )?,
+ );
+ } else {
+ // deno run -A --unstable <path> <addr>
+ res.insert(
+ name,
+ run(
+ &[
+ deno_exe,
+ "run",
+ "--allow-all",
+ "--unstable",
+ path,
+ &server_addr(port),
+ ],
+ port,
+ None,
+ None,
+ maybe_lua,
+ )?,
+ );
+ }
+ }
- // "deno_tcp" was once called "deno"
- res.insert("deno_tcp".to_string(), deno_tcp(deno_exe)?);
- // res.insert("deno_udp".to_string(), deno_udp(deno_exe)?);
- res.insert("deno_http".to_string(), deno_http(deno_exe)?);
- res.insert("deno_http_native".to_string(), deno_http_native(deno_exe)?);
// "core_http_json_ops" previously had a "bin op" counterpart called "core_http_bin_ops",
// which was previously also called "deno_core_http_bench", "deno_core_single"
res.insert(
"core_http_json_ops".to_string(),
core_http_json_ops(core_http_json_ops_exe)?,
);
- // "node_http" was once called "node"
- res.insert("node_http".to_string(), node_http()?);
- res.insert("node_tcp".to_string(), node_tcp()?);
res.insert("hyper".to_string(), hyper_http(hyper_hello_exe)?);
Ok(res)
@@ -50,6 +91,7 @@ fn run(
port: u16,
env: Option<Vec<(String, String)>>,
origin_cmd: Option<&[&str]>,
+ lua_script: Option<&str>,
) -> Result<HttpBenchmarkResult> {
// Wait for port 4544 to become available.
// TODO Need to use SO_REUSEPORT with tokio::net::TcpListener.
@@ -80,15 +122,17 @@ fn run(
let wrk = test_util::prebuilt_tool_path("wrk");
assert!(wrk.is_file());
- let wrk_cmd = &[
- wrk.to_str().unwrap(),
- "-d",
- DURATION,
- "--latency",
- &format!("http://127.0.0.1:{}/", port),
- ];
+ let addr = format!("http://127.0.0.1:{}/", port);
+ let mut wrk_cmd =
+ vec![wrk.to_str().unwrap(), "-d", DURATION, "--latency", &addr];
+
+ if let Some(lua_script) = lua_script {
+ wrk_cmd.push("-s");
+ wrk_cmd.push(lua_script);
+ }
+
println!("{}", wrk_cmd.join(" "));
- let output = test_util::run_collect(wrk_cmd, None, None, None, true).0;
+ let output = test_util::run_collect(&wrk_cmd, None, None, None, true).0;
std::thread::sleep(Duration::from_secs(1)); // wait to capture failure. TODO racy.
@@ -122,89 +166,13 @@ fn server_addr(port: u16) -> String {
format!("0.0.0.0:{}", port)
}
-fn deno_tcp(deno_exe: &str) -> Result<HttpBenchmarkResult> {
- let port = get_port();
- println!("http_benchmark testing DENO tcp.");
- run(
- &[
- deno_exe,
- "run",
- "--allow-net",
- "cli/bench/deno_tcp.ts",
- &server_addr(port),
- ],
- port,
- None,
- None,
- )
-}
-
-fn deno_http(deno_exe: &str) -> Result<HttpBenchmarkResult> {
- let port = get_port();
- println!("http_benchmark testing DENO using net/http.");
- run(
- &[
- deno_exe,
- "run",
- "--allow-net",
- "--reload",
- "--unstable",
- "test_util/std/http/bench.ts",
- &server_addr(port),
- ],
- port,
- None,
- None,
- )
-}
-
-fn deno_http_native(deno_exe: &str) -> Result<HttpBenchmarkResult> {
- let port = get_port();
- println!("http_benchmark testing DENO using native bindings.");
- run(
- &[
- deno_exe,
- "run",
- "--allow-net",
- "--reload",
- "cli/bench/deno_http_native.js",
- &server_addr(port),
- ],
- port,
- None,
- None,
- )
-}
-
fn core_http_json_ops(exe: &str) -> Result<HttpBenchmarkResult> {
println!("http_benchmark testing CORE http_bench_json_ops");
- run(&[exe], 4544, None, None)
-}
-
-fn node_http() -> Result<HttpBenchmarkResult> {
- let port = get_port();
- println!("http_benchmark testing NODE.");
- run(
- &["node", "cli/bench/node_http.js", &port.to_string()],
- port,
- None,
- None,
- )
-}
-
-fn node_tcp() -> Result<HttpBenchmarkResult> {
- let port = get_port();
- println!("http_benchmark testing node_tcp.js");
- run(
- &["node", "cli/bench/node_tcp.js", &port.to_string()],
- port,
- None,
- None,
- )
+ run(&[exe], 4544, None, None, None)
}
fn hyper_http(exe: &str) -> Result<HttpBenchmarkResult> {
let port = get_port();
println!("http_benchmark testing RUST hyper");
- run(&[exe, &port.to_string()], port, None, None)
+ run(&[exe, &port.to_string()], port, None, None, None)
}
diff --git a/cli/bench/deno_http_native.js b/cli/bench/http/deno_http_native.js
index a45416ada..a45416ada 100644
--- a/cli/bench/deno_http_native.js
+++ b/cli/bench/http/deno_http_native.js
diff --git a/cli/bench/deno_http_native_headers.js b/cli/bench/http/deno_http_native_headers.js
index 23ef1e060..23ef1e060 100644
--- a/cli/bench/deno_http_native_headers.js
+++ b/cli/bench/http/deno_http_native_headers.js
diff --git a/cli/bench/deno_tcp.ts b/cli/bench/http/deno_tcp.ts
index 43b4d2264..43b4d2264 100644
--- a/cli/bench/deno_tcp.ts
+++ b/cli/bench/http/deno_tcp.ts
diff --git a/cli/bench/node_http.js b/cli/bench/http/node_http.js
index 3380c86a5..3380c86a5 100644
--- a/cli/bench/node_http.js
+++ b/cli/bench/http/node_http.js
diff --git a/cli/bench/node_tcp.js b/cli/bench/http/node_tcp.js
index cb51a63a5..cb51a63a5 100644
--- a/cli/bench/node_tcp.js
+++ b/cli/bench/http/node_tcp.js
diff --git a/cli/bench/node_tcp_proxy.js b/cli/bench/node_tcp_proxy.js
deleted file mode 100644
index 8b4b958d7..000000000
--- a/cli/bench/node_tcp_proxy.js
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-const net = require("net");
-
-process.on("uncaughtException", function (error) {
- console.error(error);
-});
-
-if (process.argv.length != 4) {
- console.log("usage: %s <localport> <remoteport>", process.argv[1]);
- process.exit();
-}
-
-const localport = process.argv[2];
-const remoteport = process.argv[3];
-
-const remotehost = "127.0.0.1";
-
-const server = net.createServer(function (localsocket) {
- const remotesocket = new net.Socket();
-
- remotesocket.connect(remoteport, remotehost);
-
- localsocket.on("data", function (data) {
- const flushed = remotesocket.write(data);
- if (!flushed) {
- localsocket.pause();
- }
- });
-
- remotesocket.on("data", function (data) {
- const flushed = localsocket.write(data);
- if (!flushed) {
- remotesocket.pause();
- }
- });
-
- localsocket.on("drain", function () {
- remotesocket.resume();
- });
-
- remotesocket.on("drain", function () {
- localsocket.resume();
- });
-
- localsocket.on("close", function () {
- remotesocket.end();
- });
-
- remotesocket.on("close", function () {
- localsocket.end();
- });
-
- localsocket.on("error", function () {
- localsocket.end();
- });
-
- remotesocket.on("error", function () {
- remotesocket.end();
- });
-});
-
-server.listen(localport);
-
-console.log(
- "redirecting connections from 127.0.0.1:%d to %s:%d",
- localport,
- remotehost,
- remoteport,
-);