haproxy(七)多線程使用

來源:互聯網
上載者:User

現象

HAProxy綁定4核cpu、8核cpu、16核cpu,壓測的時候,都會出現CPU 100%被使用的情況。

追查過程

1. 通過 mpstat  -P ALL 1 命令查看cpu 都用在哪裡,可以看到cpu都絕大部分用在 sys態上。

 

2. 通過 strace -p pid -c 查看HAProxy 進程那個系統調用佔用cpu 最多,看到cpu 都用在了 connect系統調用上。

 

3. HAProxy串連後端會使用connect系統調用,查看HAProxy配置,發現HAProxy串連後端就只有兩個後端,即這種情況: vegeta(40台壓測機器)-》HAProxy-》httptest(2台HAProxy後端),其中 HAProxy串連後端最多隻能有63000個連接埠左右,大量的串連積壓在HAProxy機器上,導致cpu被耗盡了。


多線程使用方法

nbproc <number>
cpu-map <“all”|”odd”|”even”|process_num> <cpu-set>…

這2個配置是密切相關的,nbproc是指啟動多少個haproxy進程。

#nbproc設定為4,講啟動4個進程haproxy  11472  0.0  0.0  56520  1228 ?        Ss   08:57   0:00 ./haproxy -f /usr/local/haproxy/conf/haproxy.cfghaproxy  11473  0.0  0.0  56520  1228 ?        Ss   08:57   0:00 ./haproxy -f /usr/local/haproxy/conf/haproxy.cfghaproxy  11474  0.0  0.0  56520  1228 ?        Ss   08:57   0:00 ./haproxy -f /usr/local/haproxy/conf/haproxy.cfghaproxy  11475  0.0  0.0  56520  1228 ?        Ss   08:57   0:00 ./haproxy -f /usr/local/haproxy/conf/haproxy.cfg#查看pid檔案,也可以看到四個進程ID# cat /run/haproxy.pid 11472114731147411475
cpu-map是將進程綁定到特定的CPU上,這個好處是防止多進程對CPU的搶佔,可以提升少量效能。這個配置指令有2個參數,第一參數是進程式號,從1開始。第二個參數是CPU序號,從0開始。舉例說明如果將進程綁定到指定的CPU上的。

#查看原生CPU個數,同時也可以看到CPU的序號從0開始# cat /proc/cpuinfo | grep processorprocessor    : 0processor    : 1processor    : 2processor    : 3
# 逐一指定cpu-map 1 0cpu-map 2 1cpu-map 3 2cpu-map 4 3cpu-map 5 4 //該條超過nbproc的數量,將被忽略#全部的進程由0號cpu處理。cpu-map all 0#奇數的進程有0號cpu處理,偶數的進程有1號cpu處理。cpu-map odd 0cpu-map even 1
後端綁定

frontend access_http   bind 0.0.0.0:80   bind-process 1frontend access_https   bind 0.0.0.0:443 ssl crt /etc/yourdomain.pem   bind-process 2 3 4






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.