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: add reusePort benchmark #22

Open
wants to merge 6 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
16 changes: 16 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
Job:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
os: 'ubuntu-latest'
version: '14, 16, 18, 20, 22, 23'
install: npm run install-wrk > wrk.log && npm install && cat /proc/cpuinfo
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,44 @@ egg benchmark

## Default Middleware

- egg default enable 15 middlewares (6 security middlewares enable by default)
- enable router
- passport has 17 middlewares (15 default, 2 passport middlewares)
- csrf are disabled, because in most situation we won't caculate csrf token and set to cookie
* egg default enable 15 middlewares (6 security middlewares enable by default)
* enable router
* passport has 17 middlewares (15 default, 2 passport middlewares)
* csrf are disabled, because in most situation we won't caculate csrf token and set to cookie

## Scenes

- Hello World: `$ EGG_SERVER_ENV=prod node benchmarks/simple/dispatch.js`
- nunjucks: `$ EGG_SERVER_ENV=prod node benchmarks/simple_view/dispatch.js`
- Empty passport: `$ EGG_SERVER_ENV=prod node benchmarks/simple_passport/dispatch.js`
* Hello World: `$ EGG_SERVER_ENV=prod node benchmarks/simple/dispatch.js`
* nunjucks: `$ EGG_SERVER_ENV=prod node benchmarks/simple_view/dispatch.js`
* Empty passport: `$ EGG_SERVER_ENV=prod node benchmarks/simple_passport/dispatch.js`

## Scripts

- koa1: `wrk http://127.0.0.1:7001/ -d 10 -c 50 -t 8`
- koa2: `wrk http://127.0.0.1:7002/ -d 10 -c 50 -t 8`
- egg1: `wrk http://127.0.0.1:7003/ -d 10 -c 50 -t 8`
- egg2: `wrk http://127.0.0.1:7004/ -d 10 -c 50 -t 8`
- egg3: `wrk http://127.0.0.1:7005/ -d 10 -c 50 -t 8`
- egg3 with worker_threads: `wrk http://127.0.0.1:7006/ -d 10 -c 50 -t 8`
* koa1: `wrk http://127.0.0.1:7001/ -d 10 -c 50 -t 8`
* koa2: `wrk http://127.0.0.1:7002/ -d 10 -c 50 -t 8`
* egg1: `wrk http://127.0.0.1:7003/ -d 10 -c 50 -t 8`
* egg2: `wrk http://127.0.0.1:7004/ -d 10 -c 50 -t 8`
* egg3: `wrk http://127.0.0.1:7005/ -d 10 -c 50 -t 8`
* egg3 with worker_threads: `wrk http://127.0.0.1:7006/ -d 10 -c 50 -t 8`

## Server

- MacBook Pro (Retina, 15-inch, Late 2013)
- 2 GHz Intel Core i7 (only use 4 core for benchmark)
* MacBook Pro (Retina, 15-inch, Late 2013)
* 2 GHz Intel Core i7 (only use 4 core for benchmark)

## CPU Profiler

