diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-01-18 07:09:54 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-18 15:09:54 +0000 |
commit | f418be4f57594e88e5bcc6f384f1f6ad39f3918f (patch) | |
tree | 5c2596f6c61e0fd3a45d03e6bc046e935e2748a1 /core/examples/http_bench_json_ops.js | |
parent | 9686a0041911f5a6724c5933de57214bd940baac (diff) |
Optimize http_bench_json_ops example (#16505)
Diffstat (limited to 'core/examples/http_bench_json_ops.js')
-rw-r--r-- | core/examples/http_bench_json_ops.js | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/core/examples/http_bench_json_ops.js b/core/examples/http_bench_json_ops.js deleted file mode 100644 index 28c491064..000000000 --- a/core/examples/http_bench_json_ops.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -// 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. -Deno.core.initializeAsyncOps(); - -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:4570, returns rid. */ -function listen() { - return Deno.core.ops.op_listen(); -} - -/** Accepts a connection, returns rid. */ -function accept(serverRid) { - return Deno.core.ops.op_accept(serverRid); -} - -async function serve(rid) { - try { - while (true) { - await Deno.core.read(rid, requestBuf); - await Deno.core.writeAll(rid, responseBuf); - } - } catch (e) { - if ( - !e.message.includes("Broken pipe") && - !e.message.includes("Connection reset by peer") - ) { - throw e; - } - } - Deno.core.close(rid); -} - -async function main() { - const listenerRid = listen(); - Deno.core.print(`http_bench_ops listening on http://127.0.0.1:4570/\n`); - - while (true) { - const rid = await accept(listenerRid); - serve(rid); - } -} - -main(); |