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 egg2 vs egg1 #14

Merged
merged 6 commits into from
Nov 17, 2017
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
11 changes: 6 additions & 5 deletions .autod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ module.exports = {
'eslint',
'eslint-config-egg',
'webstorm-disable-index',
'nunjucks',
'koa',
'koa-router',
],
semver: [
'koa@2',
'koa-router@7',
'koa@1',
'koa-router@5',
],
exclude: [
'./test/fixtures',
'./dist',
'./wrk',
],
keep: [
'egg',
'egg-core',
],
};
86 changes: 13 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ egg benchmark

## Commands

* `npm test` to run all the benchmarks and store the results in `stats.csv` (requires `wrk`)
* `npm test` to run all the benchmarks and store the results in `stats.csv` (requires `wrk`), also you can open `plot/index.html` to see the results
* `./plot.sh` to compare performance between the latest releases of Node.js v7.x, v8.x, rc, nightly and v8-canary (requires `wrk` and `nvm`), then open `plot/index.html` to see the results
* Requires AJAX privilege to load data from `plot/all.csv`, you can run `python -m SimpleHTTPServer` then visit `http://localhost:8000/plot/` (or use any other static server) if you don't want to tweak browser settings

Expand All @@ -18,6 +18,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

## Scenes

Expand All @@ -27,83 +28,22 @@ egg benchmark

## Scripts

- koa1: `wrk http://127.0.0.1:7002/ -d 10 -c 50 -t 8`
- koa2: `wrk http://127.0.0.1:7004/ -d 10 -c 50 -t 8`
- egg: `wrk http://127.0.0.1:7001/ -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`

## Server

- CPU x4: Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz
- Mem: 10G
- MacBook Pro (Retina, 15-inch, Late 2013)
- 2 GHz Intel Core i7 (only use 4 core for benchmark)

## Known issues