![image](https://user-images.githubusercontent.com/985607/32961302-a6d1d506-cb8d-11e7-9273-160d8ba77da6.png)

## Known issues

- `Date.now()` cost a lot of CPU time(7%) in `meta` middleware and `CreateContext` method.
* `Date.now()` cost a lot of CPU time(7%) in `meta` middleware and `CreateContext` method.

## Last Results

- [Visualization](https://eggjs.github.io/benchmark/plot/)
- [Statistics data](https://github.com/eggjs/benchmark/blob/master/plot/all.csv)
* [Visualization](https://eggjs.github.io/benchmark/plot/)
* [Statistics data](https://github.com/eggjs/benchmark/blob/master/plot/all.csv)

## Contributors

[![contributors](https://contrib.rocks/image?repo=eggjs/benchmark&max=240&columns=26)](https://github.com/eggjs/benchmark/graphs/contributors)
3 changes: 3 additions & 0 deletions install-wrk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

[ ! -f wrk/bin/wrk ] && rm -rf wrk && git clone --depth 1 https://github.com/wg/wrk.git && make -j10 -C wrk && mkdir wrk/bin && mv wrk/wrk wrk/bin || true
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"description": "egg benchmark",
"private": true,
"dependencies": {
"egg-cluster": "^2.4.0-beta.0",
"egg-passport": "^2.0.0",
"egg-view-ejs": "^2.0.0",
"egg-view-nunjucks": "^2.1.4",
"egg1": "^1.11.0",
"egg2": "^2.37.0",
"egg3": "^3.3.3",
"egg1": "npm:egg@1",
"egg2": "npm:egg@2",
"egg3": "npm:egg@3",
"koa": "^2.13.4",
"koa-router": "^12.0.0",
"nunjucks": "^3.0.1"
Expand All @@ -22,11 +23,12 @@
"node": ">=14.20.0"
},
"scripts": {
"install-wrk": "pwd && ls -l . && sh install-wrk.sh",
"test-simple": "simple/run.sh",
"test-simple-view": "simple_view/run.sh",
"test-simple-passport": "simple_passport/run.sh",
"test": "cat stats-header.csv > stats.csv && npm run test-simple && npm run test-simple-view && npm run test-simple-passport && cp stats.csv plot/all.csv",
"ci": "EGG_SERVER_ENV=prod npm test"
"ci": "PATH=$PWD/wrk/bin:$PATH EGG_SERVER_ENV=prod npm test"
},
"repository": {
"type": "git",
Expand Down
12 changes: 12 additions & 0 deletions simple/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ const egg3 = require('egg3');
const egg2 = require('egg2');
const egg1 = require('egg1');
const cluster = require('cluster');
const os = require('os');

let workers = Number(process.argv[2] || require('os').cpus().length);
if (workers > 4) {
workers = 4;
}

if (cluster.isMaster) {
console.log('os version: %s', os.version());
console.log('egg-cluster version: %s', require('egg-cluster/package.json').version);

egg1.startCluster({
workers,
baseDir: __dirname,
Expand All @@ -30,6 +34,14 @@ if (cluster.isMaster) {
framework: 'egg3',
});

require('egg-cluster').startCluster(({
workers,
baseDir: __dirname,
port: 7008,
framework: 'egg3',
reusePort: true,
}));

egg3.startCluster({
startMode: 'worker_threads',
workers: 1,
Expand Down
42 changes: 27 additions & 15 deletions simple/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ curl 'http://127.0.0.1:7003/'
curl 'http://127.0.0.1:7004/'
curl 'http://127.0.0.1:7005/'
curl 'http://127.0.0.1:7006/'
curl 'http://127.0.0.1:7008/'

test `tail -c 1 $CSV` && printf "\n" >> $CSV

Expand All @@ -25,55 +26,66 @@ function print_head {
printf "\"$TITLE\"," >> $CSV
}

sleep 3
echo ""
echo "------- koa hello -------"
echo "------- egg3 hello -------"
echo ""
print_head "koa" "koa hello"
wrk 'http://127.0.0.1:7002/' \
print_head "egg3" "egg3 hello"
wrk 'http://127.0.0.1:7005/' \
-d 10 \
-c 50 \
-t 8 \
-s $REPORT

sleep 3
echo ""
echo "------- egg1 hello -------"
echo "------- egg3 hello with reusePort=true -------"
echo ""
print_head "egg1" "egg1 hello"
wrk 'http://127.0.0.1:7003/' \
print_head "egg3" "egg3 hello with reusePort=true"
wrk 'http://127.0.0.1:7008/' \
-d 10 \
-c 50 \
-t 8 \
-s $REPORT

sleep 3
echo ""
echo "------- egg2 hello -------"
echo "------- egg3 hello with worker_threads=1 -------"
echo ""
print_head "egg2" "egg2 hello"
wrk 'http://127.0.0.1:7004/' \
print_head "egg3" "egg3 hello with worker_threads=1"
wrk 'http://127.0.0.1:7006/' \
-d 10 \
-c 50 \
-t 8 \
-s $REPORT

echo ""
echo "------- koa hello -------"
echo ""
print_head "koa" "koa hello"
wrk 'http://127.0.0.1:7002/' \
-d 10 \
-c 50 \
-t 8 \
-s $REPORT

sleep 3
echo ""
echo "------- egg3 hello -------"
echo "------- egg1 hello -------"
echo ""
print_head "egg3" "egg3 hello"
wrk 'http://127.0.0.1:7005/' \
print_head "egg1" "egg1 hello"
wrk 'http://127.0.0.1:7003/' \
-d 10 \
-c 50 \
-t 8 \
-s $REPORT

sleep 3
echo ""
echo "------- egg3 hello with worker_threads=1 -------"
echo "------- egg2 hello -------"
echo ""
print_head "egg3" "egg3 hello with worker_threads=1"
wrk 'http://127.0.0.1:7006/' \
print_head "egg2" "egg2 hello"
wrk 'http://127.0.0.1:7004/' \
-d 10 \
-c 50 \
-t 8 \
Expand Down
Loading