Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Explicit Resource Management #1830

Merged
merged 17 commits into from
Nov 25, 2024
Merged

Explicit Resource Management #1830

merged 17 commits into from
Nov 25, 2024

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Nov 23, 2024

New Explicit Resource Management feature for the server adapters;
Learn more

  • Symbol.dispose and Symbol.asyncDispose hooks
    When the server adapter plugin has these hooks, it is added to the disposable stack of the server adapter. When the server adapter is disposed, those hooks are triggered
  • disposableStack in the server adapter
    The shared disposable stack that will be triggered when Symbol.asyncDispose is called.
  • Automatic disposal on Node and Node-compatible environments
    Even if the server adapter is not disposed explicitly, the disposal logic will be triggered on the process termination (SIGINT, SIGTERM etc)
  • ctx.waitUntil relation
    If it is an environment does not natively provide waitUntil, the unresolved passed promises will be resolved by the disposable stack.
  • Automatic ongoing request termination
    All ongoing request signals are kept in the disposable stack so when the request adapter is terminated, the requests are automatically terminated as well.

Copy link
Contributor

github-actions bot commented Nov 23, 2024

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@whatwg-node/node-fetch 0.7.4-alpha-20241125142132-d9f044a9ea5bb1f5c81f5bc09c613fdd5be81281 npm ↗︎ unpkg ↗︎
@whatwg-node/server 0.10.0-alpha-20241125142132-d9f044a9ea5bb1f5c81f5bc09c613fdd5be81281 npm ↗︎ unpkg ↗︎
@whatwg-node/server-plugin-cookies 2.0.0-alpha-20241125142132-d9f044a9ea5bb1f5c81f5bc09c613fdd5be81281 npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Nov 23, 2024

@benchmarks/node-fetch results (noConsumeBody)

   ✓ active_handles.................: avg=139.136765 min=26      med=139     max=200     p(90)=163     p(95)=167    
     data_received..................: 23 MB  773 kB/s
     data_sent......................: 15 MB  501 kB/s
     http_req_blocked...............: avg=3.93µs     min=612ns   med=1.36µs  max=9.49ms  p(90)=2.02µs  p(95)=2.29µs 
     http_req_connecting............: avg=2.05µs     min=0s      med=0s      max=5.96ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=19.71ms    min=1.91ms  med=19.06ms max=1.04s   p(90)=25.02ms p(95)=26.75ms
       { expected_response:true }...: avg=19.71ms    min=1.91ms  med=19.06ms max=1.04s   p(90)=25.02ms p(95)=26.75ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 151628
     http_req_receiving.............: avg=36.11µs    min=7.86µs  med=22.78µs max=22.81ms p(90)=37.49µs p(95)=45.38µs
     http_req_sending...............: avg=11.58µs    min=3.46µs  med=6.3µs   max=20.85ms p(90)=9.34µs  p(95)=13.57µs
     http_req_tls_handshaking.......: avg=0s         min=0s      med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=19.66ms    min=1.83ms  med=19.02ms max=1.04s   p(90)=24.98ms p(95)=26.66ms
     http_reqs......................: 151628 5053.712935/s
     iteration_duration.............: avg=39.54ms    min=12.73ms med=38.02ms max=1.07s   p(90)=44.45ms p(95)=49.03ms
     iterations.....................: 75794  2526.189874/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Nov 23, 2024

@benchmarks/server results (ponyfill)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 273022      ✗ 0     
     data_received..................: 27 MB   896 kB/s
     data_sent......................: 11 MB   364 kB/s
     http_req_blocked...............: avg=1.44µs   min=891ns   med=1.21µs   max=495.99µs p(90)=1.89µs   p(95)=2.09µs  
     http_req_connecting............: avg=0ns      min=0s      med=0s       max=122.33µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=155.68µs min=92.14µs med=138.37µs max=22.38ms  p(90)=167.49µs p(95)=188.9µs 
       { expected_response:true }...: avg=155.68µs min=92.14µs med=138.37µs max=22.38ms  p(90)=167.49µs p(95)=188.9µs 
     http_req_failed................: 0.00%   ✓ 0           ✗ 136511
     http_req_receiving.............: avg=26.13µs  min=11.3µs  med=23.97µs  max=3.73ms   p(90)=31.85µs  p(95)=35.63µs 
     http_req_sending...............: avg=6.59µs   min=3.95µs  med=5.66µs   max=4.88ms   p(90)=8.19µs   p(95)=8.99µs  
     http_req_tls_handshaking.......: avg=0s       min=0s      med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=122.95µs min=67.85µs med=106.56µs max=22.31ms  p(90)=130.72µs p(95)=148.38µs
     http_reqs......................: 136511  4550.199142/s
     iteration_duration.............: avg=215.16µs min=137µs   med=195.06µs max=22.5ms   p(90)=230.59µs p(95)=260.21µs
     iterations.....................: 136511  4550.199142/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Nov 23, 2024

