人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

Nginx開(kāi)啟一個(gè)參數(shù)就能讓你的WEB性能提升3倍的方法

發(fā)布日期:2022-03-13 12:47 | 文章來(lái)源:站長(zhǎng)之家

一、遇到的一些問(wèn)題

記得 2008 年做性能測(cè)試的時(shí)候,新進(jìn)7臺(tái) lenovo 4核4G 服務(wù)器用于性能測(cè)試。

當(dāng)時(shí)資源緊張,這7臺(tái)服務(wù)器都裝了雙系統(tǒng)(Win2003/CentOS5)空閑時(shí)用于做測(cè)試機(jī)(壓測(cè)的Agent)。

當(dāng)時(shí)給Nginx做了一系列測(cè)試,印象很深的是:在這批機(jī)器上,Nginx狀態(tài)頁(yè)面的壓測(cè)。

短連接的話最佳QPS約4萬(wàn),長(zhǎng)連接的話最高QPS約13萬(wàn)。

大概3年后,那批 lenovo 服務(wù)器已經(jīng)沒(méi)人瞧得上了,只能做肉雞。

然而,一次不經(jīng)意的測(cè)試,發(fā)現(xiàn)再牛的服務(wù)器,短連接最佳QPS也高不了多少。而且,測(cè)試機(jī)的資源沒(méi)用完,被測(cè)試服務(wù)器的資源也用不完,網(wǎng)絡(luò)也沒(méi)瓶頸。

服務(wù)器資源使用率很低,然而響應(yīng)就是不夠快。

最后,我們發(fā)現(xiàn)了瓶頸在監(jiān)聽(tīng)的入口!是否可以提高監(jiān)聽(tīng)入口的性能?是否可以端口復(fù)用?最后我們找到了SO_REUSEPORT。

SO_REUSEPORT支持多個(gè)進(jìn)程或者線程綁定到同一端口,提高服務(wù)器程序的性能。

二、解決方案

測(cè)試環(huán)境

Dell PowerEdge M620 Intel(R)Xeon(R)CPU E5–2620v2@2.10GHz
Linux3.16.0–4–amd64#1 SMP Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04) x86_64 GNU/Linux
Ethernet controller:Broadcom Corporation NetXtreme II BCM5781010Gigabit Ethernet(rev10)

查看編譯參數(shù)

Nginx 配置如下:

注意有一個(gè)reuse_port參數(shù)

user www–data;
worker_processes auto;
pid/run/nginx.pid;
events{
useepoll;
multi_accept on;
reuse_port on;
worker_connections 1048576;
}
dso{# 動(dòng)態(tài)加載功能模塊 /usr/share/nginx/modules
load ngx_http_memcached_module.so;
load ngx_http_limit_conn_module.so;
load ngx_http_empty_gif_module.so;
load ngx_http_scgi_module.so;
load ngx_http_upstream_session_sticky_module.so;
load ngx_http_user_agent_module.so;
load ngx_http_referer_module.so;
load ngx_http_upstream_least_conn_module.so;
load ngx_http_uwsgi_module.so;
load ngx_http_reqstat_module.so;
load ngx_http_browser_module.so;
load ngx_http_limit_req_module.so;
load ngx_http_split_clients_module.so;
load ngx_http_upstream_ip_hash_module.so;
}
http{
include    /etc/nginx/mime.types;
default_type text/plain;
access_log off;
sendfile    on;
tcp_nopush  on;
tcp_nodelay  on;
server_tokens off;
keepalive_timeout 120;
server_names_hash_bucket_size512;
server_name_in_redirect off;
fastcgi_connect_timeout3s;
fastcgi_send_timeout3s;
fastcgi_read_timeout3s;
fastcgi_buffer_size128k;
fastcgi_buffers8128k;
fastcgi_busy_buffers_size256k;
fastcgi_temp_file_write_size256k;
variables_hash_max_size 1024;
set_real_ip_from10.0.0.0/8;
set_real_ip_from172.28.0.0/16;
set_real_ip_from192.168.0.0/16;
real_ip_headerX–Forwarded–For;
gzip off;
gzip_disable“msie6”;
gzip_min_length1k;
gzip_buffers1664k;
gzip_http_version1.1;
gzip_comp_level6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_vary on;
ssl_protocols TLSv1 TLSv1.1TLSv1.2;# Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log/var/log/nginx/access.log;
error_log/var/log/nginx/error.log;
server{
listen    80backlog=65535;
charset utf–8;
location/{# 打印Tengine狀態(tài)頁(yè)
stub_status on;# 開(kāi)啟狀態(tài)頁(yè),依賴 http_stub_status_module 模塊
access_log off;#訪問(wèn)過(guò)程不記日志
}
location~^(.*)\/\.(svn|git|hg|bzr|cvs)\/{# 屏蔽這些目錄
deny all;
access_log off;
log_not_found off;
}
location~/\.{# 屏蔽.開(kāi)頭的目錄或文件,比如 .htaccess .bash_history
deny all;
access_log off;
log_not_found off;
}
location/do_not_delete.html{
access_log off;
empty_gif;
}
}
}

壓測(cè) reuse_port

Tengine 早已支持 reuse_port 。開(kāi)啟 reuse_port 后,你會(huì)發(fā)現(xiàn)有很多進(jìn)程同時(shí)監(jiān)聽(tīng)80端口:

加壓后你會(huì)發(fā)現(xiàn),服務(wù)器性能可被你榨干:

對(duì)比一下測(cè)試 reuse_port 的效果,小伙伴們驚呆了(短連接QPS過(guò)了24萬(wàn))!

真相大白后,你還等什么?

探個(gè)究竟

測(cè)試過(guò)程中由于壓大 TCP: Possible SYN flooding on port 80. ,出大量錯(cuò)誤 。

于是將并發(fā)量降到了6萬(wàn) net.core.somaxconn = 65535 。

再關(guān)閉 reuse_port 后,我們看下 perf top的情況:

然后再打開(kāi) reuse_port ,對(duì)比 perf top 的情況:

此時(shí)再放大 Nginx 監(jiān)聽(tīng)的 back_log ,看下資源使用情況:

我們來(lái)看看些時(shí)的隊(duì)列情況(有入隊(duì)過(guò)萬(wàn)了):

然后我們?cè)賮?lái)挑戰(zhàn)30萬(wàn)并發(fā)(MTT是平均響應(yīng)時(shí)間(ms)):

經(jīng)過(guò)一系列調(diào)優(yōu),相同環(huán)境相同并發(fā)量,沒(méi)有再出現(xiàn) TCP: Possible SYN flooding on port 80.。但出現(xiàn)了少量連接超時(shí)的情況:

至此測(cè)試完畢,開(kāi)啟reuse_port確實(shí)可以讓性能提升3倍,何不試試。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。

版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開(kāi)通

自選配置、實(shí)時(shí)開(kāi)通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問(wèn)服務(wù)

1對(duì)1客戶咨詢顧問(wèn)

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部