1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

Use 0.0.0.0 for servers in benchmarks and tests (#3010)

This commit is contained in:
Ryan Dahl 2019-09-30 12:35:48 -04:00 committed by GitHub
parent c8a5d9c585
commit 5f7ab4884c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 64 deletions

View file

@ -1,5 +1,5 @@
const { args, listen, copy } = Deno;
const addr = args[1] || "127.0.0.1:4544";
const addr = args[1] || "0.0.0.0:4544";
const [hostname, port] = addr.split(":");
const listener = listen({ hostname, port: Number(port) });
console.log("listening on", addr);

View file

@ -17,128 +17,133 @@ DURATION = "10s"
LAST_PORT = 4544
def get_addr(port=None):
def server_addr(port):
return "0.0.0.0:%s" % port
def get_port(port=None):
global LAST_PORT
if port is None:
port = LAST_PORT
LAST_PORT = LAST_PORT + 1
return ("127.0.0.1:%d" % (port))
# Return port as str because all usages below are as a str and having it an
# integer just adds complexity.
return str(port)
def deno_tcp(deno_exe):
addr = get_addr()
deno_cmd = [deno_exe, "run", "--allow-net", "tools/deno_tcp.ts", addr]
port = get_port()
deno_cmd = [
deno_exe, "run", "--allow-net", "tools/deno_tcp.ts",
server_addr(port)
]
print "http_benchmark testing DENO tcp."
return run(deno_cmd, addr)
return run(deno_cmd, port)
def deno_tcp_current_thread(deno_exe):
addr = get_addr()
port = get_port()
deno_cmd = [
deno_exe, "run", "--current-thread", "--allow-net",
"tools/deno_tcp.ts", addr
"tools/deno_tcp.ts",
server_addr(port)
]
print "http_benchmark testing DENO tcp (single-thread)."
return run(deno_cmd, addr)
return run(deno_cmd, port)
def deno_http(deno_exe):
addr = get_addr()
port = get_port()
deno_cmd = [
deno_exe, "run", "--allow-net",
"js/deps/https/deno.land/std/http/http_bench.ts", addr
"js/deps/https/deno.land/std/http/http_bench.ts",
server_addr(port)
]
print "http_benchmark testing DENO using net/http."
return run(deno_cmd, addr)
return run(deno_cmd, port)
def deno_tcp_proxy(deno_exe, hyper_hello_exe):
addr = get_addr()
origin_addr = get_addr()
port = get_port()
origin_port = get_port()
deno_cmd = [
deno_exe, "run", "--allow-net", "tools/deno_tcp_proxy.ts", addr,
origin_addr
deno_exe, "run", "--allow-net", "tools/deno_tcp_proxy.ts",
server_addr(port),
server_addr(origin_port)
]
print "http_proxy_benchmark testing DENO using net/tcp."
return run(
deno_cmd,
addr,
origin_cmd=http_proxy_origin(hyper_hello_exe, origin_addr))
port,
origin_cmd=http_proxy_origin(hyper_hello_exe, origin_port))
def deno_http_proxy(deno_exe, hyper_hello_exe):
addr = get_addr()
origin_addr = get_addr()
port = get_port()
origin_port = get_port()
deno_cmd = [
deno_exe, "run", "--allow-net", "tools/deno_http_proxy.ts", addr,
origin_addr
deno_exe, "run", "--allow-net", "tools/deno_http_proxy.ts",
server_addr(port),
server_addr(origin_port)
]
print "http_proxy_benchmark testing DENO using net/http."
return run(
deno_cmd,
addr,
origin_cmd=http_proxy_origin(hyper_hello_exe, origin_addr))
port,
origin_cmd=http_proxy_origin(hyper_hello_exe, origin_port))
def deno_core_single(exe):
print "http_benchmark testing deno_core_single"
return run([exe, "--single-thread"], "127.0.0.1:4544")
return run([exe, "--single-thread"], 4544)
def deno_core_multi(exe):
print "http_benchmark testing deno_core_multi"
return run([exe, "--multi-thread"], "127.0.0.1:4544")
return run([exe, "--multi-thread"], 4544)
def node_http():
addr = get_addr()
node_cmd = ["node", "tools/node_http.js", addr.split(":")[1]]
port = get_port()
node_cmd = ["node", "tools/node_http.js", port]
print "http_benchmark testing NODE."
return run(node_cmd, addr)
return run(node_cmd, port)
def node_http_proxy(hyper_hello_exe):
addr = get_addr()
origin_addr = get_addr()
node_cmd = [
"node", "tools/node_http_proxy.js",
addr.split(":")[1],
origin_addr.split(":")[1]
]
port = get_port()
origin_port = get_port()
node_cmd = ["node", "tools/node_http_proxy.js", port, origin_port]
print "http_proxy_benchmark testing NODE."
return run(node_cmd, addr, None,
http_proxy_origin(hyper_hello_exe, origin_addr))
return run(node_cmd, port, None,
http_proxy_origin(hyper_hello_exe, origin_port))
def node_tcp_proxy(hyper_hello_exe):
addr = get_addr()
origin_addr = get_addr()
node_cmd = [
"node", "tools/node_tcp_proxy.js",
addr.split(":")[1],
origin_addr.split(":")[1]
]
port = get_port()
origin_port = get_port()
node_cmd = ["node", "tools/node_tcp_proxy.js", port, origin_port]
print "http_proxy_benchmark testing NODE tcp."
return run(node_cmd, addr, None,
http_proxy_origin(hyper_hello_exe, origin_addr))
return run(node_cmd, port, None,
http_proxy_origin(hyper_hello_exe, origin_port))
def node_tcp():
addr = get_addr()
node_cmd = ["node", "tools/node_tcp.js", addr.split(":")[1]]
port = get_port()
node_cmd = ["node", "tools/node_tcp.js", port]
print "http_benchmark testing node_tcp.js"
return run(node_cmd, addr)
return run(node_cmd, port)
def http_proxy_origin(hyper_hello_exe, addr):
return [hyper_hello_exe, addr.split(":")[1]]
def http_proxy_origin(hyper_hello_exe, port):
return [hyper_hello_exe, port]
def hyper_http(hyper_hello_exe):
addr = get_addr()
hyper_cmd = [hyper_hello_exe, addr.split(":")[1]]
port = get_port()
hyper_cmd = [hyper_hello_exe, port]
print "http_benchmark testing RUST hyper."
return run(hyper_cmd, addr)
return run(hyper_cmd, port)
def http_benchmark(build_dir):
@ -165,7 +170,7 @@ def http_benchmark(build_dir):
}
def run(server_cmd, addr, merge_env=None, origin_cmd=None):
def run(server_cmd, port, merge_env=None, origin_cmd=None):
# Run deno echo server in the background.
if merge_env is None:
@ -183,13 +188,14 @@ def run(server_cmd, addr, merge_env=None, origin_cmd=None):
if origin_cmd is not None:
origin = subprocess.Popen(origin_cmd, env=env)
print server_cmd
server = subprocess.Popen(server_cmd, env=env)
time.sleep(10) # wait for server to wake up. TODO racy.
time.sleep(5) # wait for server to wake up. TODO racy.
try:
cmd = "third_party/wrk/%s/wrk -d %s --latency http://%s/" % (
util.platform(), DURATION, addr)
cmd = "third_party/wrk/%s/wrk -d %s --latency http://127.0.0.1:%s/" % (
util.platform(), DURATION, port)
print cmd
output = subprocess.check_output(cmd, shell=True)
stats = util.parse_wrk_output(output)

View file

@ -13,7 +13,8 @@ import subprocess
import util
MB = 1024 * 1024
ADDR = "127.0.0.1:4544"
SERVER_ADDR = "0.0.0.0:4544"
CLIENT_ADDR = "127.0.0.1 4544"
def cat(deno_exe, megs):
@ -30,14 +31,17 @@ def cat(deno_exe, megs):
def tcp(deno_exe, megs):
size = megs * MB
# Run deno echo server in the background.
echo_server = subprocess.Popen(
[deno_exe, "run", "--allow-net", "tests/echo_server.ts", ADDR])
args = [
deno_exe, "run", "--allow-net", "tests/echo_server.ts", SERVER_ADDR
]
print args
echo_server = subprocess.Popen(args)
time.sleep(5) # wait for deno to wake up. TODO racy.
try:
start = time.time()
cmd = ("head -c %s /dev/zero " % size) + "| nc " + ADDR.replace(
":", " ")
nc_cmd = "nc " + CLIENT_ADDR
cmd = ("head -c %s /dev/zero " % size) + " | " + nc_cmd
print cmd
subprocess.check_output(cmd, shell=True)
end = time.time()