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

Add performance test #6

Open
wants to merge 2 commits 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
168 changes: 168 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Performance

uWebSockets-express is at the Fastify level, but not at the uWebSockets level.

Used [autocannon tool](https://github.com/mcollina/autocannon)

## Helloworld

### Express

```
Running 5s test @ http://localhost:3000
1000 connections

┌─────────┬────────┬────────┬────────┬────────┬───────────┬──────────┬────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼────────┼────────┼────────┼────────┼───────────┼──────────┼────────┤
│ Latency │ 128 ms │ 136 ms │ 347 ms │ 393 ms │ 147.28 ms │ 45.48 ms │ 420 ms │
└─────────┴────────┴────────┴────────┴────────┴───────────┴──────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬────────┬─────────┬─────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────────┼─────────┼─────────┼────────┼─────────┼─────────┼─────────┤
│ Req/Sec │ 4511 │ 4511 │ 7343 │ 7515 │ 6780.4 │ 1146.77 │ 4511 │
├───────────┼─────────┼─────────┼─────────┼────────┼─────────┼─────────┼─────────┤
│ Bytes/Sec │ 1.08 MB │ 1.08 MB │ 1.76 MB │ 1.8 MB │ 1.62 MB │ 274 kB │ 1.08 MB │
└───────────┴─────────┴─────────┴─────────┴────────┴─────────┴─────────┴─────────┘

Req/Bytes counts sampled once per second.

34k requests in 5.24s, 8.1 MB read
```

### uWebSockets-express

```
Running 5s test @ http://localhost:3000
1000 connections

┌─────────┬───────┬───────┬───────┬───────┬──────────┬──────────┬────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼───────┼───────┼───────┼───────┼──────────┼──────────┼────────┤
│ Latency │ 30 ms │ 32 ms │ 53 ms │ 70 ms │ 35.39 ms │ 25.16 ms │ 355 ms │
└─────────┴───────┴───────┴───────┴───────┴──────────┴──────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Req/Sec │ 20671 │ 20671 │ 30015 │ 31967 │ 28689.6 │ 4182.55 │ 20666 │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Bytes/Sec │ 1.92 MB │ 1.92 MB │ 2.79 MB │ 2.97 MB │ 2.67 MB │ 389 kB │ 1.92 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘

Req/Bytes counts sampled once per second.

143k requests in 5.27s, 13.3 MB read
```

### Fastify

```
Running 5s test @ http://localhost:3000
1000 connections

┌─────────┬───────┬───────┬───────┬───────┬──────────┬──────────┬────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼───────┼───────┼───────┼───────┼──────────┼──────────┼────────┤
│ Latency │ 23 ms │ 35 ms │ 58 ms │ 89 ms │ 37.27 ms │ 23.34 ms │ 314 ms │
└─────────┴───────┴───────┴───────┴───────┴──────────┴──────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Req/Sec │ 20751 │ 20751 │ 27951 │ 29087 │ 26824 │ 3088.25 │ 20740 │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ Bytes/Sec │ 3.65 MB │ 3.65 MB │ 4.92 MB │ 5.12 MB │ 4.72 MB │ 544 kB │ 3.65 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘

Req/Bytes counts sampled once per second.

134k requests in 5.19s, 23.6 MB read
```

## Helloworldejs

### Express

```
Running 30s test @ http://localhost:3000
1000 connections

┌─────────┬────────┬────────┬────────┬────────┬───────────┬──────────┬─────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼────────┼────────┼────────┼────────┼───────────┼──────────┼─────────┤
│ Latency │ 259 ms │ 276 ms │ 562 ms │ 599 ms │ 298.67 ms │ 77.45 ms │ 2256 ms │
└─────────┴────────┴────────┴────────┴────────┴───────────┴──────────┴─────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Req/Sec │ 1405 │ 1405 │ 3571 │ 3779 │ 3336.84 │ 602.83 │ 1405 │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Bytes/Sec │ 2.25 MB │ 2.25 MB │ 5.73 MB │ 6.06 MB │ 5.35 MB │ 967 kB │ 2.25 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴────────┴─────────┘
┌──────┬────────┐
│ Code │ Count │
├──────┼────────┤
│ 200 │ 100091 │
└──────┴────────┘

Req/Bytes counts sampled once per second.

100k requests in 30.2s, 161 MB read
```

### uWebSockets-express

```
Running 30s test @ http://localhost:3000
1000 connections

┌─────────┬────────┬────────┬────────┬────────┬───────────┬──────────┬────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼────────┼────────┼────────┼────────┼───────────┼──────────┼────────┤
│ Latency │ 103 ms │ 106 ms │ 114 ms │ 117 ms │ 107.21 ms │ 10.68 ms │ 298 ms │
└─────────┴────────┴────────┴────────┴────────┴───────────┴──────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Req/Sec │ 8191 │ 8191 │ 9351 │ 9503 │ 9291.54 │ 234.84 │ 8191 │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Bytes/Sec │ 11.9 MB │ 11.9 MB │ 13.6 MB │ 13.8 MB │ 13.5 MB │ 341 kB │ 11.9 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴────────┴─────────┘
┌──────┬────────┐
│ Code │ Count │
├──────┼────────┤
│ 200 │ 278744 │
└──────┴────────┘

Req/Bytes counts sampled once per second.

279k requests in 30.18s, 406 MB read
```

### Fastify

```
Running 30s test @ http://localhost:3000
1000 connections

┌─────────┬────────┬────────┬────────┬────────┬───────────┬──────────┬────────┐
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
├─────────┼────────┼────────┼────────┼────────┼───────────┼──────────┼────────┤
│ Latency │ 128 ms │ 133 ms │ 148 ms │ 153 ms │ 135.14 ms │ 14.53 ms │ 373 ms │
└─────────┴────────┴────────┴────────┴────────┴───────────┴──────────┴────────┘
┌───────────┬─────────┬─────────┬─────────┬─────────┬─────────┬────────┬─────────┐
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Req/Sec │ 5955 │ 5955 │ 7443 │ 7599 │ 7373.47 │ 301.02 │ 5952 │
├───────────┼─────────┼─────────┼─────────┼─────────┼─────────┼────────┼─────────┤
│ Bytes/Sec │ 9.07 MB │ 9.07 MB │ 11.3 MB │ 11.6 MB │ 11.2 MB │ 459 kB │ 9.06 MB │
└───────────┴─────────┴─────────┴─────────┴─────────┴─────────┴────────┴─────────┘
┌──────┬────────┐
│ Code │ Count │
├──────┼────────┤
│ 200 │ 221196 │
└──────┴────────┘

Req/Bytes counts sampled once per second.

221k requests in 30.18s, 337 MB read
```
11 changes: 11 additions & 0 deletions examples/helloworld/Express/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express')
const app = express()
const port = 3000

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

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
11 changes: 11 additions & 0 deletions examples/helloworld/Fastify/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express')
const app = require('fastify')()
const port = 3000

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

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
15 changes: 15 additions & 0 deletions examples/helloworld/uWebSockets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const uWS = require("uWebSockets.js");
const expressify = require("uwebsockets-express").default;

const uwsApp = uWS.App();
const app = expressify(uwsApp);

const port = 3000;

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

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});
18 changes: 18 additions & 0 deletions examples/helloworldejs/Express/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const express = require('express')
const app = express()
const port = 3000

