Skip to content

Commit

Permalink
Refactor deno_core_http_bench and make it single-threaded (denoland#3903
Browse files Browse the repository at this point in the history
)
  • Loading branch information
piscisaureus committed Feb 8, 2020
1 parent 25467aa commit f650c3e
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 295 deletions.
13 changes: 12 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions core/Cargo.toml
Expand Up @@ -27,7 +27,7 @@ rusty_v8 = "0.2.1"
name = "deno_core_http_bench"
path = "examples/http_bench.rs"

# tokio is only used for deno_core_http_bench
[dev_dependencies]
# These dependendencies are only used for deno_core_http_bench.
[dev-dependencies]
derive_deref = "1.1.0"
tokio = { version = "0.2", features = ["rt-core", "tcp"] }
num_cpus = "1.11.1"
14 changes: 7 additions & 7 deletions core/examples/http_bench.js
Expand Up @@ -36,18 +36,18 @@ const scratchBytes = new Uint8Array(
);
assert(scratchBytes.byteLength === 3 * 4);

function send(promiseId, opId, arg, zeroCopy = null) {
function send(promiseId, opId, rid, zeroCopy = null) {
scratch32[0] = promiseId;
scratch32[1] = arg;
scratch32[1] = rid;
scratch32[2] = -1;
return Deno.core.dispatch(opId, scratchBytes, zeroCopy);
}

/** Returns Promise<number> */
function sendAsync(opId, arg, zeroCopy = null) {
function sendAsync(opId, rid, zeroCopy = null) {
const promiseId = nextPromiseId++;
const p = createResolvable();
const buf = send(promiseId, opId, arg, zeroCopy);
const buf = send(promiseId, opId, rid, zeroCopy);
if (buf) {
const record = recordFromBuf(buf);
// Sync result.
Expand All @@ -60,8 +60,8 @@ function sendAsync(opId, arg, zeroCopy = null) {
}

/** Returns i32 number */
function sendSync(opId, arg) {
const buf = send(0, opId, arg);
function sendSync(opId, rid) {
const buf = send(0, opId, rid);
const record = recordFromBuf(buf);
return record[2];
}
Expand Down Expand Up @@ -131,7 +131,7 @@ async function main() {
Deno.core.print("http_bench.js start\n");

const listenerRid = listen();
Deno.core.print(`listening http://127.0.0.1:4544/ rid = ${listenerRid}\n`);
Deno.core.print(`listening http://127.0.0.1:4544/ rid=${listenerRid}\n`);
while (true) {
const rid = await accept(listenerRid);
// Deno.core.print(`accepted ${rid}`);
Expand Down

0 comments on commit f650c3e

Please sign in to comment.