我正在为多个Faye聊天服务器做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负载均衡器的性能非常低。
我还配置了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上没有错误。
如果有人能把我引向正确的方向,那就太好了。
谢谢!
发布于 2014-02-07 03:59:01
你认识https://github.com/observing/balancerbattle吗?
如果你在ubuntu上没有收到错误,性能如何?(希望这些系统在性能上具有可比性)
无论如何,看看内核调优部分,你也可以尝试他们在测试中使用的nginx.conf,看看结果是否相同。
此外,如果可能的话,您应该尝试多个负载测试。您所做的测试是在运行nginx的服务器上进行的,与您的域上的实际外部ip相比,测试结果如何?
我建议在开发机器上运行负载测试,而不是在实际的服务器上。另外,对于nginx和node进程,top对cpu/内存的看法是什么?nginx maby是否会饿死你的某个进程和/或测试本身?
Websockets比ssl更稳定,这也是值得一试的。
他们用雷神做测试,你能得到同样的结果吗?https://github.com/observing/balancerbattle/blob/master/results/messaging/HAproxy/1k.md
https://stackoverflow.com/questions/21348933
复制相似问题