2018-10-15 16:44:35 -04:00
|
|
|
#!/usr/bin/env python
|
2019-01-21 14:03:30 -05:00
|
|
|
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-10-15 16:44:35 -04:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import util
|
|
|
|
import time
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
ADDR = "127.0.0.1:4544"
|
|
|
|
DURATION = "10s"
|
|
|
|
|
|
|
|
|
2018-10-16 21:02:16 -04:00
|
|
|
def deno_http_benchmark(deno_exe):
|
2018-10-15 16:44:35 -04:00
|
|
|
deno_cmd = [deno_exe, "--allow-net", "tests/http_bench.ts", ADDR]
|
|
|
|
print "http_benchmark testing DENO."
|
2018-10-16 21:02:16 -04:00
|
|
|
return run(deno_cmd)
|
|
|
|
|
2018-10-15 16:44:35 -04:00
|
|
|
|
2018-12-07 16:36:16 -05:00
|
|
|
def deno_net_http_benchmark(deno_exe):
|
|
|
|
deno_cmd = [
|
2018-12-23 18:22:14 -05:00
|
|
|
deno_exe, "--allow-net",
|
2019-03-06 10:23:47 -05:00
|
|
|
"js/deps/https/deno.land/std/http/http_bench.ts", ADDR
|
2018-12-07 16:36:16 -05:00
|
|
|
]
|
|
|
|
print "http_benchmark testing DENO using net/http."
|
|
|
|
return run(
|
|
|
|
deno_cmd,
|
|
|
|
merge_env={
|
|
|
|
# Load from //js/deps/https/deno.land/net/ submodule.
|
|
|
|
"DENO_DIR": os.path.join(util.root_path, "js")
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2019-02-26 17:36:05 -05:00
|
|
|
def deno_core_single(exe):
|
|
|
|
print "http_benchmark testing deno_core_single"
|
|
|
|
return run([exe, "--single-thread"])
|
|
|
|
|
|
|
|
|
|
|
|
def deno_core_multi(exe):
|
|
|
|
print "http_benchmark testing deno_core_multi"
|
|
|
|
return run([exe, "--multi-thread"])
|
|
|
|
|
|
|
|
|
2018-10-20 22:56:16 -04:00
|
|
|
def node_http_benchmark():
|
2018-10-16 21:02:16 -04:00
|
|
|
node_cmd = ["node", "tools/node_http.js", ADDR.split(":")[1]]
|
2018-10-15 16:44:35 -04:00
|
|
|
print "http_benchmark testing NODE."
|
2018-10-16 21:02:16 -04:00
|
|
|
return run(node_cmd)
|
|
|
|
|
|
|
|
|
2018-10-23 18:02:30 -04:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2018-10-20 22:56:16 -04:00
|
|
|
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)
|
|
|
|
|
2018-10-15 16:44:35 -04:00
|
|
|
|
2019-02-26 17:36:05 -05:00
|
|
|
def http_benchmark(deno_exe, hyper_hello_exe, core_http_bench_exe):
|
2018-10-23 18:02:30 -04:00
|
|
|
r = {}
|
|
|
|
# TODO Rename to "deno_tcp"
|
|
|
|
r["deno"] = deno_http_benchmark(deno_exe)
|
2018-12-07 16:36:16 -05:00
|
|
|
r["deno_net_http"] = deno_net_http_benchmark(deno_exe)
|
2019-02-26 17:36:05 -05:00
|
|
|
r["deno_core_single"] = deno_core_single(core_http_bench_exe)
|
|
|
|
r["deno_core_multi"] = deno_core_multi(core_http_bench_exe)
|
2018-10-23 18:02:30 -04:00
|
|
|
r["node"] = node_http_benchmark()
|
|
|
|
r["node_tcp"] = node_tcp_benchmark()
|
|
|
|
r["hyper"] = hyper_http_benchmark(hyper_hello_exe)
|
|
|
|
return r
|
2018-10-15 16:44:35 -04:00
|
|
|
|
|
|
|
|
2018-12-07 16:36:16 -05:00
|
|
|
def run(server_cmd, merge_env=None):
|
2018-10-15 16:44:35 -04:00
|
|
|
# Run deno echo server in the background.
|
2018-12-07 16:36:16 -05:00
|
|
|
if merge_env is None:
|
|
|
|
env = None
|
|
|
|
else:
|
|
|
|
env = os.environ.copy()
|
|
|
|
for key, value in merge_env.iteritems():
|
|
|
|
env[key] = value
|
|
|
|
|
2019-02-26 17:36:05 -05:00
|
|
|
# Wait for port 4544 to become available.
|
|
|
|
# TODO Need to use SO_REUSEPORT with tokio::net::TcpListener.
|
|
|
|
time.sleep(5)
|
|
|
|
|
2018-12-07 16:36:16 -05:00
|
|
|
server = subprocess.Popen(server_cmd, env=env)
|
2019-02-26 17:36:05 -05:00
|
|
|
|
2018-10-15 16:44:35 -04:00
|
|
|
time.sleep(5) # wait for server to wake up. TODO racy.
|
2019-02-26 17:36:05 -05:00
|
|
|
|
2018-10-15 16:44:35 -04:00
|
|
|
try:
|
2018-10-19 19:15:14 -04:00
|
|
|
cmd = "third_party/wrk/%s/wrk -d %s http://%s/" % (util.platform(),
|
|
|
|
DURATION, ADDR)
|
2018-10-15 16:44:35 -04:00
|
|
|
print cmd
|
|
|
|
output = subprocess.check_output(cmd, shell=True)
|
|
|
|
req_per_sec = util.parse_wrk_output(output)
|
|
|
|
print output
|
|
|
|
return req_per_sec
|
|
|
|
finally:
|
|
|
|
server.kill()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) < 2:
|
2018-11-08 13:38:20 -05:00
|
|
|
print "Usage ./tools/http_benchmark.py target/debug/deno"
|
2018-10-15 16:44:35 -04:00
|
|
|
sys.exit(1)
|
2018-12-07 16:36:16 -05:00
|
|
|
deno_net_http_benchmark(sys.argv[1])
|