- [ensure csrf token exists](https:/eggjs/egg-security/blob/master/app/extend/context.js#L75): It's cause get and set cookie on every request.
![image](https://cloud.githubusercontent.com/assets/156269/22675417/8fd55b44-ed20-11e6-8ac8-77a791e558dd.png)

## egg versions benchmark

- [plots view](https://fengmk2.com/egg/benchmark/)

### Hello World

egg version | node version | QPS Generator | Async Await
--- | --- | --- | ---
1.1.0 | 7.9.0 | 11004 | 11200
1.0.0-rc.1 | 7.6.0 | 11069 | 11296
0.12.0 | 7.6.0 | 10899 | 11122
0.12.0 | 6.9.5 | 8880 | -
0.11.0 | 6.9.5 | 8889 | -
0.10.0 | 6.9.5 | 8470 | -
0.2.0 | 6.9.5 | 8917 | -

### nunjucks

egg version | node version | QPS Generator | Async Await
--- | --- | --- | ---
1.1.0 | 7.9.0 | 6092 | 6121
1.0.0-rc.1 | 7.6.0 | 6278 | 6350
0.12.0 | 7.6.0 | 7216 | 7371
0.12.0 | 6.9.5 | 5967 | -
0.11.0 | 6.9.5 | 6057 | -
0.10.0 | 6.9.5 | 5681 | -
0.2.0 | 6.9.5 | 6732 | -
## CPU Profiler

### ejs

egg version | node version | QPS Generator | Async Await
--- | --- | --- | ---
1.1.0 | 7.9.0 | 6916 | 6985
1.0.0-rc.1 | 7.6.0 | 7333 | 7372

### passport

- egg-passport: 1.0.0

egg version | node version | QPS Generator | Async Await
--- | --- | --- | ---
1.1.0 | 7.9.0 | 10117 | 10556
1.0.0-rc.1 | 7.6.0 | 10039 | 10438
0.12.0 | 7.6.0 | 9981 | 10436
0.12.0 | 6.9.5 | 7943 | -

## Last Results

- node: 7.9.0
- koa1: 1.4.0
- koa2: 2.2.0
- egg: 1.1.0

Scene | QPS | Scene | QPS
--- | --- | --- | ---
koa1 Hello World | 18216 | koa2 Hello World | 21836
egg Hello World | 11004 | egg Hello World (Async Await) | 11200
egg Hello Passport | 10117 | egg Hello Passport (Async Await) | 10556
koa1 nunjucks | 11807 | koa2 nunjucks | 13583
egg nunjucks | 6092 | egg nunjucks (Async Await) | 6121
egg ejs | 6916 | egg ejs (Async Await) | 6985
![image](https://user-images.githubusercontent.com/985607/32961302-a6d1d506-cb8d-11e7-9273-160d8ba77da6.png)

## Known issues

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

`stats.csv`
## [Last Results](https://eggjs.github.io/benchmark/plot/)
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
"description": "egg benchmark",
"private": true,
"dependencies": {
"egg": "^1.7.0",
"egg-alinode": "^1.1.0",
"egg-passport": "^1.0.0",
"egg-view-ejs": "^1.1.0",
"egg-view-nunjucks": "^2.1.3",
"koa": "^2.3.0",
"koa-router": "^7.2.1",
"egg": "next",
"egg-alinode": "^1.1.1",
"egg-passport": "^2.0.0",
"egg-view-ejs": "^2.0.0",
"egg-view-nunjucks": "^2.1.4",
"egg1": "^1.11.0",
"koa": "^1.4.1",
"koa-router": "^5.4.2",
"nunjucks": "^3.0.1"
},
"devDependencies": {
"autod": "^2.9.0",
"eslint": "^4.4.1",
"eslint-config-egg": "^5.0.0",
"autod": "^3.0.1",
"eslint": "^4.11.0",
"eslint-config-egg": "^5.1.1",
"webstorm-disable-index": "^1.2.0"
},
"engines": {
Expand All @@ -26,7 +27,7 @@
"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",
"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": "npm test",
"autod": "autod"
},
Expand Down
21 changes: 21 additions & 0 deletions plot/all.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
config,name,latency_min,latency_max,latency_mean,latency_stdev,duration,requests,bytes,req_per_sec,byte_per_sec
"[email protected], [email protected]","koa1 hello",335.00,17593.00,1610.74,728.07,9998518,297637,47324283,29768.11,4733129.75
"[email protected], [email protected]","koa2 hello",250.00,8623.00,1590.67,825.57,9998451,311315,49499085,31136.32,4950675.36
"[email protected], [email protected]","egg1 hello",249.00,20024.00,2174.29,850.06,9998188,219740,65043040,21977.98,6505482.79
"[email protected], [email protected]","egg1 hello aa",290.00,21667.00,2090.82,856.39,9998427,228103,67518488,22813.89,6752911.03
"[email protected], [email protected]","egg2 hello",294.00,21470.00,1937.30,797.02,9998180,247161,73159656,24720.60,7317297.35
"[email protected], [email protected]","egg2 hello aa",223.00,18154.00,1733.69,649.83,9998892,274697,81310312,27472.74,8131932.22
"[email protected], [email protected]","koa1 view",621.00,24238.00,3185.92,2333.20,9992568,152598,400264554,15271.15,40056225.19
"[email protected], [email protected]","koa2 view",420.00,26781.00,3140.46,2227.33,9998726,156719,411073937,15673.90,41112631.45
"[email protected], [email protected]","egg1 nunjucks view",1000.00,31440.00,4827.71,3528.41,9999785,102209,283834467,10221.12,28384056.96
"[email protected], [email protected]","egg1 ejs view",583.00,26638.00,3727.69,2678.76,9998677,128724,359011240,12874.10,35905874.35
"[email protected], [email protected]","egg1 nunjucks view aa",919.00,31285.00,4590.49,3528.43,10000018,106972,298344990,10697.18,29834445.30
"[email protected], [email protected]","egg1 ejs view aa",639.00,31122.00,3848.20,3050.99,9999337,128880,360219602,12888.85,36024348.61
"[email protected], [email protected]","egg2 nunjucks view",953.00,41585.00,4492.01,3387.90,9999646,110182,305975492,11018.59,30598632.39
"[email protected], [email protected]","egg2 ejs view",363.00,31469.00,3426.54,2598.78,9998918,142208,396618117,14222.34,39666103.57
"[email protected], [email protected]","egg2 nunjucks view aa",860.00,29610.00,4150.34,3404.62,9999590,120659,336518047,12066.39,33653184.48
"[email protected], [email protected]","egg2 ejs view aa",927.00,27466.00,3244.35,2548.04,9999774,152216,425443722,15221.94,42545333.72
"[email protected], [email protected]","egg1 passport",338.00,27037.00,2589.48,1298.60,9998538,187560,55142641,18758.74,5515070.40
"[email protected], [email protected]","egg1 passport aa",622.00,12283.00,2406.41,974.97,9998683,200299,59689102,20032.54,5969696.41
"[email protected], [email protected]","egg2 passport",685.00,23906.00,2185.53,1067.51,9998570,224164,65904216,22419.61,6591364.17
"[email protected], [email protected]","egg2 passport aa",332.00,6578.00,1805.62,698.10,9998521,263602,78553396,26364.10,7856501.58
101 changes: 60 additions & 41 deletions plot/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ d3.csv('./all.csv', function(d) {
});

function draw(svg, data) {
const margin = { top: 20, right: 20, bottom: 30, left: 40 };
const margin = {
top: 20,
right: 20,
bottom: 30,
left: 40,
};
const width = +svg.attr('width') - margin.left - margin.right;
const height = +svg.attr('height') - margin.top - margin.bottom;
const canvas = svg.append('g')
Expand All @@ -38,13 +43,13 @@ function draw(svg, data) {

const z = d3.scaleOrdinal()
.range([
'#00bcd4', '#ffc107', '#8bc34a', '#ad8de4', '#f17e7e'
'#00bcd4', '#ffc107', '#8bc34a', '#ad8de4', '#f17e7e',
]);

const groupKeys = Array.from(new Set(data.map(d => d.name)));
const valueKeys = [
'req_per_sec',
// 'byte_per_sec'
// 'byte_per_sec'
];
const configKeys = Array.from(new Set(data.map(d => d.config)));
const barKeys = [];
Expand All @@ -64,28 +69,42 @@ function draw(svg, data) {
.selectAll('g')
.data(nested)
.enter()
.append('g');
.append('g');

function formatNest(d) {
const values = d.values;
const result = [];
for (const item of values) {
for (const v of valueKeys) {
result.push({
config: item.config,
name: item.name,
key: v,
value: item[v],
});
}
}
return result;
}

const bars = groups
.attr('transform', d => `translate(${groupX(d.key)}, 0)`)
.selectAll('rect')
.data(function(d) {
const values = d.values;
const result = [];
for (const item of values) {
for (const v of valueKeys) {
result.push({
config: item.config,
name: item.name,
key: v,
value: item[v],
});
}
}
return result;
})
.data(formatNest)
.enter()
.append('rect');

groups
// .attr('transform', d => `translate(${groupX(d.key)}, 0)`)
.selectAll('text')
.data(formatNest)
.enter()
.append('rect');
.append('text')
.text(d => d.value)
.attr('x', function(d) {
return barX(`${d.key}:${d.config}`) + (barX.bandwidth() - this.getComputedTextLength()) / 2;
})
.attr('y', d => y(d.value) - 10);

bars
.attr('x', d => barX(`${d.key}:${d.config}`))
Expand All @@ -96,21 +115,21 @@ function draw(svg, data) {
.attr('fill', d => z(d.config));

canvas.append('g')
.attr('class', 'axis')
.attr('transform', `translate(0, ${height})`)
.call(d3.axisBottom(groupX));
.attr('class', 'axis')
.attr('transform', `translate(0, ${height})`)
.call(d3.axisBottom(groupX));

canvas.append('g')
.attr('class', 'axis')
.call(d3.axisLeft(y).ticks(null, 's'))
.attr('class', 'axis')
.call(d3.axisLeft(y).ticks(null, 's'))
.append('text')
.attr('x', 2)
.attr('y', y(y.ticks().pop()) + 0.5)
.attr('dy', '0.32em')
.attr('fill', '#000')
.attr('font-weight', 'bold')
.attr('text-anchor', 'start')
.text('req/s');
.attr('x', 2)
.attr('y', y(y.ticks().pop()) + 0.5)
.attr('dy', '0.32em')
.attr('fill', '#000')
.attr('font-weight', 'bold')
.attr('text-anchor', 'start')
.text('req/s');

const legend = canvas.append('g')
.attr('font-family', 'sans-serif')
Expand All @@ -119,20 +138,20 @@ function draw(svg, data) {
.selectAll('g')
.data(configKeys.slice().reverse())
.enter()
.append('g');
.append('g');

legend
.attr('transform', (d, i) => `translate(0, ${i * 20})`);

legend.append('rect')
.attr('x', width - 19)
.attr('width', 19)
.attr('height', 19)
.attr('fill', z);
.attr('x', width - 19)
.attr('width', 19)
.attr('height', 19)
.attr('fill', z);

legend.append('text')
.attr('x', width - 24)
.attr('y', 9.5)
.attr('dy', '0.32em')
.text(d => d);
.attr('x', width - 24)
.attr('y', 9.5)
.attr('dy', '0.32em')
.text(d => d);
}
2 changes: 0 additions & 2 deletions simple/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
module.exports = app => {
console.log('egg app core middlewares: %d, app middlewares: %d',
app.config.coreMiddlewares.length, app.config.appMiddlewares.length);
require('./koa1');
require('./koa2');
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ exports.keys = 'foo';
exports.logger = {
dir: path.join(__dirname, '../logs'),
};

exports.security = {
csrf: false,
};
Loading