From cf4f47cfc6916b488d4a3f6b26df7bbcff399c0f Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 26 Oct 2024 21:56:36 +0800 Subject: [PATCH 01/19] feat: add reusePort benchmark --- .github/workflows/nodejs.yml | 16 +++++++++++++++ .travis.yml | 27 ------------------------ README.md | 40 ++++++++++++++++++++---------------- install-wrk.sh | 3 +++ package.json | 10 +++++---- simple/dispatch.js | 8 ++++++++ simple/run.sh | 12 +++++++++++ 7 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/nodejs.yml delete mode 100644 .travis.yml create mode 100755 install-wrk.sh diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..c944422 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -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, macos-latest' + version: '14, 16, 18, 20, 22, 23' + install: npm run install-wrk && npm install diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c29442b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -sudo: false -language: node_js -node_js: - - '14' -cache: - directories: - - wrk/bin -before_script: - - '[ ! -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' - - export PATH=$PWD/wrk/bin:$PATH -script: - - nvm i 14 - - node -p 'process.versions' - - npm test - - mv stats.csv 14.csv - - nvm i 16 - - node -p 'process.versions' - - npm test - - mv stats.csv 16.csv - - nvm i 18 - - node -p 'process.versions' - - npm test - - mv stats.csv 18.csv - - nvm i 19 - - node -p 'process.versions' - - npm test - - mv stats.csv 19.csv diff --git a/README.md b/README.md index 2cc3c2a..d693674 100644 --- a/README.md +++ b/README.md @@ -10,30 +10,30 @@ 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 @@ -41,9 +41,13 @@ egg benchmark ## 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) diff --git a/install-wrk.sh b/install-wrk.sh new file mode 100755 index 0000000..6f7badf --- /dev/null +++ b/install-wrk.sh @@ -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 diff --git a/package.json b/package.json index 16d7708..f3d7a8d 100644 --- a/package.json +++ b/package.json @@ -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" @@ -22,11 +23,12 @@ "node": ">=14.20.0" }, "scripts": { + "install-wrk": "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", diff --git a/simple/dispatch.js b/simple/dispatch.js index f7437ff..8870490 100644 --- a/simple/dispatch.js +++ b/simple/dispatch.js @@ -30,6 +30,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, diff --git a/simple/run.sh b/simple/run.sh index e3c0a95..97c9a42 100755 --- a/simple/run.sh +++ b/simple/run.sh @@ -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 @@ -68,6 +69,17 @@ wrk 'http://127.0.0.1:7005/' \ -t 8 \ -s $REPORT +sleep 3 +echo "" +echo "------- egg3 hello with reusePort=true -------" +echo "" +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 "------- egg3 hello with worker_threads=1 -------" From 793527310c7140b4a2e78e7b76709feb15bf0116 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 26 Oct 2024 22:00:09 +0800 Subject: [PATCH 02/19] f --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3d7a8d..565d03f 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "node": ">=14.20.0" }, "scripts": { - "install-wrk": "install-wrk.sh", + "install-wrk": "pwd && ls -l . && install-wrk.sh", "test-simple": "simple/run.sh", "test-simple-view": "simple_view/run.sh", "test-simple-passport": "simple_passport/run.sh", From 0adccea1e2b312d873558dfb8aed2ba1344fce68 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 26 Oct 2024 22:01:30 +0800 Subject: [PATCH 03/19] f --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 565d03f..ad930bb 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "node": ">=14.20.0" }, "scripts": { - "install-wrk": "pwd && ls -l . && install-wrk.sh", + "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", From 378a496f6d4f1f5ca0bb56f95991b574d2ca106a Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 26 Oct 2024 22:06:33 +0800 Subject: [PATCH 04/19] f --- simple/dispatch.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simple/dispatch.js b/simple/dispatch.js index 8870490..64f127d 100644 --- a/simple/dispatch.js +++ b/simple/dispatch.js @@ -9,6 +9,8 @@ if (workers > 4) { } if (cluster.isMaster) { + console.log('egg-cluster version: %s', require('egg-cluster/package.json').version); + egg1.startCluster({ workers, baseDir: __dirname, From 5216bc1a4eee951172e410832da7722336544621 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 26 Oct 2024 22:11:58 +0800 Subject: [PATCH 05/19] f --- .github/workflows/nodejs.yml | 2 +- simple/dispatch.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index c944422..72ae194 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -13,4 +13,4 @@ jobs: with: os: 'ubuntu-latest, macos-latest' version: '14, 16, 18, 20, 22, 23' - install: npm run install-wrk && npm install + install: npm run install-wrk && npm install && cat /proc/cpuinfo diff --git a/simple/dispatch.js b/simple/dispatch.js index 64f127d..4c7fe0e 100644 --- a/simple/dispatch.js +++ b/simple/dispatch.js @@ -2,6 +2,7 @@ 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) { @@ -9,6 +10,7 @@ if (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({ From c544195b22341f16d75ad6cc27cdd638f49c4847 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Sat, 26 Oct 2024 22:21:34 +0800 Subject: [PATCH 06/19] f --- .github/workflows/nodejs.yml | 4 ++-- simple/run.sh | 38 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 72ae194..fd72da7 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -11,6 +11,6 @@ jobs: name: Node.js uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: - os: 'ubuntu-latest, macos-latest' + os: 'ubuntu-latest' version: '14, 16, 18, 20, 22, 23' - install: npm run install-wrk && npm install && cat /proc/cpuinfo + install: npm run install-wrk > wrk.log && npm install && cat /proc/cpuinfo diff --git a/simple/run.sh b/simple/run.sh index 97c9a42..d2e95f1 100755 --- a/simple/run.sh +++ b/simple/run.sh @@ -26,11 +26,12 @@ 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 \ @@ -38,10 +39,10 @@ wrk 'http://127.0.0.1:7002/' \ 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 \ @@ -49,21 +50,20 @@ wrk 'http://127.0.0.1:7003/' \ 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 -sleep 3 echo "" -echo "------- egg3 hello -------" +echo "------- koa hello -------" echo "" -print_head "egg3" "egg3 hello" -wrk 'http://127.0.0.1:7005/' \ +print_head "koa" "koa hello" +wrk 'http://127.0.0.1:7002/' \ -d 10 \ -c 50 \ -t 8 \ @@ -71,10 +71,10 @@ wrk 'http://127.0.0.1:7005/' \ sleep 3 echo "" -echo "------- egg3 hello with reusePort=true -------" +echo "------- egg1 hello -------" echo "" -print_head "egg3" "egg3 hello with reusePort=true" -wrk 'http://127.0.0.1:7008/' \ +print_head "egg1" "egg1 hello" +wrk 'http://127.0.0.1:7003/' \ -d 10 \ -c 50 \ -t 8 \ @@ -82,10 +82,10 @@ wrk 'http://127.0.0.1:7008/' \ 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 \ From 4e3448850f7a4fa25bbbeaf2cf79868a88f1c71e Mon Sep 17 00:00:00 2001 From: MK Date: Fri, 12 Dec 2025 22:46:16 +0800 Subject: [PATCH 07/19] fix egg-cluster version --- .github/workflows/nodejs.yml | 2 +- package.json | 2 +- simple/run.sh | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index fd72da7..c742790 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,5 +12,5 @@ jobs: uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: os: 'ubuntu-latest' - version: '14, 16, 18, 20, 22, 23' + version: '20, 22, 24' install: npm run install-wrk > wrk.log && npm install && cat /proc/cpuinfo diff --git a/package.json b/package.json index ad930bb..5d764c3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "egg benchmark", "private": true, "dependencies": { - "egg-cluster": "^2.4.0-beta.0", + "egg-cluster": "2.4.0-beta.0", "egg-passport": "^2.0.0", "egg-view-ejs": "^2.0.0", "egg-view-nunjucks": "^2.1.4", diff --git a/simple/run.sh b/simple/run.sh index d2e95f1..009295e 100755 --- a/simple/run.sh +++ b/simple/run.sh @@ -35,6 +35,7 @@ wrk 'http://127.0.0.1:7005/' \ -d 10 \ -c 50 \ -t 8 \ + --latency \ -s $REPORT sleep 3 @@ -46,6 +47,7 @@ wrk 'http://127.0.0.1:7008/' \ -d 10 \ -c 50 \ -t 8 \ + --latency \ -s $REPORT sleep 3 @@ -57,6 +59,7 @@ wrk 'http://127.0.0.1:7006/' \ -d 10 \ -c 50 \ -t 8 \ + --latency \ -s $REPORT echo "" @@ -67,6 +70,7 @@ wrk 'http://127.0.0.1:7002/' \ -d 10 \ -c 50 \ -t 8 \ + --latency \ -s $REPORT sleep 3 @@ -78,6 +82,7 @@ wrk 'http://127.0.0.1:7003/' \ -d 10 \ -c 50 \ -t 8 \ + --latency \ -s $REPORT sleep 3 @@ -89,6 +94,7 @@ wrk 'http://127.0.0.1:7004/' \ -d 10 \ -c 50 \ -t 8 \ + --latency \ -s $REPORT kill $pid From 340d2f79425ecb339ac5843b5ce27e92545d5cd8 Mon Sep 17 00:00:00 2001 From: MK Date: Fri, 12 Dec 2025 22:51:01 +0800 Subject: [PATCH 08/19] FIXUP --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5d764c3..4a180c9 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "scripts": { "install-wrk": "pwd && ls -l . && sh install-wrk.sh", - "test-simple": "simple/run.sh", + "test-simple": "NODE_DEBUG=egg-cluster:app_worker 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", From 98a2d43a34f98fae598fded840a94c6ea671d2b5 Mon Sep 17 00:00:00 2001 From: MK Date: Fri, 12 Dec 2025 23:01:13 +0800 Subject: [PATCH 09/19] FIXUP --- simple/dispatch.js | 8 ++++++++ simple/run.sh | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/simple/dispatch.js b/simple/dispatch.js index 4c7fe0e..3ad7dea 100644 --- a/simple/dispatch.js +++ b/simple/dispatch.js @@ -50,6 +50,14 @@ if (cluster.isMaster) { framework: 'egg3', }); + egg3.startCluster({ + startMode: 'worker_threads', + workers, + ports: [ 7007 ], + baseDir: __dirname, + framework: 'egg3', + }); + for (let i = 0; i < workers; i++) { cluster.fork(); } diff --git a/simple/run.sh b/simple/run.sh index 009295e..46ac402 100755 --- a/simple/run.sh +++ b/simple/run.sh @@ -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:7007/' curl 'http://127.0.0.1:7008/' test `tail -c 1 $CSV` && printf "\n" >> $CSV @@ -62,6 +63,18 @@ wrk 'http://127.0.0.1:7006/' \ --latency \ -s $REPORT +sleep 3 +echo "" +echo "------- egg3 hello with worker_threads -------" +echo "" +print_head "egg3" "egg3 hello with worker_threads" +wrk 'http://127.0.0.1:7007/' \ + -d 10 \ + -c 50 \ + -t 8 \ + --latency \ + -s $REPORT + echo "" echo "------- koa hello -------" echo "" From e28cae31b8b09e7ead70c51fa8f0e81322d2db49 Mon Sep 17 00:00:00 2001 From: MK Date: Fri, 12 Dec 2025 23:06:48 +0800 Subject: [PATCH 10/19] FIXUP --- simple/dispatch.js | 9 +++++++++ simple/run.sh | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/simple/dispatch.js b/simple/dispatch.js index 3ad7dea..ca5236a 100644 --- a/simple/dispatch.js +++ b/simple/dispatch.js @@ -58,6 +58,15 @@ if (cluster.isMaster) { framework: 'egg3', }); + require('egg-cluster').startCluster({ + startMode: 'worker_threads', + workers, + ports: [ 7009 ], + baseDir: __dirname, + framework: 'egg3', + reusePort: true, + }); + for (let i = 0; i < workers; i++) { cluster.fork(); } diff --git a/simple/run.sh b/simple/run.sh index 46ac402..1871db0 100755 --- a/simple/run.sh +++ b/simple/run.sh @@ -16,6 +16,7 @@ curl 'http://127.0.0.1:7005/' curl 'http://127.0.0.1:7006/' curl 'http://127.0.0.1:7007/' curl 'http://127.0.0.1:7008/' +curl 'http://127.0.0.1:7009/' test `tail -c 1 $CSV` && printf "\n" >> $CSV @@ -75,6 +76,19 @@ wrk 'http://127.0.0.1:7007/' \ --latency \ -s $REPORT +sleep 3 +echo "" +echo "------- egg3 hello with worker_threads and reusePort=true -------" +echo "" +print_head "egg3" "egg3 hello with worker_threads and reusePort=true" +wrk 'http://127.0.0.1:7009/' \ + -d 10 \ + -c 50 \ + -t 8 \ + --latency \ + -s $REPORT + +sleep 3 echo "" echo "------- koa hello -------" echo "" From 50b37dd0c7b3bee43bba924cc82a5de8f7c87221 Mon Sep 17 00:00:00 2001 From: MK Date: Fri, 12 Dec 2025 23:11:36 +0800 Subject: [PATCH 11/19] FIXUP --- simple/run.sh | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/simple/run.sh b/simple/run.sh index 1871db0..efbc01a 100755 --- a/simple/run.sh +++ b/simple/run.sh @@ -28,97 +28,97 @@ function print_head { printf "\"$TITLE\"," >> $CSV } -sleep 3 +sleep 5 echo "" -echo "------- egg3 hello -------" +echo "------- egg3 hello with reusePort=true -------" echo "" -print_head "egg3" "egg3 hello" -wrk 'http://127.0.0.1:7005/' \ - -d 10 \ +print_head "egg3" "egg3 hello with reusePort=true" +wrk 'http://127.0.0.1:7008/' \ + -d 30 \ -c 50 \ -t 8 \ --latency \ -s $REPORT -sleep 3 +sleep 5 echo "" -echo "------- egg3 hello with reusePort=true -------" +echo "------- egg3 hello -------" echo "" -print_head "egg3" "egg3 hello with reusePort=true" -wrk 'http://127.0.0.1:7008/' \ - -d 10 \ +print_head "egg3" "egg3 hello" +wrk 'http://127.0.0.1:7005/' \ + -d 30 \ -c 50 \ -t 8 \ --latency \ -s $REPORT -sleep 3 +sleep 5 echo "" echo "------- egg3 hello with worker_threads=1 -------" echo "" print_head "egg3" "egg3 hello with worker_threads=1" wrk 'http://127.0.0.1:7006/' \ - -d 10 \ + -d 30 \ -c 50 \ -t 8 \ --latency \ -s $REPORT -sleep 3 +sleep 5 echo "" echo "------- egg3 hello with worker_threads -------" echo "" print_head "egg3" "egg3 hello with worker_threads" wrk 'http://127.0.0.1:7007/' \ - -d 10 \ + -d 30 \ -c 50 \ -t 8 \ --latency \ -s $REPORT -sleep 3 +sleep 5 echo "" echo "------- egg3 hello with worker_threads and reusePort=true -------" echo "" print_head "egg3" "egg3 hello with worker_threads and reusePort=true" wrk 'http://127.0.0.1:7009/' \ - -d 10 \ + -d 30 \ -c 50 \ -t 8 \ --latency \ -s $REPORT -sleep 3 +sleep 5 echo "" echo "------- koa hello -------" echo "" print_head "koa" "koa hello" wrk 'http://127.0.0.1:7002/' \ - -d 10 \ + -d 30 \ -c 50 \ -t 8 \ --latency \ -s $REPORT -sleep 3 +sleep 5 echo "" echo "------- egg1 hello -------" echo "" print_head "egg1" "egg1 hello" wrk 'http://127.0.0.1:7003/' \ - -d 10 \ + -d 30 \ -c 50 \ -t 8 \ --latency \ -s $REPORT -sleep 3 +sleep 5 echo "" echo "------- egg2 hello -------" echo "" print_head "egg2" "egg2 hello" wrk 'http://127.0.0.1:7004/' \ - -d 10 \ + -d 30 \ -c 50 \ -t 8 \ --latency \ From a0f0808d47967dd1f0f26a28be98714760cbd18e Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 13 Dec 2025 00:47:54 +0800 Subject: [PATCH 12/19] FIXUP --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a180c9..47315cb 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "egg benchmark", "private": true, "dependencies": { - "egg-cluster": "2.4.0-beta.0", + "egg-cluster": "2.5.0-beta.0", "egg-passport": "^2.0.0", "egg-view-ejs": "^2.0.0", "egg-view-nunjucks": "^2.1.4", From adc0c7e8f5bc436cadbae9e081f9a8d38f6f29ab Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 13 Dec 2025 00:52:57 +0800 Subject: [PATCH 13/19] FIXUP --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 47315cb..5bed031 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "egg benchmark", "private": true, "dependencies": { - "egg-cluster": "2.5.0-beta.0", + "egg-cluster": "2.5.0-beta.1", "egg-passport": "^2.0.0", "egg-view-ejs": "^2.0.0", "egg-view-nunjucks": "^2.1.4", From c45e1f3bb650ff065dd3794ab5f568de959a11aa Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 13 Dec 2025 01:01:04 +0800 Subject: [PATCH 14/19] FIXUP --- simple/dispatch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/simple/dispatch.js b/simple/dispatch.js index ca5236a..c03c069 100644 --- a/simple/dispatch.js +++ b/simple/dispatch.js @@ -53,7 +53,7 @@ if (cluster.isMaster) { egg3.startCluster({ startMode: 'worker_threads', workers, - ports: [ 7007 ], + port: 7007, baseDir: __dirname, framework: 'egg3', }); @@ -61,7 +61,7 @@ if (cluster.isMaster) { require('egg-cluster').startCluster({ startMode: 'worker_threads', workers, - ports: [ 7009 ], + port: 7009, baseDir: __dirname, framework: 'egg3', reusePort: true, From a0017ecb73e04a9fbbf8f147c21ce6328d7f6471 Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 13 Dec 2025 01:32:47 +0800 Subject: [PATCH 15/19] FIXUP --- package.json | 2 +- simple/dispatch.js | 8 -------- simple/run.sh | 13 ------------- 3 files changed, 1 insertion(+), 22 deletions(-) diff --git a/package.json b/package.json index 5bed031..b1d0d6b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "egg benchmark", "private": true, "dependencies": { - "egg-cluster": "2.5.0-beta.1", + "egg-cluster": "2.5.0-beta.2", "egg-passport": "^2.0.0", "egg-view-ejs": "^2.0.0", "egg-view-nunjucks": "^2.1.4", diff --git a/simple/dispatch.js b/simple/dispatch.js index c03c069..7d23cd9 100644 --- a/simple/dispatch.js +++ b/simple/dispatch.js @@ -50,14 +50,6 @@ if (cluster.isMaster) { framework: 'egg3', }); - egg3.startCluster({ - startMode: 'worker_threads', - workers, - port: 7007, - baseDir: __dirname, - framework: 'egg3', - }); - require('egg-cluster').startCluster({ startMode: 'worker_threads', workers, diff --git a/simple/run.sh b/simple/run.sh index efbc01a..56f65cc 100755 --- a/simple/run.sh +++ b/simple/run.sh @@ -14,7 +14,6 @@ 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:7007/' curl 'http://127.0.0.1:7008/' curl 'http://127.0.0.1:7009/' @@ -64,18 +63,6 @@ wrk 'http://127.0.0.1:7006/' \ --latency \ -s $REPORT -sleep 5 -echo "" -echo "------- egg3 hello with worker_threads -------" -echo "" -print_head "egg3" "egg3 hello with worker_threads" -wrk 'http://127.0.0.1:7007/' \ - -d 30 \ - -c 50 \ - -t 8 \ - --latency \ - -s $REPORT - sleep 5 echo "" echo "------- egg3 hello with worker_threads and reusePort=true -------" From b8b1ab30fdb81c0007c5e5abbbadb755b5ec0b3d Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 13 Dec 2025 01:46:13 +0800 Subject: [PATCH 16/19] FIXUP --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b1d0d6b..33e91bb 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "egg benchmark", "private": true, "dependencies": { - "egg-cluster": "2.5.0-beta.2", + "egg-cluster": "2.5.0-beta.3", "egg-passport": "^2.0.0", "egg-view-ejs": "^2.0.0", "egg-view-nunjucks": "^2.1.4", From 7922383c26dccd7960142aae8644f467afa8b9c4 Mon Sep 17 00:00:00 2001 From: MK Date: Sat, 13 Dec 2025 17:20:09 +0800 Subject: [PATCH 17/19] FIXUP --- .github/workflows/nodejs.yml | 2 +- package.json | 1 - simple/dispatch.js | 6 +++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index c742790..b55fbcb 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,5 +12,5 @@ jobs: uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: os: 'ubuntu-latest' - version: '20, 22, 24' + version: '18, 20, 22, 24' install: npm run install-wrk > wrk.log && npm install && cat /proc/cpuinfo diff --git a/package.json b/package.json index 33e91bb..eeb2c3c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "description": "egg benchmark", "private": true, "dependencies": { - "egg-cluster": "2.5.0-beta.3", "egg-passport": "^2.0.0", "egg-view-ejs": "^2.0.0", "egg-view-nunjucks": "^2.1.4", diff --git a/simple/dispatch.js b/simple/dispatch.js index 7d23cd9..1be94d9 100644 --- a/simple/dispatch.js +++ b/simple/dispatch.js @@ -34,13 +34,13 @@ if (cluster.isMaster) { framework: 'egg3', }); - require('egg-cluster').startCluster(({ + egg3.startCluster({ workers, baseDir: __dirname, port: 7008, framework: 'egg3', reusePort: true, - })); + }); egg3.startCluster({ startMode: 'worker_threads', @@ -50,7 +50,7 @@ if (cluster.isMaster) { framework: 'egg3', }); - require('egg-cluster').startCluster({ + egg3.startCluster({ startMode: 'worker_threads', workers, port: 7009, From 33bc22f1e0355dad6d5446eaf0a7bad698ad052b Mon Sep 17 00:00:00 2001 From: "MK (fengmk2)" Date: Sat, 13 Dec 2025 17:22:08 +0800 Subject: [PATCH 18/19] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d693674..c39a9fa 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ egg benchmark * 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 +* csrf are disabled, because in most situation we won't calculate csrf token and set to cookie ## Scenes @@ -29,6 +29,7 @@ egg benchmark * 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` +* egg3 with reusePort: `wrk http://127.0.0.1:7008/ -d 10 -c 50 -t 8` ## Server From 2383fc05d346512f459676bb79fef17aaa6cbf25 Mon Sep 17 00:00:00 2001 From: "MK (fengmk2)" Date: Sat, 13 Dec 2025 21:50:01 +0800 Subject: [PATCH 19/19] Update simple/dispatch.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- simple/dispatch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple/dispatch.js b/simple/dispatch.js index 1be94d9..2893328 100644 --- a/simple/dispatch.js +++ b/simple/dispatch.js @@ -4,7 +4,7 @@ const egg1 = require('egg1'); const cluster = require('cluster'); const os = require('os'); -let workers = Number(process.argv[2] || require('os').cpus().length); +let workers = Number(process.argv[2] || os.cpus().length); if (workers > 4) { workers = 4; }