需求和技術指標整理
node服務在引入node性能監控過程中,需要使用alinode,為了對alinode與官方node各項性能指標的差異有進一步的認識,現開展以下調研、測試.
原理性分析
alinode是基於官方node做封裝,官方解釋是alinode對性能影響可以忽略.
測試方案
1、node版本
Node.js 10.16.3 on Linux 64-bit
2、Linux系統
uname -a
2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
3、 測試代碼
循環:
const Benchmark = require('benchmark');
let suite = new Benchmark.Suite('foo', {});
console.log(String(Benchmark.platform));
const arr = new Array(100000).fill(1);
const arr = []
suite.add('for_normal', () => { for (let i = 0; i < arr.length; i++) { }})
.add('for正序-inTurn', () => { for (let i = 0, len = arr.length; i < len; i++) { } })
.add('for倒序-invertedOrder', () => { for (let i = arr.length; i--;) { } })
.add('for_in', () => { for (let i in arr) { } })
.add('for_of', () => { for (let i of arr) { } })
.add('for_map', () => { arr.map(item => { }) })
.add('for_each', () => { arr.forEach(item => { }) })
.add('for_while', () => { let i = 0; let len = arr.length; while (i < len) { i++ } })
.add('while_normal', () => { let i = 0; while (i < arr.length) { i++ } })
.on('cycle', event => { console.log(String(event.target)); })
.on('complete', function () {
const fastest = this.filter('fastest').map('name');
console.log(`Fastest is ${fastest}`); })
.run({ 'async': true });
接口:
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, {'content-type':'text/plain'});
res.end('hello world');})
.listen(3002)
console.log('Server running at http://127.0.0.1:8888/');
4、測試工具
clinic 、autocannon
#循環 clinic doctor -- node index.js # connections:10 autocannon http://127.0.0.1:3002 -c 10 # connections:1000 autocannon http://127.0.0.1:3002 -c 1000
測試數據結果
注:12,978 ops/sec每秒執行次數;±0.60% 方差;94 runs sampled 樣本
| node類型 | Node.js 10.16.3循環計算 | I/O Node.js 10.16.3 |
|---|---|---|
| alinode | Node.js 10.16.3 on Linux 64-bit for_normal x 13,087 ops/sec ±0.68% (94 runs sampled) 見圖1 |
connections:10 見圖3 connections:1000 見圖4
|
| 官方node | Node.js 10.16.3 on Linux 64-bit 見圖2 |
connections:10 見圖5 connections:1000 見圖6 |
圖1
圖2
圖3
圖4
圖5
圖6
測試結果分析
cpu計算上,alinode略優於普通node,但是不明顯;
從網絡I/O上看,alinode的延遲性低,每秒處理請求數的性能要優於官方node,數據見下表.
| Node | 並發10 | 並發1000 | 備注 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| 延遲平均值(ms) | 延遲標准樣本差(ms) | 每秒請求數(req/sec) | req/sec樣本標准差 | 延遲平均值(ms) | 延遲標准樣本差(ms) | 每秒請求數(req/sec) | req/sec樣本標准差 | ||
| alinode | 0.02 | 0.18 | 32678.91 | 8410 | 32.79 | 8.81 | 30114.91 | 3449.49 | |
| 官方node | 0.08 | 0.42 | 18614.6 | 4850 | 53.91 | 17.95 | 18430.19 | 2982.79 | |
對於生產中的性能待進一步的論證.如有錯誤,歡迎批評指正.
