-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
191 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ jobs: | |
run: npm install | ||
- name: Run tests | ||
run: npm test | ||
- name: Run benchmark | ||
run: npm run benchmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import fastify from 'fastify' | ||
|
||
const app = fastify({ | ||
logger: false, | ||
}) | ||
|
||
app.get('/', (req, reply) => { | ||
reply.send({ hello: 'world' }) | ||
}) | ||
|
||
app.listen({ port: 3000 }, async (err, address) => { | ||
if (err) throw err | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import fastify from 'fastify' | ||
|
||
import { serverFactory } from '../src/server.js' | ||
|
||
const app = fastify({ | ||
logger: false, | ||
serverFactory, | ||
}) | ||
|
||
app.get('/', (req, reply) => { | ||
reply.send({ hello: 'world' }) | ||
}) | ||
|
||
app.listen({ port: 3000 }, async (err, address) => { | ||
if (err) throw err | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { fork } from 'node:child_process' | ||
|
||
import autocannon from 'autocannon' | ||
import autocannonCompare from 'autocannon-compare' | ||
|
||
const benchs = [ | ||
{ | ||
name: 'fastify-node', | ||
file: 'fastify-node.js', | ||
}, | ||
{ | ||
name: 'fastify-uws', | ||
file: 'fastify-uws.js', | ||
}, | ||
] | ||
|
||
const results = new Map() | ||
|
||
for (const bench of benchs) { | ||
const child = fork(`./benchmarks/${bench.file}`) | ||
|
||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
|
||
const result = await autocannon({ | ||
url: `http://localhost:3000/${bench.file}`, | ||
connections: 100, | ||
pipelining: 10, | ||
duration: 3, | ||
}) | ||
|
||
results.set(bench.name, { | ||
name: bench.name, | ||
...result, | ||
}) | ||
|
||
child.kill('SIGINT') | ||
} | ||
|
||
const a = results.get('fastify-node') | ||
const b = results.get('fastify-uws') | ||
|
||
const comp = autocannonCompare(a, b) | ||
|
||
console.log(`a: ${a.requests.average}`) | ||
console.log(`b: ${b.requests.average}`) | ||
|
||
if (comp.equal) { | ||
console.log('Same performance!') | ||
} else if (comp.aWins) { | ||
console.log(`${a.name} is faster than ${b.name} by ${comp.requests.difference} of difference`) | ||
} else { | ||
console.log(`${b.name} is faster than ${a.name} by ${autocannonCompare(b, a).requests.difference} of difference`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,9 +79,8 @@ export class Request extends Readable { | |
|
||
if (!data) { | ||
this.readableEnded = true | ||
cb() | ||
} | ||
|
||
cb() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.