我正在尝试HAProxy进行TCP负载平衡。连接在单个IP上进入端口X,然后HAProxy使用“leastconn”平衡方法将这些连接平衡到后端,以保持连接数均匀。这是在Ubuntu 10.04 x64上。
我已经将内核配置中的file-max调高到700,000。我已经将每个进程的ulimit调高到大约400,000。我已经将haproxy配置中的maxconn调到了200,000。它报告看到这个maxconn很好:
show info
Name: HAProxy
Version: 1.3.22
Release_date: 2009/10/14
Nbproc: 1
Process_num: 1
Pid: 1355
Uptime: 0d 4h38m46s
Uptime_sec: 16726
Memmax_MB: 0
Ulimit-n: 400013
Maxsock: 400013
Maxconn: 200000
Maxpipes: 0
CurrConns: 1113
PipesUsed: 0
PipesFree: 0
Tasks: 1113
Run_queue: 1
node: XXXXX
这个前端负载均衡5个后端系统。但是,当每个后端达到400个会话时,它只是平衡停止平衡,并且只是推迟了其他连接。我可以用“smax”统计数据看到这一点。您将注意到每个会话的最大会话数为400,并且最大会话总数为2000:
show stat
#
pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,
protoa,FRONTEND,,,958,2000,2000,12624,6230219,6445523,0,0,0,,,,,OPEN,,,,,,,,,1,1,0,,,,0,0,0,406,
protoa,XXX1672,0,0,191,400,,3222,1249403,1286659,,0,,221,0,664,0,no check,1,1,0,,,,,,1,1,1,,2559,,2,0,,198,
protoa,XXX1674,0,0,192,400,,3106,1242103,1289247,,0,,178,0,535,0,no check,1,1,0,,,,,,1,1,2,,2572,,2,0,,171,
protoa,XXX1707,0,0,193,400,,3043,1266305,1305311,,0,,164,0,492,0,no check,1,1,0,,,,,,1,1,3,,2551,,2,0,,161,
protoa,XXX1782,0,0,189,400,,3046,1236790,1282690,,0,,204,0,619,0,no check,1,1,0,,,,,,1,1,4,,2429,,2,0,,190,
protoa,XXX1851,0,0,193,400,,3060,1235618,1281616,,0,,189,0,570,0,no check,1,1,0,,,,,,1,1,5,,2490,,2,0,,180,
protoa,BACKEND,0,0,958,2000,2000,12624,6230219,6445523,0,0,,956,0,2880,0,UP,5,5,0,,0,17645,0,,1,1,0,,12601,,1,0,,406,
protob,FRONTEND,,,4,6,2000,28,15204,15726,0,0,0,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,2,
protob,XXX1672,0,0,2,2,,5,2313,2322,,0,,0,0,0,0,no check,1,1,0,,,,,,1,2,1,,5,,2,0,,1,
protob,XXX1674,0,0,0,2,,5,3520,3803,,0,,0,0,0,0,no check,1,1,0,,,,,,1,2,2,,5,,2,0,,1,
protob,XXX1707,0,0,0,2,,8,3303,3214,,0,,0,0,0,0,no check,1,1,0,,,,,,1,2,3,,8,,2,0,,1,
protob,XXX1782,0,0,1,2,,5,3529,3745,,0,,0,0,0,0,no check,1,1,0,,,,,,1,2,4,,5,,2,0,,1,
protob,XXX1851,0,0,1,1,,5,2539,2642,,0,,0,0,0,0,no check,1,1,0,,,,,,1,2,5,,5,,2,0,,1,
protob,BACKEND,0,0,4,6,2000,28,15204,15726,0,0,,0,0,0,0,UP,5,5,0,,0,17645,0,,1,2,0,,28,,1,0,,2,
这种限制来自哪里?我真的想把数十万个连接吸引到这个haproxy实例中。 (机器有网络,CPU和RAM跟上)
答案 0 :(得分:11)
因此,阅读1.3.x版的源代码,我发现: 有两个最大值。 一个是全局最大#连接,在命令行上使用-n设置,在全局配置中使用maxconn。 另一个是每代理最大#连接,在命令行上使用-N设置,或在配置中按代理配置。 具体来说,除了命令行之外,您无法配置每个代理的默认max#connections! 默认是......等待它...... 2000! 因此,在我的/etc/haproxy/haproxy.cfg文件中为每个“listen”部分添加“maxconn 200000”可以解决这个问题。
请注意,尽管文档非常好,但它并没有很好地解释这一点。具体来说,从阅读文档,我认为全局maxconn也将应用于每个代理,但不是这样。对于总连接数,全局maxconn 强制,但必须明确指定给定代理前端的本地最大连接数。