2011-01-28 95 views
5

我正在嘗試HAProxy的TCP負載平衡。連接通過一個IP進入端口X,然後HAProxy使用「leastconn」平衡方法將這些連接平衡到後端,以保持連接數量均勻。這是在Ubuntu 10.04 x64上。HAProxy TCP會話計數在400停止

我已經把內核配置中的file-max設置爲700,000。我已經把per-process 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跟上)

回答

10

因此,閱讀1.3.x版本的源代碼,我發現: 有兩個最大值。 一個是全局最大#連接,在命令行中設置爲-n,在全局配置中設置爲maxconn。 另一個是per-proxy max#連接,在命令行上使用-N設置,或者在配置中爲每個代理配置。 具體而言,您不能配置每個代理的默認最大#連接而不是從命令行! 默認值是...等待它... 2000! 因此,在我的/etc/haproxy/haproxy.cfg文件的每個「監聽」部分中添加「maxconn 200000」可解決此問題。

請注意,儘管文檔非常好,但它並沒有很好地解釋這一點。具體而言,從閱讀文檔的角度來看,我認爲全球maxconn也會應用於每個代理,但並非如此。對於連接總數,全局maxconn爲強制執行,但必須明確指定給定代理前端的本地最大連接數。

+1

我認爲你的答案有點混亂。你說「你不能配置每個代理的默認最大#連接,而不是從命令行」,並且「在'cfg'的每個'listen'部分添加'maxconn 200000'解決了這個問題」,這似乎是矛盾的。 – 2014-03-05 03:09:21