hello world的benchmark
发布于 9 年前 作者 anklos 4126 次浏览 最后一次编辑是 8 年前 来自 问答

我经常听到别人的node.js本机的hello world程序可以跑到10000/s的数据,可我在我的2014 新的macpro机子上跑,怎么只能拿到1400/s的数据?

ulimit:

-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       709
-n: file descriptors                9999

helloworld.js

// Load the http module to create an http server.
var http = require('http');

http.globalAgent.maxSockets = 2000;

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

性能测试工具wrk wrk -t8 -c800 -d30s http://localhost:8000/

测试结果:

Running 30s test @ http://localhost:8000/
  8 threads and 800 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    71.76ms   32.52ms 191.40ms   81.79%
    Req/Sec     1.41k   527.68     4.00k    70.22%
  333705 requests in 30.00s, 49.65MB read
  Socket errors: connect 0, read 958, write 0, timeout 797

为什么 结果这么渣渣?达人请指点指点!谢谢!!

13 回复

https://cnodejs.org/topic/53df57aa111cfedf0b4500b5#53ed8959bdaad9a22f83c298

貌似node连接开多反而性能下降。另外你这个测试开8线程,node本身是单线程,多线程的用例见这里: https://cnodejs.org/topic/53df57aa111cfedf0b4500b5#53df8d7bbd3cc3e50b4a9dfc

最最后,nodejs的http性能本来就不突出,所以大家才用nginx+node。

@pockry 嗯,我是想benchmark单线程的。

fibjs这种天顶星技术暂时不敢用啊。

如果用node.js自带的cluster或者passenger来管理多进程都可以,但前者官方说是experimental,后者在大规模并发测试中总时不时有 Resource temporarily unavailable) while connecting to upstream的错误。

自己怒顶一下。

并发数会不会太大了点?

@alsotang 啊。。不是并发数越大越能达到每秒最大requests数量吗?

@alsotang 真的是这样,如果运行wrk -t1 -c1 -d10s http://localhost:8000, 数据直接刷到17k. 为什么!!

wrk先等到第一批所有并发的requests返回,再进行下一批是吗?这样并发越多久越会导致wrk等待第一批的时间变长?

我晕。。才发现,那个req/sec是每个thread的数据,要乘以8才是总共每秒数据。

这下脑筋顺了。。谢谢大家。

這時候該拿出 這張圖了,哈哈 Screen Shot 2014-12-01 at 4.16.51 PM.png

@ngot 牛!fibjs也自带cluster的module吗?nodejs 将要推出的0.12版本的cluster用round robin据说更吊哦

本机测了下helloworld的cluster版本性能(4 cpu), 可以到72k/s

  8 threads and 80 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.13ms    1.12ms  25.30ms   88.20%
    Req/Sec     9.75k     4.36k   22.11k    60.48%
  724735 requests in 10.00s, 89.85MB read
Requests/sec:  72479.33
Transfer/sec:      8.99MB

@anklos 多进程才勉强拼过单进程的fibjs

@ngot fibjs有模块可以根据CPU的数量线性scale吗?

@anklos 自动利用多核,不需要什么模块支持,和golang类似

@ngot 那你这个50000/s的数据是单核的吗?还是自动用了多核已经?

回到顶部