alinode與官方node性能測試方法及分析


需求和技術指標整理

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)
for正序-inTurn x 12,976 ops/sec ±0.96% (88 runs sampled)
for倒序-invertedOrder x 13,169 ops/sec ±0.84% (95 runs sampled)
for_in x 80.03 ops/sec ±1.60% (70 runs sampled)
for_of x 890 ops/sec ±1.09% (89 runs sampled)
for_map x 64.73 ops/sec ±0.75% (66 runs sampled)
for_each x 741 ops/sec ±0.64% (92 runs sampled)
for_while x 12,945 ops/sec ±0.94% (93 runs sampled)
while_normal x 12,904 ops/sec ±0.77% (92 runs sampled)
Fastest is for倒序-invertedOrder

 見圖1

connections:10

 見圖3

connections:1000  

 見圖4

 

官方node

Node.js 10.16.3 on Linux 64-bit
for_normal x 15,697 ops/sec ±3.54% (75 runs sampled)
for正序-inTurn x 12,590 ops/sec ±1.78% (83 runs sampled)
for倒序-invertedOrder x 11,926 ops/sec ±3.29% (78 runs sampled)
for_in x 61.22 ops/sec ±4.13% (53 runs sampled)
for_of x 720 ops/sec ±3.53% (73 runs sampled)
for_map x 52.43 ops/sec ±4.52% (54 runs sampled)
for_each x 617 ops/sec ±3.31% (78 runs sampled)
for_while x 12,124 ops/sec ±3.03% (80 runs sampled)
while_normal x 15,735 ops/sec ±3.69% (79 runs sampled)
Fastest is while_normal,for_normal

  見圖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  

對於生產中的性能待進一步的論證.如有錯誤,歡迎批評指正.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM