Skip to content

Commit 5e9b592

Browse files
fengmk2Copilotcoderabbitai[bot]
authored
feat: add reusePort benchmark (#22)
eggjs/egg#5365 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Migrated CI from Travis to GitHub Actions and added multi-version Node.js runs. * Added automation to build/ensure benchmarking tool and integrated it into CI scripts. * Expanded runtime test sequences to cover additional service variants, ports, and longer latency-measured blocks. * **Documentation** * Reformatted README lists and added a Contributors subsection. * **Dependencies** * Updated dependency aliases and adjusted test/ci scripts to use the new tooling. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 1aa236f commit 5e9b592

File tree

7 files changed

+126
-75
lines changed

7 files changed

+126
-75
lines changed

.github/workflows/nodejs.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
Job:
11+
name: Node.js
12+
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
13+
with:
14+
os: 'ubuntu-latest'
15+
version: '18, 20, 22, 24'
16+
install: npm run install-wrk > wrk.log && npm install && cat /proc/cpuinfo

.travis.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,45 @@ egg benchmark
1010

1111
## Default Middleware
1212

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

1818
## Scenes
1919

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

2424
## Scripts
2525

26-
- koa1: `wrk http://127.0.0.1:7001/ -d 10 -c 50 -t 8`
27-
- koa2: `wrk http://127.0.0.1:7002/ -d 10 -c 50 -t 8`
28-
- egg1: `wrk http://127.0.0.1:7003/ -d 10 -c 50 -t 8`
29-
- egg2: `wrk http://127.0.0.1:7004/ -d 10 -c 50 -t 8`
30-
- egg3: `wrk http://127.0.0.1:7005/ -d 10 -c 50 -t 8`
31-
- egg3 with worker_threads: `wrk http://127.0.0.1:7006/ -d 10 -c 50 -t 8`
26+
* koa1: `wrk http://127.0.0.1:7001/ -d 10 -c 50 -t 8`
27+
* koa2: `wrk http://127.0.0.1:7002/ -d 10 -c 50 -t 8`
28+
* egg1: `wrk http://127.0.0.1:7003/ -d 10 -c 50 -t 8`
29+
* egg2: `wrk http://127.0.0.1:7004/ -d 10 -c 50 -t 8`
30+
* egg3: `wrk http://127.0.0.1:7005/ -d 10 -c 50 -t 8`
31+
* egg3 with worker_threads: `wrk http://127.0.0.1:7006/ -d 10 -c 50 -t 8`
32+
* egg3 with reusePort: `wrk http://127.0.0.1:7008/ -d 10 -c 50 -t 8`
3233

3334
## Server
3435

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

3839
## CPU Profiler
3940

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

4243
## Known issues
4344

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

4647
## Last Results
4748

48-
- [Visualization](https://eggjs.github.io/benchmark/plot/)
49-
- [Statistics data](https://github.com/eggjs/benchmark/blob/master/plot/all.csv)
49+
* [Visualization](https://eggjs.github.io/benchmark/plot/)
50+
* [Statistics data](https://github.com/eggjs/benchmark/blob/master/plot/all.csv)
51+
52+
## Contributors
53+
54+
[![contributors](https://contrib.rocks/image?repo=eggjs/benchmark&max=240&columns=26)](https://github.com/eggjs/benchmark/graphs/contributors)

install-wrk.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
[ ! -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

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"egg-passport": "^2.0.0",
88
"egg-view-ejs": "^2.0.0",
99
"egg-view-nunjucks": "^2.1.4",
10-
"egg1": "^1.11.0",
11-
"egg2": "^2.37.0",
12-
"egg3": "^3.3.3",
10+
"egg1": "npm:egg@1",
11+
"egg2": "npm:egg@2",
12+
"egg3": "npm:egg@3",
1313
"koa": "^2.13.4",
1414
"koa-router": "^12.0.0",
1515
"nunjucks": "^3.0.1"
@@ -22,11 +22,12 @@
2222
"node": ">=14.20.0"
2323
},
2424
"scripts": {
25-
"test-simple": "simple/run.sh",
25+
"install-wrk": "pwd && ls -l . && sh install-wrk.sh",
26+
"test-simple": "NODE_DEBUG=egg-cluster:app_worker simple/run.sh",
2627
"test-simple-view": "simple_view/run.sh",
2728
"test-simple-passport": "simple_passport/run.sh",
2829
"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",
29-
"ci": "EGG_SERVER_ENV=prod npm test"
30+
"ci": "PATH=$PWD/wrk/bin:$PATH EGG_SERVER_ENV=prod npm test"
3031
},
3132
"repository": {
3233
"type": "git",

simple/dispatch.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ const egg3 = require('egg3');
22
const egg2 = require('egg2');
33
const egg1 = require('egg1');
44
const cluster = require('cluster');
5+
const os = require('os');
56

6-
let workers = Number(process.argv[2] || require('os').cpus().length);
7+
let workers = Number(process.argv[2] || os.cpus().length);
78
if (workers > 4) {
89
workers = 4;
910
}
1011

1112
if (cluster.isMaster) {
13+
console.log('os version: %s', os.version());
14+
console.log('egg-cluster version: %s', require('egg-cluster/package.json').version);
15+
1216
egg1.startCluster({
1317
workers,
1418
baseDir: __dirname,
@@ -30,6 +34,14 @@ if (cluster.isMaster) {
3034
framework: 'egg3',
3135
});
3236

37+
egg3.startCluster({
38+
workers,
39+
baseDir: __dirname,
40+
port: 7008,
41+
framework: 'egg3',
42+
reusePort: true,
43+
});
44+
3345
egg3.startCluster({
3446
startMode: 'worker_threads',
3547
workers: 1,
@@ -38,6 +50,15 @@ if (cluster.isMaster) {
3850
framework: 'egg3',
3951
});
4052

53+
egg3.startCluster({
54+
startMode: 'worker_threads',
55+
workers,
56+
port: 7009,
57+
baseDir: __dirname,
58+
framework: 'egg3',
59+
reusePort: true,
60+
});
61+
4162
for (let i = 0; i < workers; i++) {
4263
cluster.fork();
4364
}

simple/run.sh

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ curl 'http://127.0.0.1:7003/'
1414
curl 'http://127.0.0.1:7004/'
1515
curl 'http://127.0.0.1:7005/'
1616
curl 'http://127.0.0.1:7006/'
17+
curl 'http://127.0.0.1:7008/'
18+
curl 'http://127.0.0.1:7009/'
1719

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

@@ -25,58 +27,88 @@ function print_head {
2527
printf "\"$TITLE\"," >> $CSV
2628
}
2729

30+
sleep 5
2831
echo ""
29-
echo "------- koa hello -------"
32+
echo "------- egg3 hello with reusePort=true -------"
3033
echo ""
31-
print_head "koa" "koa hello"
32-
wrk 'http://127.0.0.1:7002/' \
33-
-d 10 \
34+
print_head "egg3" "egg3 hello with reusePort=true"
35+
wrk 'http://127.0.0.1:7008/' \
36+
-d 30 \
3437
-c 50 \
3538
-t 8 \
39+
--latency \
3640
-s $REPORT
3741

38-
sleep 3
42+
sleep 5
3943
echo ""
40-
echo "------- egg1 hello -------"
44+
echo "------- egg3 hello -------"
4145
echo ""
42-
print_head "egg1" "egg1 hello"
43-
wrk 'http://127.0.0.1:7003/' \
44-
-d 10 \
46+
print_head "egg3" "egg3 hello"
47+
wrk 'http://127.0.0.1:7005/' \
48+
-d 30 \
4549
-c 50 \
4650
-t 8 \
51+
--latency \
4752
-s $REPORT
4853

49-
sleep 3
54+
sleep 5
5055
echo ""
51-
echo "------- egg2 hello -------"
56+
echo "------- egg3 hello with worker_threads=1 -------"
5257
echo ""
53-
print_head "egg2" "egg2 hello"
54-
wrk 'http://127.0.0.1:7004/' \
55-
-d 10 \
58+
print_head "egg3" "egg3 hello with worker_threads=1"
59+
wrk 'http://127.0.0.1:7006/' \
60+
-d 30 \
5661
-c 50 \
5762
-t 8 \
63+
--latency \
5864
-s $REPORT
5965

60-
sleep 3
66+
sleep 5
6167
echo ""
62-
echo "------- egg3 hello -------"
68+
echo "------- egg3 hello with worker_threads and reusePort=true -------"
6369
echo ""
64-
print_head "egg3" "egg3 hello"
65-
wrk 'http://127.0.0.1:7005/' \
66-
-d 10 \
70+
print_head "egg3" "egg3 hello with worker_threads and reusePort=true"
71+
wrk 'http://127.0.0.1:7009/' \
72+
-d 30 \
6773
-c 50 \
6874
-t 8 \
75+
--latency \
6976
-s $REPORT
7077

71-
sleep 3
78+
sleep 5
7279
echo ""
73-
echo "------- egg3 hello with worker_threads=1 -------"
80+
echo "------- koa hello -------"
7481
echo ""
75-
print_head "egg3" "egg3 hello with worker_threads=1"
76-
wrk 'http://127.0.0.1:7006/' \
77-
-d 10 \
82+
print_head "koa" "koa hello"
83+
wrk 'http://127.0.0.1:7002/' \
84+
-d 30 \
85+
-c 50 \
86+
-t 8 \
87+
--latency \
88+
-s $REPORT
89+
90+
sleep 5
91+
echo ""
92+
echo "------- egg1 hello -------"
93+
echo ""
94+
print_head "egg1" "egg1 hello"
95+
wrk 'http://127.0.0.1:7003/' \
96+
-d 30 \
97+
-c 50 \
98+
-t 8 \
99+
--latency \
100+
-s $REPORT
101+
102+
sleep 5
103+
echo ""
104+
echo "------- egg2 hello -------"
105+
echo ""
106+
print_head "egg2" "egg2 hello"
107+
wrk 'http://127.0.0.1:7004/' \
108+
-d 30 \
78109
-c 50 \
79110
-t 8 \
111+
--latency \
80112
-s $REPORT
81113

82114
kill $pid

0 commit comments

Comments
 (0)