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

onDispose and other disposal improvements #1899

Merged
merged 2 commits into from
Dec 17, 2024
Merged

onDispose and other disposal improvements #1899

merged 2 commits into from
Dec 17, 2024

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Dec 17, 2024

  • New onDispose hook which is alias of Symbol.asyncDispose for Explicit Resource Management
  • Registration of the server adapter's disposal to the global process termination listener is now opt-in and configurable.
const plugin: ServerAdapterPlugin = {
    onDispose() {
        console.log('Server adapter is disposed');
    }
};

const serverAdapter = createServerAdapter(() => new Response('Hello world!'), {
    plugins: [plugin],
    // Register the server adapter's disposal to the global process termination listener
    // Then the server adapter will be disposed when the process exit signals only in Node.js!
    disposeOnProcessTerminate: true
});

await serverAdapter.dispose();
// Prints 'Server adapter is disposed'

Copy link
Contributor

github-actions bot commented Dec 17, 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/server 0.9.64-alpha-20241217104652-37546cf3a248f20fd8676a3175d6f78e0effffaf npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Dec 17, 2024

@benchmarks/node-fetch results (noConsumeBody)

   ✓ active_handles.................: avg=140.786035 min=12     med=141     max=187     p(90)=160     p(95)=164    
     data_received..................: 23 MB  755 kB/s
     data_sent......................: 15 MB  489 kB/s
     http_req_blocked...............: avg=3.41µs     min=611ns  med=1.4µs   max=11.96ms p(90)=2.06µs  p(95)=2.34µs 
     http_req_connecting............: avg=1.06µs     min=0s     med=0s      max=6.53ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=20.18ms    min=1.6ms  med=19.5ms  max=1.06s   p(90)=25.14ms p(95)=27.15ms
       { expected_response:true }...: avg=20.18ms    min=1.6ms  med=19.5ms  max=1.06s   p(90)=25.14ms p(95)=27.15ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 148080
     http_req_receiving.............: avg=34.47µs    min=9.81µs med=23.27µs max=16.12ms p(90)=38.14µs p(95)=45.4µs 
     http_req_sending...............: avg=12.2µs     min=3.48µs med=6.69µs  max=12.27ms p(90)=10µs    p(95)=14.37µs
     http_req_tls_handshaking.......: avg=0s         min=0s     med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=20.13ms    min=1.55ms med=19.46ms max=1.06s   p(90)=25.1ms  p(95)=27.06ms
     http_reqs......................: 148080 4935.391563/s
     iteration_duration.............: avg=40.48ms    min=10.2ms med=38.99ms max=1.09s   p(90)=45.14ms p(95)=50ms   
     iterations.....................: 74026  2467.229172/s
     vus............................: 0      min=0         max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Dec 17, 2024

@benchmarks/server results (ponyfill)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 290916      ✗ 0     
     data_received..................: 29 MB   955 kB/s
     data_sent......................: 12 MB   388 kB/s
     http_req_blocked...............: avg=1.43µs   min=881ns    med=1.2µs    max=193.81µs p(90)=1.91µs   p(95)=2.1µs   
     http_req_connecting............: avg=0ns      min=0s       med=0s       max=136.65µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=141.55µs min=95.03µs  med=136.02µs max=6.02ms   p(90)=159.66µs p(95)=168.98µs
       { expected_response:true }...: avg=141.55µs min=95.03µs  med=136.02µs max=6.02ms   p(90)=159.66µs p(95)=168.98µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 145458
     http_req_receiving.............: avg=25.05µs  min=12.02µs  med=23.44µs  max=3.06ms   p(90)=31.03µs  p(95)=34.57µs 
     http_req_sending...............: avg=6.61µs   min=4.09µs   med=5.85µs   max=302.97µs p(90)=8.4µs    p(95)=9.79µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=109.88µs min=67.59µs  med=104.15µs max=5.95ms   p(90)=124.33µs p(95)=131.95µs
     http_reqs......................: 145458  4848.430154/s
     iteration_duration.............: avg=201.52µs min=141.25µs med=195.2µs  max=6.41ms   p(90)=222.99µs p(95)=235.41µs
     iterations.....................: 145458  4848.430154/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Dec 17, 2024

