diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-08-14 15:26:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 22:26:21 +0000 |
commit | e92a05b5518e5fd30559c96c5990b08657bbc3e4 (patch) | |
tree | 037cad394db9097d8f695810426a2de9ba03d825 /cli/tools/run/mod.rs | |
parent | 875ee618d318ea748e38641108d906eff34a9f86 (diff) |
feat(serve): Opt-in parallelism for `deno serve` (#24920)
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
```
Diffstat (limited to 'cli/tools/run/mod.rs')
-rw-r--r-- | cli/tools/run/mod.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/cli/tools/run/mod.rs b/cli/tools/run/mod.rs index 65044fbad..1964cfdd9 100644 --- a/cli/tools/run/mod.rs +++ b/cli/tools/run/mod.rs @@ -18,11 +18,7 @@ use crate::util::file_watcher::WatcherRestartMode; pub mod hmr; -pub async fn run_script( - mode: WorkerExecutionMode, - flags: Arc<Flags>, - watch: Option<WatchFlagsWithPaths>, -) -> Result<i32, AnyError> { +pub fn check_permission_before_script(flags: &Flags) { if !flags.has_permission() && flags.has_permission_in_argv() { log::warn!( "{}", @@ -33,6 +29,14 @@ To grant permissions, set them before the script argument. For example: ) ); } +} + +pub async fn run_script( + mode: WorkerExecutionMode, + flags: Arc<Flags>, + watch: Option<WatchFlagsWithPaths>, +) -> Result<i32, AnyError> { + check_permission_before_script(&flags); if let Some(watch_flags) = watch { return run_with_watch(mode, flags, watch_flags).await; @@ -187,7 +191,7 @@ pub async fn eval_command( Ok(exit_code) } -async fn maybe_npm_install(factory: &CliFactory) -> Result<(), AnyError> { +pub async fn maybe_npm_install(factory: &CliFactory) -> Result<(), AnyError> { // ensure an "npm install" is done if the user has explicitly // opted into using a managed node_modules directory if factory.cli_options()?.node_modules_dir_enablement() == Some(true) { |