小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

開啟一個參數(shù)就能讓你的WEB性能提升3倍

 命運(yùn)之輪 2016-07-19

一、遇到的一些問題

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

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

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

短連接的話最佳QPS約4萬,長連接的話最高QPS約13萬。

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

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

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

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

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

二、解決方案

測試環(huán)境

Default
1
2
3
    Dell PowerEdge M620 Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz
    Linux 3.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 BCM57810 10 Gigabit Ethernet (rev 10)

查看編譯參數(shù)

21

Nginx 配置如下:

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

Default
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
use epoll;
multi_accept on;
reuse_port on;
worker_connections  1048576;
}
dso { # 動態(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_size 512;
server_name_in_redirect off;
fastcgi_connect_timeout 3s;
fastcgi_send_timeout 3s;
fastcgi_read_timeout 3s;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
variables_hash_max_size  1024;
set_real_ip_from 10.0.0.0/8;
set_real_ip_from 172.28.0.0/16;
set_real_ip_from 192.168.0.0/16;
real_ip_header X-Forwarded-For;
gzip off;
gzip_disable "msie6";
gzip_min_length 1k;
gzip_buffers 16 64k;
gzip_http_version 1.1;
gzip_comp_level 6;
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.1 TLSv1.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       80 backlog=65535;
charset utf-8;
location / { # 打印Tengine狀態(tài)頁
stub_status on; # 開啟狀態(tài)頁,依賴 http_stub_status_module 模塊
access_log  off; #訪問過程不記日志
}
location ~ ^(.*)\/\.(svn|git|hg|bzr|cvs)\/ { # 屏蔽這些目錄
deny all;
access_log off;
log_not_found off;
}
location ~ /\. { # 屏蔽.開頭的目錄或文件,比如  .htaccess .bash_history
deny all;
access_log off;
log_not_found off;
}
location /do_not_delete.html {
access_log off;
empty_gif;
}
}
}

壓測 reuse_port

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

22

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

23

對比一下測試 reuse_port 的效果,小伙伴們驚呆了(短連接QPS過了24萬)!

25

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

探個究竟

測試過程中由于壓大 TCP: Possible SYN flooding on port 80. ,出大量錯誤 。

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

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

26

然后再打開 reuse_port ,對比 perf top 的情況:

27

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

28

我們來看看些時的隊列情況(有入隊過萬了):

29

然后我們再來挑戰(zhàn)30萬并發(fā)(MTT是平均響應(yīng)時間(ms)):

30

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

31

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

【via@運(yùn)維幫

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多