nginx nodejs faye性能问题

时间:2014-01-25 09:41:47

标签: node.js nginx benchmarking faye

我正在为多个Faye Chat服务器进行nginx负载均衡。 我能够在普通的http请求中看到显着的性能。但是,在没有nginx的情况下比较结果时,websocket连接性能非常低。

这是我的nginx配置。

upstream backend {
    server 127.0.0.1:4000;
    server 127.0.0.1:4002;
    server 127.0.0.1:4003;
    server 127.0.0.1:4004;
}

server {
    listen   4001;

    root /var/www/html/laughing-robot;
    index index.html index.htm;

    server_name backend;

    location /faye {
            proxy_pass http://backend;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }

        location / {
            proxy_http_version 1.1;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_set_header   X-NginX-Proxy    true;
            proxy_set_header   Host             $http_host;
            proxy_set_header   Upgrade          $http_upgrade;
            proxy_redirect     off;
            proxy_pass         http://backend;
        }
}

我使用websocket-bench对Faye连接进行基准测试(websocket)。

以下是nginx的结果:

user@machine:/etc/nginx/sites-enabled$ websocket-bench -a 2000 -c 500 -t faye http://127.0.0.1:4000/faye
Launch bench with 2000 total connection, 500 concurent connection
0 message(s) send by client
1 worker(s)
WS server : faye
trying : 500 ...
trying : 1000 ...
trying : 1500 ...
trying : 2000 ...

#### steps report ####
┌────────┬─────────────┬────────┬──────────────┐
│ Number │ Connections │ Errors │ Duration(ms) │
├────────┼─────────────┼────────┼──────────────┤
│ 500    │ 500         │ 0      │ 2488         │
├────────┼─────────────┼────────┼──────────────┤
│ 1000   │ 500         │ 0      │ 2830         │
├────────┼─────────────┼────────┼──────────────┤
│ 1500   │ 500         │ 0      │ 2769         │
├────────┼─────────────┼────────┼──────────────┤
│ 2000   │ 500         │ 0      │ 2144         │
└────────┴─────────────┴────────┴──────────────┘
#### total report ####
┌────────┬─────────────┬────────┬──────────────┬──────────────┬──────────────┐
│ Number │ Connections │ Errors │ Message Send │ Message Fail │ Duration(ms) │
├────────┼─────────────┼────────┼──────────────┼──────────────┼──────────────┤
│ 2000   │ 2000        │ 0      │ 0            │ 0            │ 5150         │
└────────┴─────────────┴────────┴──────────────┴──────────────┴──────────────┘

总持续时间低于6000 ms

以下是nginx负载均衡器的结果:

user@machine:/etc/nginx/sites-enabled$ websocket-bench -a 2000 -c 500 -t faye http://127.0.0.1:4001/faye
Launch bench with 2000 total connection, 500 concurent connection
0 message(s) send by client
1 worker(s)
WS server : faye
trying : 500 ...
trying : 1000 ...
trying : 1500 ...
trying : 2000 ...

#### steps report ####
┌────────┬─────────────┬────────┬──────────────┐
│ Number │ Connections │ Errors │ Duration(ms) │
├────────┼─────────────┼────────┼──────────────┤
│ 500    │ 500         │ 0      │ 6452         │
├────────┼─────────────┼────────┼──────────────┤
│ 1000   │ 500         │ 0      │ 9394         │
├────────┼─────────────┼────────┼──────────────┤
│ 1500   │ 500         │ 0      │ 12772        │
├────────┼─────────────┼────────┼──────────────┤
│ 2000   │ 500         │ 0      │ 16163        │
└────────┴─────────────┴────────┴──────────────┘
#### total report ####
┌────────┬─────────────┬────────┬──────────────┬──────────────┬──────────────┐
│ Number │ Connections │ Errors │ Message Send │ Message Fail │ Duration(ms) │
├────────┼─────────────┼────────┼──────────────┼──────────────┼──────────────┤
│ 2000   │ 2000        │ 0      │ 0            │ 0            │ 19173        │
└────────┴─────────────┴────────┴──────────────┴──────────────┴──────────────┘

总共2000个连接& 500个并发连接,nginx loadbalancer的性能非常低。

我还配置了nofile& file-max

/etc/security/limits.conf文件

*       soft    nofile  2048
*       hard    nofile  65536

/etc/sysctl.conf中

fs.file-max = 100000

在Fedora上,我在/var/log/nginx/error.log上收到很多连接拒绝错误。但是在Ubuntu 13.04上没有错误。

如果有人能够把我推向正确的方向,那将是非常值得注意的。

谢谢!

1 个答案:

答案 0 :(得分:0)

你知道https://github.com/observing/balancerbattle吗?

如果ubuntu没有收到任何错误,那么性能如何? (希望系统在性能上具有可比性)

无论如何,看看内核调优部分,你也可以尝试他们在测试中使用的nginx.conf,看看是否会产生相同的结果。

如果可能,您应该尝试多次负载测试。您所做的测试是在运行nginx的服务器上进行的,测试如何从您的域上的实际外部IP进行比较?

我建议在开发机器上运行负载测试,而不是在实际服务器上运行。 对于nginx和节点进程来说,顶级的cpu /内存是什么呢? nginx maby是否会使你的一个进程和/或测试本身挨饿?

Websockets比ssl更稳定,也值得测试它。

他们使用Thor进行测试,这会给你带来相同的结果吗? https://github.com/observing/balancerbattle/blob/master/results/messaging/HAproxy/1k.md