e92a05b551
Adds a `parallel` flag to `deno serve`. When present, we spawn multiple workers to parallelize serving requests. ```bash deno serve --parallel main.ts ``` Currently on linux we use `SO_REUSEPORT` and rely on the fact that the kernel will distribute connections in a round-robin manner. On mac and windows, we sort of emulate this by cloning the underlying file descriptor and passing a handle to each worker. The connections will not be guaranteed to be fairly distributed (and in practice almost certainly won't be), but the distribution is still spread enough to provide a significant performance increase. --- (Run on an Macbook Pro with an M3 Max, serving `deno.com` baseline:: ``` ❯ wrk -d 30s -c 125 --latency http://127.0.0.1:8000 Running 30s test @ http://127.0.0.1:8000 2 threads and 125 connections Thread Stats Avg Stdev Max +/- Stdev Latency 239.78ms 13.56ms 330.54ms 79.12% Req/Sec 258.58 35.56 360.00 70.64% Latency Distribution 50% 236.72ms 75% 248.46ms 90% 256.84ms 99% 268.23ms 15458 requests in 30.02s, 2.47GB read Requests/sec: 514.89 Transfer/sec: 84.33MB ``` this PR (`with --parallel` flag) ``` ❯ wrk -d 30s -c 125 --latency http://127.0.0.1:8000 Running 30s test @ http://127.0.0.1:8000 2 threads and 125 connections Thread Stats Avg Stdev Max +/- Stdev Latency 117.40ms 142.84ms 590.45ms 79.07% Req/Sec 1.33k 175.19 1.77k 69.00% Latency Distribution 50% 22.34ms 75% 223.67ms 90% 357.32ms 99% 460.50ms 79636 requests in 30.07s, 12.74GB read Requests/sec: 2647.96 Transfer/sec: 433.71MB ``` |
||
---|---|---|
.. | ||
examples/extension | ||
js | ||
ops | ||
permissions | ||
Cargo.toml | ||
clippy.toml | ||
code_cache.rs | ||
errors.rs | ||
fmt_errors.rs | ||
fs_util.rs | ||
inspector_server.rs | ||
js.rs | ||
lib.rs | ||
README.md | ||
shared.rs | ||
snapshot.rs | ||
tokio_util.rs | ||
web_worker.rs | ||
worker.rs | ||
worker_bootstrap.rs |
deno_runtime
crate
This is a slim version of the Deno CLI which removes typescript integration and various tooling (like lint and doc). Basically only JavaScript execution with Deno's operating system bindings (ops).
Stability
This crate is built using battle-tested modules that were originally in the
deno
crate, however the API of this crate is subject to rapid and breaking
changes.
MainWorker
The main API of this crate is MainWorker
. MainWorker
is a structure
encapsulating deno_core::JsRuntime
with a set of ops used to implement Deno
namespace.
When creating a MainWorker
implementors must call MainWorker::bootstrap
to
prepare JS runtime for use.
MainWorker
is highly configurable and allows to customize many of the
runtime's properties:
- module loading implementation
- error formatting
- support for source maps
- support for V8 inspector and Chrome Devtools debugger
- HTTP client user agent, CA certificate
- random number generator seed
Worker
Web API
deno_runtime
comes with support for Worker
Web API. The Worker
API is
implemented using WebWorker
structure.
When creating a new instance of MainWorker
implementors must provide a
callback function that is used when creating a new instance of Worker
.
All WebWorker
instances are descendents of MainWorker
which is responsible
for setting up communication with child worker. Each WebWorker
spawns a new OS
thread that is dedicated solely to that worker.