Nginx HttpMemcModule和直接存取memcached效率對比測試

來源:互聯網
上載者:User

標籤:nginx   memcached   

  • 測試環境:

  1. 測試客戶機A: HP DL380G4,2個雙核CPU,4G Ram,2塊10k RPM SAS盤做raid 1,ext3

  2. Nginx所在伺服器B:DELL R710,E5620 * 2,32G Ram,6塊盤15K RPM SAS盤做raid 1+0,xfs

  3. Memcached所在伺服器C:DELL R710,E5620 * 2,32G Ram,6塊盤15K RPM SAS盤做raid 5,ext4

  4. Nginx設定:keepalive 8192

  5. Php fpm設定:listen.backlog = -1

  6. memcached啟動參數:memcached -d -m 24576 -p 12000 -c 10240

  7. 核心參數:

net.ipv4.tcp_tw_recycle = 0net.ipv4.tcp_tw_reuse = 0net.ipv4.tcp_timestamps = 1

關於這幾個核心參數對應的解釋可參考資料:2.12. Reduce TCP performance spikes

  • 測試方案:

  1. 使用php串連本地nginx代理,存取遠程memcached資料;

  2. 使用php直接連接遠程memcached伺服器;

  3. 從測試用戶端用ab發起並發測試;

  4. 並發線程從64開始,直到2048,分別是64的N倍;

  5. 每種併發模式都進行5輪測試,最後取平均值;

  6. 儲存在memcached中的key長度96個字元,value長度400字元,總是隨機產生;

  • 測試結果:

650) this.width=650;" class="alignnone size-medium wp-image-152" alt="NginxHttpMemcMC-vs-NativeMC-benchmark-2013091301" src="http://imysql.com/wp-content/uploads/2013/09/NginxHttpMemcMC-vs-NativeMC-benchmark-2013091301-300x180.png" width="300" height="180" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;height:auto;" />  650) this.width=650;" class="alignnone size-medium wp-image-153" alt="NginxHttpMemcMC-vs-NativeMC-benchmark-2013091302" src="http://imysql.com/wp-content/uploads/2013/09/NginxHttpMemcMC-vs-NativeMC-benchmark-2013091302-300x180.png" width="300" height="180" style="margin:0px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;height:auto;" />

650) this.width=650;" class="alignnone size-medium wp-image-154" alt="NginxHttpMemcMC-vs-NativeMC-benchmark-2013091303" src="http://imysql.com/wp-content/uploads/2013/09/NginxHttpMemcMC-vs-NativeMC-benchmark-2013091303-300x180.png" width="300" height="180" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;height:auto;" />  650) this.width=650;" class="alignnone size-medium wp-image-155" alt="NginxHttpMemcMC-vs-NativeMC-benchmark-2013091304" src="http://imysql.com/wp-content/uploads/2013/09/NginxHttpMemcMC-vs-NativeMC-benchmark-2013091304-300x180.png" width="300" height="180" style="margin:0px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;height:auto;" />

結論及建議:

  1. Php程式通過HttpMemcMC訪問memcache和直接存取memcached的效率並沒有太多損失;

  2. 採用php直接存取memcached,失敗的次數相比通過HttpMemcMC有較大增加,應該是HttpMemcMC在keepalive方面更有優勢;

  3. 後續會在進行一次測試,調整nginx、php及核心相關參數,再做對比;

  4. 本次測試沒有和正常的http請求混在一起對比,測試結果不具備絕對參考價值;

單從本次測試結果來看,HttpMemcMC值得擁有 :)

  • 結果結果更新:

調整上述幾個核心參數:

net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_timestamps = 1

通過調整核心參數,調整tcp串連複用性提高tcp效率,新的測試結果如下:

650) this.width=650;" class="alignnone size-medium wp-image-156" alt="NginxHttpMemcMC-vs-NativeMC-benchmark-2013091305" src="http://imysql.com/wp-content/uploads/2013/09/NginxHttpMemcMC-vs-NativeMC-benchmark-2013091305-300x180.png" width="300" height="180" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;height:auto;" />   650) this.width=650;" class="alignnone size-medium wp-image-157" alt="NginxHttpMemcMC-vs-NativeMC-benchmark-2013091306" src="http://imysql.com/wp-content/uploads/2013/09/NginxHttpMemcMC-vs-NativeMC-benchmark-2013091306-300x180.png" width="300" height="180" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;height:auto;" /> 650) this.width=650;" class="alignnone size-medium wp-image-158" alt="NginxHttpMemcMC-vs-NativeMC-benchmark-2013091307" src="http://imysql.com/wp-content/uploads/2013/09/NginxHttpMemcMC-vs-NativeMC-benchmark-2013091307-300x180.png" width="300" height="180" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;height:auto;" />   650) this.width=650;" class="alignnone size-medium wp-image-159" alt="NginxHttpMemcMC-vs-NativeMC-benchmark-2013091308" src="http://imysql.com/wp-content/uploads/2013/09/NginxHttpMemcMC-vs-NativeMC-benchmark-2013091308-300x180.png" width="300" height="180" style="margin:0px;padding:0px;border:0px;vertical-align:baseline;height:auto;" />

備忘:由於2次測試案例中,每並發線程請求數不一樣,所以你會發現兩邊的資料無法直接對比,這是我的失誤,抱歉。

  • 補充小結:

調整完核心後:
1. 可以發現,HttpMemc的平均效率只有NativeMC 72.62%;
2. 調整核心tcp參數對提升tcp效率非常有協助,Failed requests次數完全為0;
3. 由於可以提高memcached串連複用率以及對程式透明的好處,即便HttpMemc效能不如NativeMC,損失並不是非常厲害,仍然是可以接受的;


--------------------------------------分割線--------------------------------------

知數堂 (http://zhishuedu.com)培訓是由資深MySQL專家葉金榮、吳炳錫聯合推出的專業優質培訓品牌,主要有MySQL DBA實戰最佳化和Python營運開發課程,是業內最有良心、最有品質的培訓課程。

本文出自 “老葉茶館” 部落格,請務必保留此出處http://imysql.blog.51cto.com/1540006/1879883

Nginx HttpMemcModule和直接存取memcached效率對比測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.