mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
Use 0.0.0.0 for servers in benchmarks and tests (#3010)
This commit is contained in:
parent
c8a5d9c585
commit
5f7ab4884c
3 changed files with 74 additions and 64 deletions
|
@ -1,5 +1,5 @@
|
||||||
const { args, listen, copy } = Deno;
|
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 [hostname, port] = addr.split(":");
|
||||||
const listener = listen({ hostname, port: Number(port) });
|
const listener = listen({ hostname, port: Number(port) });
|
||||||
console.log("listening on", addr);
|
console.log("listening on", addr);
|
||||||
|
|
|
@ -17,128 +17,133 @@ DURATION = "10s"
|
||||||
LAST_PORT = 4544
|
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
|
global LAST_PORT
|
||||||
if port is None:
|
if port is None:
|
||||||
port = LAST_PORT
|
port = LAST_PORT
|
||||||
LAST_PORT = LAST_PORT + 1
|
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):
|
def deno_tcp(deno_exe):
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
deno_cmd = [deno_exe, "run", "--allow-net", "tools/deno_tcp.ts", addr]
|
deno_cmd = [
|
||||||
|
deno_exe, "run", "--allow-net", "tools/deno_tcp.ts",
|
||||||
|
server_addr(port)
|
||||||
|
]
|
||||||
print "http_benchmark testing DENO tcp."
|
print "http_benchmark testing DENO tcp."
|
||||||
return run(deno_cmd, addr)
|
return run(deno_cmd, port)
|
||||||
|
|
||||||
|
|
||||||
def deno_tcp_current_thread(deno_exe):
|
def deno_tcp_current_thread(deno_exe):
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
deno_cmd = [
|
deno_cmd = [
|
||||||
deno_exe, "run", "--current-thread", "--allow-net",
|
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)."
|
print "http_benchmark testing DENO tcp (single-thread)."
|
||||||
return run(deno_cmd, addr)
|
return run(deno_cmd, port)
|
||||||
|
|
||||||
|
|
||||||
def deno_http(deno_exe):
|
def deno_http(deno_exe):
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
deno_cmd = [
|
deno_cmd = [
|
||||||
deno_exe, "run", "--allow-net",
|
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."
|
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):
|
def deno_tcp_proxy(deno_exe, hyper_hello_exe):
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
origin_addr = get_addr()
|
origin_port = get_port()
|
||||||
deno_cmd = [
|
deno_cmd = [
|
||||||
deno_exe, "run", "--allow-net", "tools/deno_tcp_proxy.ts", addr,
|
deno_exe, "run", "--allow-net", "tools/deno_tcp_proxy.ts",
|
||||||
origin_addr
|
server_addr(port),
|
||||||
|
server_addr(origin_port)
|
||||||
]
|
]
|
||||||
print "http_proxy_benchmark testing DENO using net/tcp."
|
print "http_proxy_benchmark testing DENO using net/tcp."
|
||||||
return run(
|
return run(
|
||||||
deno_cmd,
|
deno_cmd,
|
||||||
addr,
|
port,
|
||||||
origin_cmd=http_proxy_origin(hyper_hello_exe, origin_addr))
|
origin_cmd=http_proxy_origin(hyper_hello_exe, origin_port))
|
||||||
|
|
||||||
|
|
||||||
def deno_http_proxy(deno_exe, hyper_hello_exe):
|
def deno_http_proxy(deno_exe, hyper_hello_exe):
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
origin_addr = get_addr()
|
origin_port = get_port()
|
||||||
deno_cmd = [
|
deno_cmd = [
|
||||||
deno_exe, "run", "--allow-net", "tools/deno_http_proxy.ts", addr,
|
deno_exe, "run", "--allow-net", "tools/deno_http_proxy.ts",
|
||||||
origin_addr
|
server_addr(port),
|
||||||
|
server_addr(origin_port)
|
||||||
]
|
]
|
||||||
print "http_proxy_benchmark testing DENO using net/http."
|
print "http_proxy_benchmark testing DENO using net/http."
|
||||||
return run(
|
return run(
|
||||||
deno_cmd,
|
deno_cmd,
|
||||||
addr,
|
port,
|
||||||
origin_cmd=http_proxy_origin(hyper_hello_exe, origin_addr))
|
origin_cmd=http_proxy_origin(hyper_hello_exe, origin_port))
|
||||||
|
|
||||||
|
|
||||||
def deno_core_single(exe):
|
def deno_core_single(exe):
|
||||||
print "http_benchmark testing deno_core_single"
|
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):
|
def deno_core_multi(exe):
|
||||||
print "http_benchmark testing deno_core_multi"
|
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():
|
def node_http():
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
node_cmd = ["node", "tools/node_http.js", addr.split(":")[1]]
|
node_cmd = ["node", "tools/node_http.js", port]
|
||||||
print "http_benchmark testing NODE."
|
print "http_benchmark testing NODE."
|
||||||
return run(node_cmd, addr)
|
return run(node_cmd, port)
|
||||||
|
|
||||||
|
|
||||||
def node_http_proxy(hyper_hello_exe):
|
def node_http_proxy(hyper_hello_exe):
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
origin_addr = get_addr()
|
origin_port = get_port()
|
||||||
node_cmd = [
|
node_cmd = ["node", "tools/node_http_proxy.js", port, origin_port]
|
||||||
"node", "tools/node_http_proxy.js",
|
|
||||||
addr.split(":")[1],
|
|
||||||
origin_addr.split(":")[1]
|
|
||||||
]
|
|
||||||
print "http_proxy_benchmark testing NODE."
|
print "http_proxy_benchmark testing NODE."
|
||||||
return run(node_cmd, addr, None,
|
return run(node_cmd, port, None,
|
||||||
http_proxy_origin(hyper_hello_exe, origin_addr))
|
http_proxy_origin(hyper_hello_exe, origin_port))
|
||||||
|
|
||||||
|
|
||||||
def node_tcp_proxy(hyper_hello_exe):
|
def node_tcp_proxy(hyper_hello_exe):
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
origin_addr = get_addr()
|
origin_port = get_port()
|
||||||
node_cmd = [
|
node_cmd = ["node", "tools/node_tcp_proxy.js", port, origin_port]
|
||||||
"node", "tools/node_tcp_proxy.js",
|
|
||||||
addr.split(":")[1],
|
|
||||||
origin_addr.split(":")[1]
|
|
||||||
]
|
|
||||||
print "http_proxy_benchmark testing NODE tcp."
|
print "http_proxy_benchmark testing NODE tcp."
|
||||||
return run(node_cmd, addr, None,
|
return run(node_cmd, port, None,
|
||||||
http_proxy_origin(hyper_hello_exe, origin_addr))
|
http_proxy_origin(hyper_hello_exe, origin_port))
|
||||||
|
|
||||||
|
|
||||||
def node_tcp():
|
def node_tcp():
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
node_cmd = ["node", "tools/node_tcp.js", addr.split(":")[1]]
|
node_cmd = ["node", "tools/node_tcp.js", port]
|
||||||
print "http_benchmark testing node_tcp.js"
|
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):
|
def http_proxy_origin(hyper_hello_exe, port):
|
||||||
return [hyper_hello_exe, addr.split(":")[1]]
|
return [hyper_hello_exe, port]
|
||||||
|
|
||||||
|
|
||||||
def hyper_http(hyper_hello_exe):
|
def hyper_http(hyper_hello_exe):
|
||||||
addr = get_addr()
|
port = get_port()
|
||||||
hyper_cmd = [hyper_hello_exe, addr.split(":")[1]]
|
hyper_cmd = [hyper_hello_exe, port]
|
||||||
print "http_benchmark testing RUST hyper."
|
print "http_benchmark testing RUST hyper."
|
||||||
return run(hyper_cmd, addr)
|
return run(hyper_cmd, port)
|
||||||
|
|
||||||
|
|
||||||
def http_benchmark(build_dir):
|
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.
|
# Run deno echo server in the background.
|
||||||
if merge_env is None:
|
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:
|
if origin_cmd is not None:
|
||||||
origin = subprocess.Popen(origin_cmd, env=env)
|
origin = subprocess.Popen(origin_cmd, env=env)
|
||||||
|
|
||||||
|
print server_cmd
|
||||||
server = subprocess.Popen(server_cmd, env=env)
|
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:
|
try:
|
||||||
cmd = "third_party/wrk/%s/wrk -d %s --latency http://%s/" % (
|
cmd = "third_party/wrk/%s/wrk -d %s --latency http://127.0.0.1:%s/" % (
|
||||||
util.platform(), DURATION, addr)
|
util.platform(), DURATION, port)
|
||||||
print cmd
|
print cmd
|
||||||
output = subprocess.check_output(cmd, shell=True)
|
output = subprocess.check_output(cmd, shell=True)
|
||||||
stats = util.parse_wrk_output(output)
|
stats = util.parse_wrk_output(output)
|
||||||
|
|
|
@ -13,7 +13,8 @@ import subprocess
|
||||||
import util
|
import util
|
||||||
|
|
||||||
MB = 1024 * 1024
|
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):
|
def cat(deno_exe, megs):
|
||||||
|
@ -30,14 +31,17 @@ def cat(deno_exe, megs):
|
||||||
def tcp(deno_exe, megs):
|
def tcp(deno_exe, megs):
|
||||||
size = megs * MB
|
size = megs * MB
|
||||||
# Run deno echo server in the background.
|
# Run deno echo server in the background.
|
||||||
echo_server = subprocess.Popen(
|
args = [
|
||||||
[deno_exe, "run", "--allow-net", "tests/echo_server.ts", ADDR])
|
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.
|
time.sleep(5) # wait for deno to wake up. TODO racy.
|
||||||
try:
|
try:
|
||||||
start = time.time()
|
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
|
print cmd
|
||||||
subprocess.check_output(cmd, shell=True)
|
subprocess.check_output(cmd, shell=True)
|
||||||
end = time.time()
|
end = time.time()
|
||||||
|
|
Loading…
Reference in a new issue