我的 haproxy 设置有 2 个后端:be1 和 be2
我使用 ACL 根据路径进行路由。
当 be2 开始开发队列时,对 be1 的请求会受到负面影响 - 通常需要 100 毫秒的请求需要 2-3 秒(就像对 be2 的请求所发生的情况一样)。
有没有办法让be2排队而不影响be1的性能?
在高峰期,我每秒处理大约 2000 个请求。
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 2000
#chroot /usr/share/haproxy
user haproxy
group haproxy
daemon
#debug
#quiet
ulimit-n 65535
stats socket /var/run/haproxy.sock
nopoll
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
frontend http_in *:80
option httpclose
option forwardfor
acl vt path_beg /route/1
use_backend be2 if vt
default_backend be1
backend be1
balance leastconn
option httpchk HEAD /redirect/are_you_alive HTTP/1.0
server 01-2C2P9HI x:80 check inter 3000 rise 2 fall 3 maxconn 500
backend be2
balance leastconn
option httpchk HEAD /redirect/are_you_alive HTTP/1.0
server 01-3TPDP27 x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-3CR0FKC x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-3E9CVMP x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-211LQMA x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-3H974V3 x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-13UCFVO x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-0HPIGGT x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-2LFP88F x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-1TIQBDH x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-2GG2LBB x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-1H5231E x:80 check inter 3000 rise 2 fall 3 maxconn 250
server 01-0KIOVID x:80 check inter 3000 rise 2 fall 3 maxconn 250
listen stats 0.0.0.0:7474 #Listen on all IP's on port 9000
mode http
balance
timeout client 5000
timeout connect 4000
timeout server 30000
#This is the virtual URL to access the stats page
stats uri /haproxy_stats
#Authentication realm. This can be set to anything. Escape space characters with a backslash.
stats realm HAProxy\ Statistics
#The user/pass you want to use. Change this password!
stats auth ge:test123
#This allows you to take down and bring up back end servers.
#This will produce an error on older versions of HAProxy.
stats admin if TRUE
不知道我昨天怎么没有注意到这一点,但是看到 maxconn 设置为 2000...所以这可能是我的问题之一?
最佳答案
有两种不同的 maxconn 设置。一种用于前端,另一种用于后端。前端的设置限制传入连接,因此即使您的后端可用,它也不会收到请求,因为它在前端排队。一旦请求通过前端,后端就会排队。前端受到“默认”部分中 maxconn 设置的影响,因此我会将其增加到 4000,例如,因为后端应该能够处理它。
请注意,maxconn 不限制每秒请求数,而是限制同时连接数。您可能有一些活跃的 HTTP 保持事件请求,这可能会严重限制可用吞吐量。
关于具有 2 个后端的 haproxy - 当 1 个后端排队时,另一个也会受到影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11870038/