@benchmarks/server results (native)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 236222      ✗ 0     
     data_received..................: 24 MB   791 kB/s
     data_sent......................: 9.4 MB  315 kB/s
     http_req_blocked...............: avg=1.41µs   min=921ns    med=1.22µs   max=178.71µs p(90)=1.92µs   p(95)=2.07µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=119.98µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=193.15µs min=143.85µs med=181.85µs max=9.17ms   p(90)=205.51µs p(95)=213.81µs
       { expected_response:true }...: avg=193.15µs min=143.85µs med=181.85µs max=9.17ms   p(90)=205.51µs p(95)=213.81µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 118111
     http_req_receiving.............: avg=25.4µs   min=13.42µs  med=24.21µs  max=2.29ms   p(90)=30.97µs  p(95)=32.86µs 
     http_req_sending...............: avg=6.3µs    min=4.11µs   med=5.58µs   max=276.43µs p(90)=8.13µs   p(95)=8.62µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=161.44µs min=117.34µs med=149.58µs max=9.12ms   p(90)=170.59µs p(95)=178.42µs
     http_reqs......................: 118111  3936.888599/s
     iteration_duration.............: avg=249.6µs  min=190.62µs med=237.45µs max=9.26ms   p(90)=264.48µs p(95)=274.96µs
     iterations.....................: 118111  3936.888599/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Nov 23, 2024

@benchmarks/server results (undici)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 219056      ✗ 0     
     data_received..................: 22 MB   734 kB/s
     data_sent......................: 8.8 MB  292 kB/s
     http_req_blocked...............: avg=1.47µs   min=962ns    med=1.25µs   max=289.31µs p(90)=1.98µs   p(95)=2.16µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=136.13µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=211.36µs min=157.96µs med=198.06µs max=12.02ms  p(90)=224.07µs p(95)=233.98µs
       { expected_response:true }...: avg=211.36µs min=157.96µs med=198.06µs max=12.02ms  p(90)=224.07µs p(95)=233.98µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 109528
     http_req_receiving.............: avg=25.9µs   min=13.94µs  med=24.48µs  max=2.73ms   p(90)=31.65µs  p(95)=33.57µs 
     http_req_sending...............: avg=6.66µs   min=4.24µs   med=5.99µs   max=5.76ms   p(90)=8.42µs   p(95)=9.1µs   
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=178.79µs min=131.17µs med=165.44µs max=11.94ms  p(90)=188.23µs p(95)=197.2µs 
     http_reqs......................: 109528  3650.786334/s
     iteration_duration.............: avg=269.41µs min=208.39µs med=255.29µs max=12.18ms  p(90)=284.76µs p(95)=297.3µs 
     iterations.....................: 109528  3650.786334/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Nov 23, 2024

@benchmarks/node-fetch results (consumeBody)

   ✓ active_handles.................: avg=138.748223 min=13      med=138     max=197     p(90)=162     p(95)=167    
     data_received..................: 22 MB  722 kB/s
     data_sent......................: 14 MB  463 kB/s
     http_req_blocked...............: avg=5.95µs     min=631ns   med=1.37µs  max=15.62ms p(90)=2.05µs  p(95)=2.38µs 
     http_req_connecting............: avg=3.98µs     min=0s      med=0s      max=15.43ms p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=21.11ms    min=1.8ms   med=20.46ms max=1.11s   p(90)=26.44ms p(95)=28.41ms
       { expected_response:true }...: avg=21.11ms    min=1.8ms   med=20.46ms max=1.11s   p(90)=26.44ms p(95)=28.41ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 141566
     http_req_receiving.............: avg=38.24µs    min=10.07µs med=25.68µs max=23.17ms p(90)=40.04µs p(95)=47.04µs
     http_req_sending...............: avg=15.46µs    min=3.39µs  med=6.78µs  max=17.27ms p(90)=10.32µs p(95)=14.24µs
     http_req_tls_handshaking.......: avg=0s         min=0s      med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=21.05ms    min=1.76ms  med=20.42ms max=1.11s   p(90)=26.39ms p(95)=28.34ms
     http_reqs......................: 141566 4717.418996/s
     iteration_duration.............: avg=42.34ms    min=5.34ms  med=40.7ms  max=1.14s   p(90)=47.56ms p(95)=52.54ms
     iterations.....................: 70761  2357.97639/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

@ardatan ardatan changed the title New disposal logic for server adapter Explicit Resource Management Nov 23, 2024
@ardatan ardatan marked this pull request as ready for review November 25, 2024 13:49
@ardatan ardatan merged commit 9cb09da into master Nov 25, 2024
25 checks passed
ardatan added a commit that referenced this pull request Nov 25, 2024
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant