From a4fb5175cecc62573eaf3406154ece2938f45b88 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 23 Oct 2018 15:02:30 -0700 Subject: Add node_tcp target to http_benchmark. (#1074) --- tools/http_benchmark.py | 18 +++++++++++++----- tools/node_tcp.js | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tools/node_tcp.js (limited to 'tools') diff --git a/tools/http_benchmark.py b/tools/http_benchmark.py index a039484b7..a2148ba45 100755 --- a/tools/http_benchmark.py +++ b/tools/http_benchmark.py @@ -22,6 +22,12 @@ def node_http_benchmark(): return run(node_cmd) +def node_tcp_benchmark(): + node_cmd = ["node", "tools/node_tcp.js", ADDR.split(":")[1]] + print "http_benchmark testing node_tcp.js" + return run(node_cmd) + + def hyper_http_benchmark(hyper_hello_exe): hyper_cmd = [hyper_hello_exe, ADDR.split(":")[1]] print "http_benchmark testing RUST hyper." @@ -29,11 +35,13 @@ def hyper_http_benchmark(hyper_hello_exe): 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} + r = {} + # TODO Rename to "deno_tcp" + r["deno"] = deno_http_benchmark(deno_exe) + r["node"] = node_http_benchmark() + r["node_tcp"] = node_tcp_benchmark() + r["hyper"] = hyper_http_benchmark(hyper_hello_exe) + return r def run(server_cmd): diff --git a/tools/node_tcp.js b/tools/node_tcp.js new file mode 100644 index 000000000..d4ed6db40 --- /dev/null +++ b/tools/node_tcp.js @@ -0,0 +1,18 @@ +// Copyright 2018 the Deno authors. All rights reserved. MIT license. +// Note: this is a keep-alive server. +const { Server } = require("net"); +const port = process.argv[2] || "4544"; +console.log("port", port); + +const response = Buffer.from( + "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n" +); + +Server(socket => { + socket.on("data", _ => { + socket.write(response); + }); + socket.on("error", _ => { + socket.destroy(); + }); +}).listen(port); -- cgit v1.2.3