1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 08:39:09 -05:00

Add node_tcp target to http_benchmark. (#1074)

This commit is contained in:
Ryan Dahl 2018-10-23 15:02:30 -07:00 committed by GitHub
parent e9bf206416
commit a4fb5175ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 5 deletions

View file

@ -1,6 +1,7 @@
// Used for benchmarking Deno's networking. See tools/http_benchmark.py // Used for benchmarking Deno's networking. See tools/http_benchmark.py
// TODO Replace this with a real HTTP server once // TODO Replace this with a real HTTP server once
// https://github.com/denoland/deno/issues/726 is completed. // https://github.com/denoland/deno/issues/726 is completed.
// Note: this is a keep-alive server.
import * as deno from "deno"; import * as deno from "deno";
const addr = deno.args[1] || "127.0.0.1:4500"; const addr = deno.args[1] || "127.0.0.1:4500";
const listener = deno.listen("tcp", addr); const listener = deno.listen("tcp", addr);

View file

@ -22,6 +22,12 @@ def node_http_benchmark():
return run(node_cmd) 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): def hyper_http_benchmark(hyper_hello_exe):
hyper_cmd = [hyper_hello_exe, ADDR.split(":")[1]] hyper_cmd = [hyper_hello_exe, ADDR.split(":")[1]]
print "http_benchmark testing RUST hyper." 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): def http_benchmark(deno_exe, hyper_hello_exe):
deno_rps = deno_http_benchmark(deno_exe) r = {}
node_rps = node_http_benchmark() # TODO Rename to "deno_tcp"
hyper_http_rps = hyper_http_benchmark(hyper_hello_exe) r["deno"] = deno_http_benchmark(deno_exe)
r["node"] = node_http_benchmark()
return {"deno": deno_rps, "node": node_rps, "hyper": hyper_http_rps} r["node_tcp"] = node_tcp_benchmark()
r["hyper"] = hyper_http_benchmark(hyper_hello_exe)
return r
def run(server_cmd): def run(server_cmd):

18
tools/node_tcp.js Normal file
View file

@ -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);