-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Used for benchmarking Deno's networking. See tools/http_benchmark.py | ||
// TODO Replace this with a real HTTP server once | ||
// https://github.com/denoland/deno/issues/726 is completed. | ||
import * as deno from "deno"; | ||
const addr = deno.args[1] || "127.0.0.1:4500"; | ||
const listener = deno.listen("tcp", addr); | ||
const response = new TextEncoder().encode( | ||
"HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n" | ||
); | ||
|
||
async function handle(conn: deno.Conn): Promise<void> { | ||
const buffer = new Uint8Array(1024); | ||
try { | ||
while (true) { | ||
const r = await conn.read(buffer); | ||
if (r.eof) { | ||
break; | ||
} | ||
await conn.write(response); | ||
} | ||
} finally { | ||
conn.close(); | ||
} | ||
} | ||
|
||
async function main(): Promise<void> { | ||
console.log("Listening on", addr); | ||
while (true) { | ||
const conn = await listener.accept(); | ||
handle(conn); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
import util | ||
import time | ||
import subprocess | ||
|
||
ADDR = "127.0.0.1:4544" | ||
DURATION = "10s" | ||
|
||
|
||
def http_benchmark(deno_exe): | ||
deno_cmd = [deno_exe, "--allow-net", "tests/http_bench.ts", ADDR] | ||
node_cmd = ["node", "tools/node_http.js", ADDR.split(":")[1]] | ||
|
||
print "http_benchmark testing DENO." | ||
deno_rps = run(deno_cmd) | ||
|
||
print "http_benchmark testing NODE." | ||
node_rps = run(node_cmd) | ||
|
||
return {"deno": deno_rps, "node": node_rps} | ||
|
||
|
||
def run(server_cmd): | ||
# Run deno echo server in the background. | ||
server = subprocess.Popen(server_cmd) | ||
time.sleep(5) # wait for server to wake up. TODO racy. | ||
wrk_platform = { | ||
"linux2": "linux", | ||
"darwin": "mac", | ||
}[sys.platform] | ||
try: | ||
cmd = "third_party/wrk/" + wrk_platform + "/wrk -d " + DURATION + " http://" + ADDR + "/" | ||
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: | ||
print "Usage ./tools/tcp_http_benchmark.py out/debug/deno" | ||
sys.exit(1) | ||
http_benchmark(sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const http = require("http"); | ||
const port = process.argv[2] || "4544"; | ||
console.log("port", port); | ||
http | ||
.Server((req, res) => { | ||
res.end("Hello World\n"); | ||
}) | ||
.listen(port); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Running 10s test @ http://127.0.0.1:4500/ | ||
2 threads and 10 connections | ||
Thread Stats Avg Stdev Max +/- Stdev | ||
Latency 5.08ms 1.37ms 34.96ms 96.63% | ||
Req/Sec 0.92k 51.83 1.00k 78.50% | ||
18381 requests in 10.00s, 0.89MB read | ||
Socket errors: connect 0, read 18381, write 0, timeout 0 | ||
Requests/sec: 1837.86 | ||
Transfer/sec: 91.53KB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters