Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(serve): Opt-in parallelism for deno serve #24920

Merged
merged 21 commits into from
Aug 14, 2024

Conversation

nathanwhit
Copy link
Member

@nathanwhit nathanwhit commented Aug 7, 2024

Adds a parallel flag to deno serve. When present, we spawn multiple workers to parallelize serving requests.

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

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the parallelism should be opt-out rather than opt-in

nevermind - i see that it defaults to number of cores

@bartlomieju bartlomieju added this to the 1.46 milestone Aug 7, 2024
@nathanwhit nathanwhit enabled auto-merge (squash) August 14, 2024 21:21
@nathanwhit nathanwhit merged commit e92a05b into denoland:main Aug 14, 2024
17 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants