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

Better fastify support #1229

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Better fastify support #1229

wants to merge 5 commits into from

Conversation

ardatan
Copy link
Owner

@ardatan ardatan commented Mar 27, 2024

Now the server adapter created with @whatwg-node/server can be used with Fastify easier;

import fastify, { FastifyReply, FastifyRequest } from 'fastify'
import myServerAdapter from './myServerAdapter'

// This is the fastify instance you have created
const app = fastify({ logger: true })

/**
 * We pass the incoming HTTP request to our adapter
 * and handle the response using Fastify's `reply` API
 * Learn more about `reply` https://www.fastify.io/docs/latest/Reply/
 **/
app.route({
  url: '/mypath',
  method: ['GET', 'POST', 'OPTIONS'],
  handler: (req, reply) => myServerAdapter.handleNodeRequestAndResponse(req, reply, {
      req,
      reply
    })
})

app.listen(4000)

Copy link

codesandbox bot commented Mar 27, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

github-actions bot commented Mar 27, 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.5.18-alpha-20240726153005-ce5d304c2d2f79f6b44b7fc5a6ac4ec231b76090 npm ↗︎ unpkg ↗︎
@whatwg-node/server 0.9.45-alpha-20240726153005-ce5d304c2d2f79f6b44b7fc5a6ac4ec231b76090 npm ↗︎ unpkg ↗︎

Copy link
Contributor

github-actions bot commented Mar 27, 2024

@benchmarks/node-fetch results (consumeBody)

   ✓ active_handles.................: avg=138.814104 min=13     med=140     max=200      p(90)=160     p(95)=165    
     data_received..................: 21 MB  699 kB/s
     data_sent......................: 13 MB  448 kB/s
     http_req_blocked...............: avg=2.75µs     min=631ns  med=1.21µs  max=6.24ms   p(90)=2.01µs  p(95)=2.3µs  
     http_req_connecting............: avg=1.05µs     min=0s     med=0s      max=6.14ms   p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=21.81ms    min=2.58ms med=21.21ms max=983.23ms p(90)=27.49ms p(95)=29.13ms
       { expected_response:true }...: avg=21.81ms    min=2.58ms med=21.21ms max=983.23ms p(90)=27.49ms p(95)=29.13ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 137060
     http_req_receiving.............: avg=34.59µs    min=9.12µs med=23.98µs max=20.75ms  p(90)=38.07µs p(95)=44.18µs
     http_req_sending...............: avg=11.2µs     min=3.28µs med=5.79µs  max=19.72ms  p(90)=9.48µs  p(95)=13.08µs
     http_req_tls_handshaking.......: avg=0s         min=0s     med=0s      max=0s       p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=21.77ms    min=2.54ms med=21.17ms max=983.16ms p(90)=27.45ms p(95)=29.07ms
     http_reqs......................: 137060 4567.389146/s
     iteration_duration.............: avg=43.73ms    min=9.28ms med=42.4ms  max=1s       p(90)=47.03ms p(95)=52.91ms
     iterations.....................: 68506  2282.894797/s
     vus............................: 96     min=96        max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Mar 27, 2024

@benchmarks/node-fetch results (noConsumeBody)

   ✓ active_handles.................: avg=139.846395 min=50      med=141     max=186      p(90)=162     p(95)=168    
     data_received..................: 22 MB  719 kB/s
     data_sent......................: 14 MB  466 kB/s
     http_req_blocked...............: avg=3.46µs     min=681ns   med=1.37µs  max=9.07ms   p(90)=2.01µs  p(95)=2.28µs 
     http_req_connecting............: avg=1.48µs     min=0s      med=0s      max=5.14ms   p(90)=0s      p(95)=0s     
     http_req_duration..............: avg=21.2ms     min=2.31ms  med=20.69ms max=870.08ms p(90)=27.02ms p(95)=28.52ms
       { expected_response:true }...: avg=21.2ms     min=2.31ms  med=20.69ms max=870.08ms p(90)=27.02ms p(95)=28.52ms
     http_req_failed................: 0.00%  ✓ 0           ✗ 141008
     http_req_receiving.............: avg=35.89µs    min=9.42µs  med=24.36µs max=55.96ms  p(90)=39.56µs p(95)=46.55µs
     http_req_sending...............: avg=11.63µs    min=3.4µs   med=6.59µs  max=13.61ms  p(90)=9.88µs  p(95)=13.59µs
     http_req_tls_handshaking.......: avg=0s         min=0s      med=0s      max=0s       p(90)=0s      p(95)=0s     
     http_req_waiting...............: avg=21.15ms    min=2.29ms  med=20.65ms max=870.01ms p(90)=26.97ms p(95)=28.46ms
     http_reqs......................: 141008 4698.906862/s
     iteration_duration.............: avg=42.51ms    min=10.58ms med=41.22ms max=890.75ms p(90)=46.12ms p(95)=51.94ms
     iterations.....................: 70473  2348.420397/s
     vus............................: 100    min=100       max=100 
     vus_max........................: 100    min=100       max=100 

Copy link
Contributor

github-actions bot commented Mar 27, 2024

@benchmarks/server results

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 291010      ✗ 0     
     data_received..................: 29 MB   956 kB/s
     data_sent......................: 12 MB   388 kB/s
     http_req_blocked...............: avg=1.44µs   min=881ns    med=1.19µs   max=5.81ms   p(90)=1.9µs    p(95)=2.07µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=150.59µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=144.02µs min=98.11µs  med=139.18µs max=7.14ms   p(90)=160.74µs p(95)=168.09µs
       { expected_response:true }...: avg=144.02µs min=98.11µs  med=139.18µs max=7.14ms   p(90)=160.74µs p(95)=168.09µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 145505
     http_req_receiving.............: avg=25.22µs  min=13.12µs  med=24.02µs  max=5.19ms   p(90)=30.88µs  p(95)=32.94µs 
     http_req_sending...............: avg=6µs      min=3.84µs   med=5.33µs   max=170µs    p(90)=7.65µs   p(95)=8.16µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=112.78µs min=71.99µs  med=107.52µs max=6.96ms   p(90)=126.18µs p(95)=131.93µs
     http_reqs......................: 145505  4850.123988/s
     iteration_duration.............: avg=200.32µs min=143.66µs med=194.2µs  max=7.34ms   p(90)=219.59µs p(95)=229.61µs
     iterations.....................: 145505  4850.123988/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

@ardatan ardatan force-pushed the better-fastify-support branch from 26e1725 to c89f778 Compare May 31, 2024 12:28
Copy link
Contributor

github-actions bot commented May 31, 2024

@benchmarks/server results (ponyfill)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 293064      ✗ 0     
     data_received..................: 29 MB   962 kB/s
     data_sent......................: 12 MB   391 kB/s
     http_req_blocked...............: avg=1.4µs    min=892ns    med=1.21µs   max=165.21µs p(90)=1.88µs   p(95)=2.05µs  
     http_req_connecting............: avg=0ns      min=0s       med=0s       max=110.47µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=142.57µs min=95.3µs   med=136.86µs max=7.3ms    p(90)=158µs    p(95)=164.28µs
       { expected_response:true }...: avg=142.57µs min=95.3µs   med=136.86µs max=7.3ms    p(90)=158µs    p(95)=164.28µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 146532
     http_req_receiving.............: avg=24.58µs  min=12.64µs  med=23.47µs  max=448.69µs p(90)=30.4µs   p(95)=32.41µs 
     http_req_sending...............: avg=6.32µs   min=4.06µs   med=5.6µs    max=347.35µs p(90)=8.16µs   p(95)=8.76µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=111.66µs min=71.05µs  med=105.56µs max=7.19ms   p(90)=123.59µs p(95)=128.83µs
     http_reqs......................: 146532  4884.207999/s
     iteration_duration.............: avg=200.19µs min=142.05µs med=193.96µs max=7.49ms   p(90)=217.57µs p(95)=225.88µs
     iterations.....................: 146532  4884.207999/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

Copy link
Contributor

github-actions bot commented May 31, 2024

@benchmarks/server results (native)

     ✓ no-errors
     ✓ expected-result

   ✓ checks.........................: 100.00% ✓ 233444      ✗ 0     
     data_received..................: 24 MB   782 kB/s
     data_sent......................: 9.3 MB  311 kB/s
     http_req_blocked...............: avg=1.35µs   min=881ns    med=1.16µs   max=270.62µs p(90)=1.87µs   p(95)=2.03µs  
     http_req_connecting............: avg=1ns      min=0s       med=0s       max=120.39µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=197.38µs min=151.32µs med=185.01µs max=12.36ms  p(90)=211.19µs p(95)=220.55µs
       { expected_response:true }...: avg=197.38µs min=151.32µs med=185.01µs max=12.36ms  p(90)=211.19µs p(95)=220.55µs
     http_req_failed................: 0.00%   ✓ 0           ✗ 116722
     http_req_receiving.............: avg=24.97µs  min=13.28µs  med=23.43µs  max=2.97ms   p(90)=30.36µs  p(95)=32.54µs 
     http_req_sending...............: avg=5.95µs   min=4.02µs   med=5.15µs   max=1.4ms    p(90)=7.91µs   p(95)=8.29µs  
     http_req_tls_handshaking.......: avg=0s       min=0s       med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=166.45µs min=124µs    med=154.12µs max=12.31ms  p(90)=176.71µs p(95)=185.35µs
     http_reqs......................: 116722  3890.600335/s
     iteration_duration.............: avg=252.71µs min=201.3µs  med=239.69µs max=12.45ms  p(90)=269.18µs p(95)=280.71µs
     iterations.....................: 116722  3890.600335/s
     vus............................: 1       min=1         max=1   
     vus_max........................: 1       min=1         max=1   

@ardatan ardatan force-pushed the better-fastify-support branch from 0e72e3d to 1c1d931 Compare July 26, 2024 14:15
ardatan added 2 commits July 26, 2024 17:22
Prevent extra patching

Better support on Fastify

Better changeset

Even easier

Update the changeset
@ardatan ardatan force-pushed the better-fastify-support branch from 1c1d931 to d85e825 Compare July 26, 2024 14:43
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