@benchmarks/node-fetch results (consumeBody)

   ✓ active_handles.................: avg=140.319004 min=31     med=140     max=181     p(90)=160     p(95)=167    
     data_received..................: 21 MB  702 kB/s
     data_sent......................: 14 MB  450 kB/s
     http_req_blocked...............: avg=4.03µs     min=611ns  med=1.38µs  max=5.86ms  p(90)=2.07µs  p(95)=2.43µs 
     http_req_connecting............: avg=2.17µs     min=0s     med=0s      max=5.75ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=21.71ms    min=2.95ms med=20.96ms max=1.12s   p(90)=27.2ms  p(95)=29.27ms
       { expected_response:true }...: avg=21.71ms    min=2.95ms med=20.96ms max=1.12s   p(90)=27.2ms  p(95)=29.27ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 137701
     http_req_receiving.............: avg=36.25µs    min=9.54µs med=25.44µs max=22.23ms p(90)=40.43µs p(95)=48.4µs 
     http_req_sending...............: avg=11.43µs    min=3.4µs  med=6.77µs  max=12.98ms p(90)=10.52µs p(95)=14.84µs
     http_req_tls_handshaking.......: avg=0s         min=0s     med=0s      max=0s      p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=21.66ms    min=2.92ms med=20.92ms max=1.12s   p(90)=27.15ms p(95)=29.2ms 
     http_reqs......................: 137701 4589.165315/s
     iteration_duration.............: avg=43.54ms    min=9.78ms med=41.93ms max=1.15s   p(90)=48.84ms p(95)=53.41ms
     iterations.....................: 68833  2293.999435/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Dec 17, 2024

@benchmarks/server results (undici)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 217506      ✗ 0     
     data_received..................: 22 MB   729 kB/s
     data_sent......................: 8.7 MB  290 kB/s
     http_req_blocked...............: avg=1.44µs   min=912ns    med=1.21µs   max=2.61ms   p(90)=1.89µs   p(95)=2.05µs  
     http_req_connecting............: avg=23ns     min=0s       med=0s       max=2.54ms   p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=212.49µs min=159.43µs med=201.43µs max=32.03ms  p(90)=226.46µs p(95)=235.34µs
       { expected_response:true }...: avg=212.49µs min=159.43µs med=201.43µs max=32.03ms  p(90)=226.46µs p(95)=235.34µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 108753
     http_req_receiving.............: avg=25.6µs   min=14.13µs  med=23.91µs  max=2.78ms   p(90)=31.03µs  p(95)=33.75µs 
     http_req_sending...............: avg=6.42µs   min=4.08µs   med=5.65µs   max=367.13µs p(90)=8.13µs   p(95)=8.82µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=180.47µs min=131.98µs med=169.67µs max=31.96ms  p(90)=191.67µs p(95)=199.72µs
     http_reqs......................: 108753  3624.803741/s
     iteration_duration.............: avg=271.29µs min=204.08µs med=258.87µs max=32.15ms  p(90)=287.58µs p(95)=298.46µs
     iterations.....................: 108753  3624.803741/s
     vus............................: 0       min=0         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented Dec 17, 2024

@benchmarks/server results (native)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 233774      ✗ 0     
     data_received..................: 24 MB   783 kB/s
     data_sent......................: 9.4 MB  312 kB/s
     http_req_blocked...............: avg=1.37µs   min=892ns    med=1.16µs   max=164.79µs p(90)=1.85µs   p(95)=2.01µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=120.32µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=194.55µs min=142.14µs med=184.11µs max=6.28ms   p(90)=210.57µs p(95)=221.6µs 
       { expected_response:true }...: avg=194.55µs min=142.14µs med=184.11µs max=6.28ms   p(90)=210.57µs p(95)=221.6µs 
     http_req_failed................: 0.00%   ✓ 0           ✗ 116887
     http_req_receiving.............: avg=25.39µs  min=13.71µs  med=23.66µs  max=4.56ms   p(90)=30.96µs  p(95)=33.77µs 
     http_req_sending...............: avg=6.3µs    min=4.14µs   med=5.45µs   max=258.68µs p(90)=8.1µs    p(95)=8.68µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=162.85µs min=119.02µs med=152.21µs max=6.24ms   p(90)=175.68µs p(95)=185.59µs
     http_reqs......................: 116887  3896.086226/s
     iteration_duration.............: avg=252.2µs  min=184.57µs med=240.7µs  max=6.35ms   p(90)=270.82µs p(95)=285.16µs
     iterations.....................: 116887  3896.086226/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

@ardatan ardatan merged commit a84e84a into master Dec 17, 2024
24 checks passed
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.

2 participants