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

Benchmark Testing #5845

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,27 @@ You can use `make && node -v` to include the node.js version in the output.
### Tip: Save the results to a file

You can use `make > results.log` to save the results to a file `results.log`.

# Result full test

```bash
$ node ./tools/check-benchmarks.js
```

| (index) | Framework | Requests/sec | Transfer/sec | Latency | Total Requests | Transfer Total | Latency Stdev | Latency Max |
|---------|--------------------|--------------|--------------|------------|----------------|----------------|---------------|-------------|
| 0 | cluster_fastify | 138457.36 | 23.24MB | 15.58ms | 1388733 | 233.09MB | 58.10ms | 842.11ms |
| 1 | cluster_http | 137054.68 | 23.27MB | 14.56ms | 1376920 | 233.74MB | 52.84ms | 802.10ms |
| 2 | cluster_koa | 122922.41 | 20.51MB | 14.97ms | 1234474 | 206.03MB | 52.39ms | 823.15ms |
| 3 | cluster_hapi | 94445.64 | 19.91MB | 23.66ms | 949082 | 200.03MB | 83.97ms | 1.10s |
| 4 | cluster_restify | 93398.96 | 16.48MB | 22.78ms | 937893 | 165.47MB | 79.86ms | 1.09s |
| 5 | cluster_express | 43577.99 | 9.89MB | 60.64ms | 437738 | 99.36MB | 190.66ms | 2.00s |
| 6 | single_uws | 37081.93 | 3.71MB | 27.45ms | 372355 | 37.29MB | 3.06ms | 76.40ms |
| 7 | cluster_uws | 35629.39 | 3.57MB | 28.57ms | 357699 | 35.82MB | 1.82ms | 95.33ms |
| 8 | single_http | 24159.04 | 4.10MB | 42.09ms | 242998 | 41.25MB | 7.12ms | 235.08ms |
| 9 | single_fastify | 23794.91 | 3.99MB | 43.18ms | 239197 | 40.15MB | 11.90ms | 343.66ms |
| 10 | single_koa | 20263.96 | 3.38MB | 50.25ms | 204371 | 34.11MB | 17.65ms | 294.61ms |
| 11 | single_hapi | 14163.93 | 2.99MB | 71.82ms | 142853 | 30.11MB | 16.06ms | 410.62ms |
| 12 | single_restify | 14036.58 | 2.48MB | 72.46ms | 141118 | 24.90MB | 13.49ms | 527.51ms |
| 13 | single_express | 6830.47 | 1.55MB | 147.89ms | 68993 | 15.66MB | 29.75ms | 626.75ms |

22 changes: 22 additions & 0 deletions benchmarks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "express-benchmarks",
"version": "0.0.1",
"author": "Andre Ferreira <[email protected]>",
"description": "Performance test",
"main": "index.js",
"devDependencies": {
"@hapi/hapi": "^21.3.10",
"express": "^4.19.2",
"fastify": "^4.28.1",
"koa": "^2.15.3",
"restify": "^11.1.0",
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.47.0"
},
"engines": {
"node": ">=12.0.0"
},
"dependencies": {
"bytes": "^3.1.2",
"wrk": "^1.2.1"
}
}
22 changes: 22 additions & 0 deletions benchmarks/servers/cluster_express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const cluster = require('cluster');
const express = require('express');
const numCPUs = 6;

if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++)
cluster.fork();

cluster.on('exit', (worker, code, signal) => {
cluster.fork();
});
} else {
const app = express();

app.get('/', (req, res) => {
res.send('Hello world');
});

app.listen(3000, () => {});
}
27 changes: 27 additions & 0 deletions benchmarks/servers/cluster_fastify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const cluster = require('cluster');
const numCPUs = 6;

if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}

cluster.on('exit', (worker, code, signal) => {
cluster.fork();
});
} else {
const fastify = require('fastify')();

fastify.get('/', async (req, reply) => {
reply.send('Hello world');
});

fastify.listen({ port: 3000 }, (err, address) => {
if (err) {
console.error(err);
process.exit(1);
}
});
}
39 changes: 39 additions & 0 deletions benchmarks/servers/cluster_hapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

const cluster = require('cluster');
const numCPUs = 6;

if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++)
cluster.fork();

