Skip to content
Merged
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: '18, 20, 22, 24'
install: npm run install-wrk > wrk.log && npm install && cat /proc/cpuinfo
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

41 changes: 23 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,45 @@ 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 calculate 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`
* egg3 with reusePort: `wrk http://127.0.0.1:7008/ -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
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The install-wrk.sh script clones and builds wrk from the mutable default branch of https://github.com/wg/wrk.git and immediately runs make on the fetched repository. This means any compromise of that repository (or a malicious change on its default branch) would execute attacker-controlled build steps with your local or CI privileges, potentially exfiltrating secrets or modifying artifacts. To reduce this supply-chain risk, fetch and build from a pinned immutable reference (specific commit or signed release) and consider verifying integrity (e.g., via checksum or signature) before running make.

Copilot uses AI. Check for mistakes.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"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 +22,12 @@
"node": ">=14.20.0"
},
"scripts": {
"test-simple": "simple/run.sh",
"install-wrk": "pwd && ls -l . && sh install-wrk.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",
"ci": "EGG_SERVER_ENV=prod npm test"
"ci": "PATH=$PWD/wrk/bin:$PATH EGG_SERVER_ENV=prod npm test"
},
"repository": {
"type": "git",
Expand Down
23 changes: 22 additions & 1 deletion 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);
let workers = Number(process.argv[2] || 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',
});

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

egg3.startCluster({
startMode: 'worker_threads',
workers: 1,
Expand All @@ -38,6 +50,15 @@ if (cluster.isMaster) {
framework: 'egg3',
});

egg3.startCluster({
startMode: 'worker_threads',
workers,
port: 7009,
baseDir: __dirname,
framework: 'egg3',
reusePort: true,
});

for (let i = 0; i < workers; i++) {
cluster.fork();
}
Expand Down
80 changes: 56 additions & 24 deletions simple/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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/'
curl 'http://127.0.0.1:7009/'

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

Expand All @@ -25,58 +27,88 @@ function print_head {
printf "\"$TITLE\"," >> $CSV
}

sleep 5
echo ""
echo "------- koa hello -------"
echo "------- egg3 hello with reusePort=true -------"
echo ""
print_head "koa" "koa hello"
wrk 'http://127.0.0.1:7002/' \
-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 "------- egg1 hello -------"
echo "------- egg3 hello -------"
echo ""
print_head "egg1" "egg1 hello"
wrk 'http://127.0.0.1:7003/' \
-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 "------- egg2 hello -------"
echo "------- egg3 hello with worker_threads=1 -------"
echo ""
print_head "egg2" "egg2 hello"
wrk 'http://127.0.0.1:7004/' \
-d 10 \
print_head "egg3" "egg3 hello with worker_threads=1"
wrk 'http://127.0.0.1:7006/' \
-d 30 \
-c 50 \
-t 8 \
--latency \
-s $REPORT

sleep 3
sleep 5
echo ""
echo "------- egg3 hello -------"
echo "------- egg3 hello with worker_threads and reusePort=true -------"
echo ""
print_head "egg3" "egg3 hello"
wrk 'http://127.0.0.1:7005/' \
-d 10 \
print_head "egg3" "egg3 hello with worker_threads and reusePort=true"
wrk 'http://127.0.0.1:7009/' \
-d 30 \
-c 50 \
-t 8 \
--latency \
-s $REPORT

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

sleep 5
echo ""
echo "------- egg1 hello -------"
echo ""
print_head "egg1" "egg1 hello"
wrk 'http://127.0.0.1:7003/' \
-d 30 \
-c 50 \
-t 8 \
--latency \
-s $REPORT

sleep 5
echo ""
echo "------- egg2 hello -------"
echo ""
print_head "egg2" "egg2 hello"
wrk 'http://127.0.0.1:7004/' \
-d 30 \
-c 50 \
-t 8 \
--latency \
-s $REPORT

kill $pid
Expand Down