设为首页 收藏本站
查看: 1232|回复: 0

[经验分享] nodejs测试: buffer和字符串相加对比测试

[复制链接]

尚未签到

发表于 2017-2-22 09:28:46 | 显示全部楼层 |阅读模式
  

  看到jsconf2010.pdf写的关于buffer对象和string字符串相加的对比图表。发现buffer对象响应的变化很大,眼见为实,因此证实一下:
  

  准备:
  apache ab模拟并发,编写两份代码
  os: debian 6.0

  cpu: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz
  mem: 4G
  

  代码:

var http = require('http'), string = '', buffer='';for(i = 0; i < 16*1024; i++) {string +='d';
}var server = http.createServer(function(req, res) {res.writeHead(200);res.end(string, 'ascii');}
);server.listen(1339, '127.0.0.1');buffer = new Buffer(16*1024);for(i=0; i < buffer.length; i++) {buffer = 100;
}var server2 = http.createServer(function(req, res) {res.writeHead(200);res.end(buffer);}
);server2.listen(1340, '127.0.0.1');console.log('running');
  说明:定义两个监听,实现不同的字符串拼接,并监听不同的端口,方便测试。
  

  运行:

/usr/mytools/httpd/bin/ab -c 300 -n 10000 http://127.0.0.1:1339
/usr/mytools/httpd/bin/ab -c 300 -n 10000 http://127.0.0.1:1340

  结果:

madding@wmmad:~$ /usr/mytools/httpd/bin/ab -c 300 -n 10000 http://127.0.0.1:1339/
This is ApacheBench, Version 2.3 <$Revision: 655654 {1}gt;
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requestsServer Software:        
Server Hostname:        127.0.0.1
Server Port:            1339Document Path:          /
Document Length:        16384 bytesConcurrency Level:      300
Time taken for tests:   3.602 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      164220000 bytes
HTML transferred:       163840000 bytes
Requests per second:    2776.02 [#/sec] (mean)
Time per request:       108.068 [ms] (mean)
Time per request:       0.360 [ms] (mean, across all concurrent requests)
Transfer rate:          44519.36 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0   36 326.6      0    3008
Processing:     1   47  29.8     46     570
Waiting:        1   47  29.8     46     570
Total:          1   83 328.9     46    3094Percentage of the requests served within a certain time (ms)50%     4666%     6075%     6880%     7290%     8195%     9098%    14199%   3033100%   3094 (longest request)
madding@wmmad:~$ /usr/mytools/httpd/bin/ab -c 300 -n 10000 http://127.0.0.1:1340/
This is ApacheBench, Version 2.3 <$Revision: 655654 {1}gt;
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requestsServer Software:        
Server Hostname:        127.0.0.1
Server Port:            1340Document Path:          /
Document Length:        16384 bytesConcurrency Level:      300
Time taken for tests:   1.167 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      164220000 bytes
HTML transferred:       163840000 bytes
Requests per second:    8565.63 [#/sec] (mean)
Time per request:       35.024 [ms] (mean)
Time per request:       0.117 [ms] (mean, across all concurrent requests)
Transfer rate:          137368.00 [Kbytes/sec] receivedConnection Times (ms)min  mean[+/-sd] median   max
Connect:        0    0   0.9      0       9
Processing:     0   16  12.5     15     611
Waiting:        0   15  12.4     15     610
Total:          1   16  12.5     15     612Percentage of the requests served within a certain time (ms)50%     1566%     1975%     2180%     2390%     2695%     3098%     3399%     37100%    612 (longest request)
  说明:在300个并发,10000个请求下,采用buffer方式构造对象的性能优化是和之前的3倍以上。
  

  

  

  

  

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-345504-1-1.html 上篇帖子: 学习nodejs、seajs中 下篇帖子: nodejs的单线程——有趣的比喻
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表