cluster.on('exit', (worker, code, signal) => {
cluster.fork();
});
} else {
const Hapi = require('@hapi/hapi');

const init = async () => {
const server = Hapi.server({
port: 3000,
host: 'localhost'
});

server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
return 'Hello world';
}
});

await server.start();
};

process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});

init();
}
24 changes: 24 additions & 0 deletions benchmarks/servers/cluster_http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const cluster = require('cluster');
const http = require('http');
const numCPUs = 6;

if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++)
cluster.fork();

cluster.on('exit', (worker, code, signal) => {
cluster.fork();
});
} else {
const requestListener = (req, res) => {
if (req.method === 'GET' && req.url === '/') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello world');
}
};

const server = http.createServer(requestListener);
server.listen(3000);
}
22 changes: 22 additions & 0 deletions benchmarks/servers/cluster_koa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const cluster = require('cluster');
const numCPUs = 6;

if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++)
cluster.fork();

cluster.on('exit', (worker, code, signal) => {
cluster.fork();
});
} else {
const Koa = require('koa');
const app = new Koa();

app.use(async ctx => {
ctx.body = 'Hello world';
});

app.listen(3000);
}
24 changes: 24 additions & 0 deletions benchmarks/servers/cluster_restify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const cluster = require('cluster');
const numCPUs = 6;

if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++)
cluster.fork();

cluster.on('exit', (worker, code, signal) => {
cluster.fork();
});
} else {
const restify = require('restify');

const server = restify.createServer();

server.get('/', (req, res, next) => {
res.send('Hello world');
next();
});

server.listen(3000);
}
15 changes: 15 additions & 0 deletions benchmarks/servers/cluster_uws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

const { Worker, isMainThread } = require('worker_threads');
const uWS = require('uWebSockets.js');
const numCPUs = 6;
const port = 3000;

if (isMainThread) {
for (let i = 0; i < numCPUs; i++)
new Worker(__filename);
} else {
const app = uWS.App().get('/*', (res, req) => {
res.end('Hello World!');
}).listen(port, (token) => {});
}
17 changes: 17 additions & 0 deletions benchmarks/servers/single_cmmv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { startServer, getMessageFromCpp, processResponse } = require('../build/Release/cmmv_binding');

async function consumerLoop(id) {
setInterval(async () => {
const message = getMessageFromCpp();

if (message && message.reqId)
processResponse(message.reqId, `Hello from Consumer ${id}`);
}, 1)
}

startServer('127.0.0.1', 3000);

const numConsumers = 24;
for (let i = 1; i <= numConsumers; i++) {
consumerLoop(i).catch((error) => console.error(`Erro no Consumer ${i}:`, error));
}
7 changes: 7 additions & 0 deletions benchmarks/servers/single_express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const express = require('express');
const app = express();

app.get('/', (req, res) => res.send('Hello world'));
app.listen(3000);
5 changes: 5 additions & 0 deletions benchmarks/servers/single_fastify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const fastify = require('fastify')();
fastify.get('/', async (req, reply) => reply.send('Hello world'));
fastify.listen({ port: 3000 });
27 changes: 27 additions & 0 deletions benchmarks/servers/single_hapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const Hapi = require('@hapi/hapi');

const init = async () => {
const server = Hapi.server({
port: 3000,
host: 'localhost'
});

server.route({
method: 'GET',
path: '/',
handler: (request, h) => {
return 'Hello world';
}
});

await server.start();
};

process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});

init();
13 changes: 13 additions & 0 deletions benchmarks/servers/single_http.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const http = require('http');

const requestListener = (req, res) => {
if (req.method === 'GET' && req.url === '/') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello world');
}
};

const server = http.createServer(requestListener);
server.listen(3000);
10 changes: 10 additions & 0 deletions benchmarks/servers/single_koa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const Koa = require('koa');
const app = new Koa();

app.use(async ctx => {
ctx.body = 'Hello world';
});

app.listen(3000);
9 changes: 9 additions & 0 deletions benchmarks/servers/single_restify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const restify = require('restify');

const server = restify.createServer();
server.get('/', (req, res, next) => {
res.send('Hello world');
next();
});

server.listen(3000, () => {});
8 changes: 8 additions & 0 deletions benchmarks/servers/single_uws.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Minimal HTTP/3 example */

const uWS = require('uWebSockets.js');
const port = 3000;

uWS.App().get('/*', (res, req) => {
res.end('Hello World!');
}, 5).listen(port, () =>{});
Loading
Loading