需求和技术指标整理

node服务在引入node性能监控过程中,需要使用alinode,为了对alinode与官方node各项性能指标的差异有进一步的认识,现开展以下调研、测试.

原理性分析

alinode是基于官方node做封装,官方解释是alinode对性能影响可以忽略.

 

测试方案

1、node版本

Node.js 8.16.1 on Linux 64-bit
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
 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 () { // console.log(this); // console.log(this.filter('fastest')); 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


测试数据结果

node类型 Node.js 10.16.3循环计算 Node.js 8.16.1循环计算 I/O Node.js 10.16.3 I/O Node.js 8.16.1 备注
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

 

Node.js 8.16.1 on Linux 64-bit
for_normal x 13,092 ops/sec ±0.45% (90 runs sampled)
for正序-inTurn x 12,707 ops/sec ±1.63% (91 runs sampled)
for倒序-invertedOrder x 13,009 ops/sec ±0.54% (91 runs sampled)
for_in x 99.56 ops/sec ±1.07% (71 runs sampled)
for_of x 3,338 ops/sec ±0.34% (93 runs sampled)
for_map x 65.81 ops/sec ±0.69% (67 runs sampled)
for_each x 728 ops/sec ±0.47% (92 runs sampled)
for_while x 12,999 ops/sec ±1.10% (92 runs sampled)
while_normal x 12,881 ops/sec ±1.23% (95 runs sampled)
Fastest is for_normal,for倒序-invertedOrder,for_while

connections:10

autocannon

connections:1000

connections:10

connections1000:

12,978 ops/sec每秒执行次数

±0.60% 方差

94 runs sampled 样本

官方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

 

Node.js 8.16.1 on Linux 64-bit
for_normal x 12,515 ops/sec ±1.82% (89 runs sampled)
for正序-inTurn x 12,327 ops/sec ±2.40% (80 runs sampled)
for倒序-invertedOrder x 12,231 ops/sec ±3.04% (81 runs sampled)
for_in x 81.33 ops/sec ±4.54% (61 runs sampled)
for_of x 3,160 ops/sec ±3.54% (75 runs sampled)
for_map x 53.71 ops/sec ±2.45% (56 runs sampled)
for_each x 642 ops/sec ±2.51% (78 runs sampled)
for_while x 12,526 ops/sec ±2.45% (81 runs sampled)
while_normal x 11,997 ops/sec ±3.35% (80 runs sampled)
Fastest is for_normal,for_while,for正序-inTurn,for倒序-invertedOrder,while_normal

 

 

 

connections:10

connections:1000

connections:10

connections:1000

 

 

测试结果分析

cpu计算上,alinode略优于普通node,但是不明显;

从网络I/O上看,alinode的延迟性低,每秒处理请求数的性能要优于官方node,数据见下表.

Node10.16.3 并发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.42ms 18614.6 4850 53.91 17.95 18430.19 2982.79  

对于生产中的性能待进一步的论证.

 

版权声明:本文为yiyi17原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/yiyi17/p/11741033.html