diff options
author | Bert Belder <bertbelder@gmail.com> | 2020-08-21 17:14:47 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2020-08-21 20:21:32 +0200 |
commit | 29e3f4cd3a42415d73b371f87a6efc787331de86 (patch) | |
tree | 78e4b62f8504889d1d4605d0acdb0ad1ff5908f8 /core/examples/http_bench.js | |
parent | 999e5cf3d44ba41d988f0f3b4f94439a3b794bdc (diff) |
Split core http benchmark into 'bin_ops' and 'json_ops' variants (#7147)
Diffstat (limited to 'core/examples/http_bench.js')
-rw-r--r-- | core/examples/http_bench.js | 73 |
1 files changed, 0 insertions, 73 deletions
diff --git a/core/examples/http_bench.js b/core/examples/http_bench.js deleted file mode 100644 index de6b5a9a4..000000000 --- a/core/examples/http_bench.js +++ /dev/null @@ -1,73 +0,0 @@ -// This is not a real HTTP server. We read blindly one time into 'requestBuf', -// then write this fixed 'responseBuf'. The point of this benchmark is to -// exercise the event loop in a simple yet semi-realistic way. -const requestBuf = new Uint8Array(64 * 1024); -const responseBuf = new Uint8Array( - "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n" - .split("") - .map((c) => c.charCodeAt(0)), -); - -/** Listens on 0.0.0.0:4500, returns rid. */ -function listen() { - const { rid } = Deno.core.jsonOpSync("listen", {}); - return rid; -} - -/** Accepts a connection, returns rid. */ -async function accept(serverRid) { - const { rid } = await Deno.core.jsonOpAsync("accept", { rid: serverRid }); - return rid; -} - -/** - * Reads a packet from the rid, presumably an http request. data is ignored. - * Returns bytes read. - */ -async function read(rid, data) { - const { nread } = await Deno.core.jsonOpAsync("read", { rid }, data); - return nread; -} - -/** Writes a fixed HTTP response to the socket rid. Returns bytes written. */ -async function write(rid, data) { - const { nwritten } = await Deno.core.jsonOpAsync("write", { rid }, data); - return nwritten; -} - -function close(rid) { - Deno.core.jsonOpSync("close", { rid }); -} - -async function serve(rid) { - while (true) { - const nread = await read(rid, requestBuf); - if (nread <= 0) { - break; - } - - const nwritten = await write(rid, responseBuf); - if (nwritten < 0) { - break; - } - } - close(rid); -} - -async function main() { - Deno.core.ops(); - - const listenerRid = listen(); - Deno.core.print(`listening http://127.0.0.1:4544/ rid=${listenerRid}\n`); - - for (;;) { - const rid = await accept(listenerRid); - if (rid < 0) { - Deno.core.print(`accept error ${rid}`); - return; - } - serve(rid); - } -} - -main(); |