mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
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 ``` |
||
---|---|---|
.. | ||
01_net.js | ||
02_tls.js | ||
Cargo.toml | ||
io.rs | ||
lib.deno_net.d.ts | ||
lib.rs | ||
ops.rs | ||
ops_tls.rs | ||
ops_unix.rs | ||
raw.rs | ||
README.md | ||
resolve_addr.rs | ||
tcp.rs |
deno_net
This crate implements networking APIs.
Usage Example
From javascript, include the extension's source:
import * as webidl from "ext:deno_webidl/00_webidl.js";
import * as net from "ext:deno_net/01_net.js";
import * as tls from "ext:deno_net/02_tls.js";
Then from rust, provide:
deno_net::deno_net::init_ops_and_esm::<Permissions>(root_cert_store_provider, unsafely_ignore_certificate_errors)
Where:
- root_cert_store_provider:
Option<Arc<dyn RootCertStoreProvider>>
- unsafely_ignore_certificate_errors:
Option<Vec<String>>
- Permissions: A struct implementing
deno_net::NetPermissions
In the extensions
field of your RuntimeOptions
Dependencies
- deno_web: Provided by the
deno_web
crate - deno_fetch: Provided by the
deno_fetch
crate
Provided ops
Following ops are provided, which can be accessed through Deno.ops
:
Net
- op_net_accept_tcp
- op_net_accept_unix
- op_net_connect_tcp
- op_net_connect_unix
- op_net_listen_tcp
- op_net_listen_udp
- op_net_listen_unix
- op_net_listen_unixpacket
- op_net_recv_udp
- op_net_recv_unixpacket
- op_net_send_udp
- op_net_send_unixpacket
- op_net_connect_tls
- op_net_listen_tls
- op_net_accept_tls
- op_net_recv_udp
- op_net_send_udp
- op_net_join_multi_v4_udp
- op_net_join_multi_v6_udp
- op_net_leave_multi_v4_udp
- op_net_leave_multi_v6_udp
- op_net_set_multi_loopback_udp
- op_net_set_multi_ttl_udp
- op_net_accept_tcp
- op_net_connect_tcp
- op_net_listen_tcp
- op_net_listen_udp
- op_net_connect_tls
- op_net_listen_tls
- op_net_accept_tls
- op_net_accept_unix
- op_net_connect_unix
- op_net_listen_unix
- op_net_listen_unixpacket
- op_net_recv_unixpacket
- op_net_send_unixpacket
TLS
- op_tls_start
- op_tls_handshake
- op_tls_key_null
- op_tls_key_static
- op_tls_key_static_from_file
- op_tls_cert_resolver_create
- op_tls_cert_resolver_poll
- op_tls_cert_resolver_resolve
- op_tls_cert_resolver_resolve_error
- op_tls_start
- op_tls_handshake
Other
- op_node_unstable_net_listen_udp
- op_dns_resolve
- op_dns_resolve
- op_set_nodelay
- op_set_keepalive
- op_node_unstable_net_listen_unixpacket