diff options
author | Kurt Mackey <mrkurt@gmail.com> | 2019-06-06 21:46:18 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-06 22:46:18 -0400 |
commit | 9a6cfd653d74ab23d9415e6ce67da22badb8101e (patch) | |
tree | dd1e32fb3947a957622c8cca491885f57623b67b /tools/deno_tcp_proxy.ts | |
parent | 9bea576f3ea224ec72f371f6f0bc582171ca7890 (diff) |
add tcp proxy benchmarks + split out website section for proxy req/s (#2464)
Diffstat (limited to 'tools/deno_tcp_proxy.ts')
-rw-r--r-- | tools/deno_tcp_proxy.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/deno_tcp_proxy.ts b/tools/deno_tcp_proxy.ts new file mode 100644 index 000000000..96877fa20 --- /dev/null +++ b/tools/deno_tcp_proxy.ts @@ -0,0 +1,29 @@ +// Used for benchmarking Deno's tcp proxy perfromance. See tools/http_benchmark.py +const addr = Deno.args[1] || "127.0.0.1:4500"; +const originAddr = Deno.args[2] || "127.0.0.1:4501"; + +const listener = Deno.listen("tcp", addr); + +async function handle(conn: Deno.Conn): Promise<void> { + const origin = await Deno.dial("tcp", originAddr); + try { + await Promise.all([Deno.copy(conn, origin), Deno.copy(origin, conn)]); + } catch (err) { + if (err.message !== "read error" && err.message !== "write error") { + throw err; + } + } finally { + conn.close(); + origin.close(); + } +} + +async function main(): Promise<void> { + console.log("Listening on", addr); + while (true) { + const conn = await listener.accept(); + handle(conn); + } +} + +main(); |