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

feat(server): native fetch implementation support for Node #1328

Merged
merged 6 commits into from
May 30, 2024

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented May 30, 2024

Changes & Notes;

  • Add a benchmark scenario that uses @whatwg-node/server with the native fetch
  • Add a test scenario for unit tests of @whatwg-node/server with the native fetch
    • It is fully compatible in terms of functionality but when you create a proxying server with native fetch, it is flakey and sometimes leaks according to Jest on Node 18 and Node 22. See proxy.spec.ts
    • Every single unit test is now done both the ponyfill and the native fetch
  • Introduce a new flag in createFetch of @whatwg-node/fetch to use the native Fetch implementation, so native Fetch impl can be used with @whatwg-node/server

Copy link
Contributor

github-actions bot commented May 30, 2024

@benchmarks/node-fetch results (noConsumeBody)

   ✓ active_handles.................: avg=137.084155 min=10       med=137     max=200      p(90)=160     p(95)=167    
     data_received..................: 24 MB  808 kB/s
     data_sent......................: 16 MB  523 kB/s
     http_req_blocked...............: avg=4.78µs     min=611ns    med=1.43µs  max=12.99ms  p(90)=2.01µs  p(95)=2.33µs 
     http_req_connecting............: avg=2.81µs     min=0s       med=0s      max=12.96ms  p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=18.86ms    min=571.55µs med=18.41ms max=869.57ms p(90)=24.68ms p(95)=26.25ms
       { expected_response:true }...: avg=18.86ms    min=571.55µs med=18.41ms max=869.57ms p(90)=24.68ms p(95)=26.25ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 158400
     http_req_receiving.............: avg=36.7µs     min=8.54µs   med=24.52µs max=48.95ms  p(90)=39.63µs p(95)=48.13µs
     http_req_sending...............: avg=13.3µs     min=3.06µs   med=6.77µs  max=29.63ms  p(90)=10.12µs p(95)=15.33µs
     http_req_tls_handshaking.......: avg=0s         min=0s       med=0s      max=0s       p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=18.81ms    min=516.38µs med=18.37ms max=869.51ms p(90)=24.64ms p(95)=26.19ms
     http_reqs......................: 158400 5279.432979/s
     iteration_duration.............: avg=37.84ms    min=7.95ms   med=36.81ms max=888.32ms p(90)=41.73ms p(95)=47.2ms 
     iterations.....................: 79175  2638.883246/s
     vus............................: 0      min=0         max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented May 30, 2024

@benchmarks/node-fetch results (consumeBody)

   ✓ active_handles.................: avg=139.427742 min=60       med=141     max=199      p(90)=161     p(95)=167    
     data_received..................: 22 MB  745 kB/s
     data_sent......................: 14 MB  478 kB/s
     http_req_blocked...............: avg=3.99µs     min=641ns    med=1.43µs  max=6.56ms   p(90)=2.03µs  p(95)=2.39µs 
     http_req_connecting............: avg=2.17µs     min=0s       med=0s      max=6.47ms   p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=20.45ms    min=521.38µs med=19.95ms max=803.69ms p(90)=26.38ms p(95)=27.94ms
       { expected_response:true }...: avg=20.45ms    min=521.38µs med=19.95ms max=803.69ms p(90)=26.38ms p(95)=27.94ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 146101
     http_req_receiving.............: avg=38.92µs    min=9.39µs   med=25.34µs max=26.08ms  p(90)=40.53µs p(95)=48.71µs
     http_req_sending...............: avg=11.47µs    min=3.48µs   med=7.14µs  max=21.39ms  p(90)=10.35µs p(95)=14.7µs 
     http_req_tls_handshaking.......: avg=0s         min=0s       med=0s      max=0s       p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=20.4ms     min=492.43µs med=19.91ms max=803.63ms p(90)=26.33ms p(95)=27.87ms
     http_reqs......................: 146101 4868.881849/s
     iteration_duration.............: avg=41.03ms    min=4.97ms   med=39.84ms max=823.09ms p(90)=45.23ms p(95)=50.96ms
     iterations.....................: 73030  2433.757753/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented May 30, 2024

@benchmarks/server results (ponyfill)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 301300      ✗ 0     
     data_received..................: 30 MB   989 kB/s
     data_sent......................: 12 MB   402 kB/s
     http_req_blocked...............: avg=1.35µs   min=861ns    med=1.17µs   max=173.03µs p(90)=1.83µs   p(95)=1.99µs  
     http_req_connecting............: avg=0ns      min=0s       med=0s       max=114.04µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=138.05µs min=92.76µs  med=133.08µs max=7.14ms   p(90)=154.68µs p(95)=160.87µs
       { expected_response:true }...: avg=138.05µs min=92.76µs  med=133.08µs max=7.14ms   p(90)=154.68µs p(95)=160.87µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 150650
     http_req_receiving.............: avg=24.18µs  min=12.06µs  med=22.99µs  max=1.35ms   p(90)=30.24µs  p(95)=32.16µs 
     http_req_sending...............: avg=6.01µs   min=3.92µs   med=5.27µs   max=287.24µs p(90)=7.9µs    p(95)=8.34µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=107.85µs min=69.28µs  med=102.42µs max=7.09ms   p(90)=120.87µs p(95)=125.92µs
     http_reqs......................: 150650  5021.494115/s
     iteration_duration.............: avg=194.76µs min=138.27µs med=189µs    max=7.28ms   p(90)=213.65µs p(95)=221.88µs
     iterations.....................: 150650  5021.494115/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented May 30, 2024

@benchmarks/server results (native)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 226308      ✗ 0     
     data_received..................: 23 MB   758 kB/s
     data_sent......................: 9.1 MB  302 kB/s
     http_req_blocked...............: avg=1.34µs   min=871ns    med=1.16µs   max=175.72µs p(90)=1.84µs   p(95)=2µs     
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=123.65µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=204.26µs min=147.52µs med=190.81µs max=22.55ms  p(90)=218.41µs p(95)=228.94µs
       { expected_response:true }...: avg=204.26µs min=147.52µs med=190.81µs max=22.55ms  p(90)=218.41µs p(95)=228.94µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 113154
     http_req_receiving.............: avg=24.81µs  min=13.05µs  med=23.13µs  max=6.09ms   p(90)=30.37µs  p(95)=32.62µs 
     http_req_sending...............: avg=6.03µs   min=3.9µs    med=5.24µs   max=295.45µs p(90)=7.96µs   p(95)=8.47µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=173.41µs min=123.25µs med=160.01µs max=22.47ms  p(90)=183.92µs p(95)=193.44µs
     http_reqs......................: 113154  3768.943977/s
     iteration_duration.............: avg=260.93µs min=189.99µs med=246.62µs max=22.7ms   p(90)=278.32µs p(95)=291.71µs
     iterations.....................: 113154  3768.943977/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Repository owner deleted a comment from github-actions bot May 30, 2024
@ardatan ardatan changed the title Check Node 22 perf Add benchmarks for server with native Fetch Implementation May 30, 2024
@ardatan ardatan marked this pull request as ready for review May 30, 2024 10:35
@ardatan ardatan changed the title Add benchmarks for server with native Fetch Implementation Native Fetch Implementation support May 30, 2024
Copy link
Contributor

🚀 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/fetch 0.9.18-alpha-20240530124408-1cc9a2d00c89801f9114bd63132482860f1ca41d npm ↗︎ unpkg ↗︎

@ardatan ardatan changed the title Native Fetch Implementation support feat(server): native fetch implementation support for Node May 30, 2024
@ardatan ardatan merged commit 36904b4 into master May 30, 2024
22 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.

1 participant