zoukankan      html  css  js  c++  java
  • 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  

    对于生产中的性能待进一步的论证.如有错误,欢迎批评指正.

  • 相关阅读:
    IDL读取TXT文件并写入二维数组中【转】
    远程连接ArcSDE
    Silverlight项目启动出现System.NullReferenceException未将对象引用到对象实例
    ENVI扩展工具:HDF5 Browser
    READF: End of file encountered. Unit: 100
    ENVI4.8下从两幅分类结果的栅格图中计算土地利用类型转换矩阵
    IDL中去掉数组中相同的元素方法
    利用IDL程序自动添加ENVI菜单【转】
    WIN7远程桌面连接知识
    对COM组件的调用返回了错误"HRESULT E_FAIL”的错误分析(c#与IDL混合编程)转
  • 原文地址:https://www.cnblogs.com/yiyi17/p/11741033.html
Copyright © 2011-2022 走看看