我正在研究用HAProxyreplace专有的软件负载平衡器。 作为这项调查的一部分,我试图在负载下testingHAProxy。 虽然我的HAProxyconfiguration在单用户testing时工作正常,但只要我加载它,网站的速度开始急剧下降,不久(约100个模拟用户)我们的负载testing工具开始报告故障。
这是非常直接的configuration,只有值得注意的一点是我们正在使用HAProxy 1.5.4以及OpenSSL和PCRE支持编译和使用。 我们也有一些ACL可以在URL上匹配,尽pipe这个前端并没有用在这个负载testing中。
这是在CentOS 6.5机器上运行。
负载testing中前端/后端组合的(消毒)configuration以及全局和默认值:
global daemon tune.ssl.default-dh-param 2048 maxconn 100000 maxsessrate 100000 log /dev/log local6 defaults mode http option forwardfor option http-server-close timeout client 61s timeout server 61s timeout connect 13s log global option httplog frontend stats bind xxx.xxx.xxx.xxx:80 default_backend stats-backend backend stats-backend stats enable server stats 127.0.0.1:80 frontend portal-frontend bind xxx.xxx.xxx.xxx:80 default_backend portal-backend frontend portal-frontend-https bind xxx.xxx.xxx.xxx:443 ssl crt /path/to/pem default_backend portal-backend backend portal-backend redirect scheme https if !{ ssl_fc } appsession session len 140 timeout 4h request-learn server web1.example.com web1.example.com:80 check server web2.example.com web2.example.com:80 check [...snip...]
在负载testing期间,我们从日志中获取一些信息,但不是大量的。 相关片段:
Sep 4 11:06:12 xxxx haproxy[15609]: xxx.xxx.xxx.xxx:30983 [04/Sep/2014:11:05:42.984] portal-frontend-https~ portal-frontend-https/<NOSRV> -1/-1/-1/-1/28782 408 212 - - cR-- 1840/1840/0/0/0 0/0 "<BADREQ>" ... Sep 4 11:06:03 xxxx haproxy[15609]: xxx.xxx.xxx.xxx:61502 [04/Sep/2014:11:05:47.810] portal-frontend-https~ portal-frontend-https/<NOSRV> -1/-1/-1/-1/14345 400 187 - - CR-- 1715/1693/0/0/0 0/0 "<BADREQ>" ... Sep 4 11:06:03 xxxx haproxy[15609]: xxx.xxx.xxx.xxx:43939 [04/Sep/2014:11:05:59.553] portal-frontend portal-backend/<NOSRV> 314/-1/-1/-1/2602 302 181 - - LR-- 1719/22/223/0/3 0/0 "GET /mon/login.php?C=1&LID=15576783&TID=8145&PID=8802 HTTP/1.1"
在这些日志条目的基础上,我们尝试了诸如调整超时http请求之类的东西,但没有任何改进(在我们的工具报告失败之前,负载testing会运行更长的时间,但是减速发生的方式类似) 。
我相信HAProxy能做得比这更好,但我现在真的不知道该从哪里开始诊断问题(或限制)了。
请运行dmesg并确保你的iptables的conntrack表没有满…你可能有很多这样的消息:“ip_conntrack:table full,dropped packet”
如果是这样,请调整您的sysctl:net.ipv4.netfilter.ip_conntrack_max默认值非常低。 你最多可以设置50000,也许更多,取决于你的工作量。
巴蒂斯特
菲利克斯是对的。 你需要把你的后台服务器上的maxconn设置得很低,你的全局maxconn是高的。 把这样的东西像4000。
了解全局和服务器maxconn的差异至关重要。
Willy Tarreau(HAProxy的作者)在这里描述的非常清楚: https ://stackoverflow.com/questions/8750518/difference-between-global-maxconn-and-server-maxconn-haproxy
我一直在使用HAProxy多年,在后端服务器上默认为64个maxcon。
HAProxy是非常高的性能,当然如果configuration错误,可以超载Web服务器。 看看networking服务器的networking连接和错误日志,看看他们是否达到最大连接。 如果是这样,我不会感到惊讶。