app.set('view engine', 'ejs');

app.get('/', (req, res) => {
let names = ["Alex", "Smith", "Daniel", "James", "Arno", "Elisa", "Kaile", "Julia", "Jana"]

res.locals.name = names[Math.floor(names.length * Math.random())]
res.locals.age = 15 + Math.floor(Math.random() * 30)

res.render("index.ejs", res.locals)
})

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
60 changes: 60 additions & 0 deletions examples/helloworldejs/Express/views/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<style media="all">
body{
margin: 0;
}

#hi {
height: 500px; /* Element */
margin: 0;
padding: 0;
line-height:500px;
text-align: center;

font-size: 5em; /* Font */
font-family: Monospace;
word-wrap: break-word;
color: #fff;

background: rgb(13,0,232); /* Background */
background: linear-gradient(45deg, rgba(13,0,232,1) 0%, rgba(0,212,255,1) 100%);
}

.hr-line {
height: 0px;
margin: 0px 0;
padding: 0;
height: 0;
border: none;
border-top: 1px solid #333;
}

#name {
height: 500px; /* Element */
margin:0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
text-align: center;

font-size: 3em; /* Font */
font-family: Monospace;
word-wrap: break-word;
color: #fff;

background: rgb(13,0,232); /* Background */
background: linear-gradient(45deg, rgba(13,0,232,1) 0%, rgba(255,0,215,1) 100%);
}
</style>
</head>
<body>
<h1 id="hi">Hello World</h1>
<hr class="hr-line">
<h2 id="name"><%= name + ", I know your age. Is " + age + "... May be."%></h2>
</body>
</html>
19 changes: 19 additions & 0 deletions examples/helloworldejs/Fastify/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const app = require('fastify')()

const port = 3000;

let ejs = require('ejs');

app.get('/', (req, res) => {
let names = ["Alex", "Smith", "Daniel", "James", "Arno", "Elisa", "Kaile", "Julia", "Jana"]
ejs.renderFile("./views/index.ejs", {name: names[Math.floor(names.length * Math.random())], age: 15 + Math.floor(Math.random() * 30)}, (err, result) => {
if (err) {
console.log(err);
}
res.type('text/html').send(result)
})
})

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
60 changes: 60 additions & 0 deletions examples/helloworldejs/Fastify/views/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<style media="all">
body{
margin: 0;
}

#hi {
height: 500px; /* Element */
margin: 0;
padding: 0;
line-height:500px;
text-align: center;

font-size: 5em; /* Font */
font-family: Monospace;
word-wrap: break-word;
color: #fff;

background: rgb(13,0,232); /* Background */
background: linear-gradient(45deg, rgba(13,0,232,1) 0%, rgba(0,212,255,1) 100%);
}

.hr-line {
height: 0px;
margin: 0px 0;
padding: 0;
height: 0;
border: none;
border-top: 1px solid #333;
}

#name {
height: 500px; /* Element */
margin:0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
text-align: center;

font-size: 3em; /* Font */
font-family: Monospace;
word-wrap: break-word;
color: #fff;

background: rgb(13,0,232); /* Background */
background: linear-gradient(45deg, rgba(13,0,232,1) 0%, rgba(255,0,215,1) 100%);
}
</style>
</head>
<body>
<h1 id="hi">Hello World</h1>
<hr class="hr-line">
<h2 id="name"><%= name + ", I know your age. Is " + age + "... May be."%></h2>
</body>
</html>
Loading