標籤:nginx memcached
測試客戶機A: HP DL380G4,2個雙核CPU,4G Ram,2塊10k RPM SAS盤做raid 1,ext3
Nginx所在伺服器B:DELL R710,E5620 * 2,32G Ram,6塊盤15K RPM SAS盤做raid 1+0,xfs
Memcached所在伺服器C:DELL R710,E5620 * 2,32G Ram,6塊盤15K RPM SAS盤做raid 5,ext4
Nginx設定:keepalive 8192
Php fpm設定:listen.backlog = -1
memcached啟動參數:memcached -d -m 24576 -p 12000 -c 10240
核心參數:
net.ipv4.tcp_tw_recycle = 0net.ipv4.tcp_tw_reuse = 0net.ipv4.tcp_timestamps = 1
關於這幾個核心參數對應的解釋可參考資料:2.12. Reduce TCP performance spikes
使用php串連本地nginx代理,存取遠程memcached資料;
使用php直接連接遠程memcached伺服器;
從測試用戶端用ab發起並發測試;
並發線程從64開始,直到2048,分別是64的N倍;
每種併發模式都進行5輪測試,最後取平均值;
儲存在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;" />
結論及建議:
Php程式通過HttpMemcMC訪問memcache和直接存取memcached的效率並沒有太多損失;
採用php直接存取memcached,失敗的次數相比通過HttpMemcMC有較大增加,應該是HttpMemcMC在keepalive方面更有優勢;
後續會在進行一次測試,調整nginx、php及核心相關參數,再做對比;
本次測試沒有和正常的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效率對比測試