杰克工作室 发表于 2024-2-10 15:17

nginx io瓶颈问题

<p>&nbsp;目前我有几个站大概十几万ip,pv三四百万左右,之前是分成好几台iis服务器,由于网站大部分是生成的静态页面,考虑到nginx对静态页面的优秀的表现,所有就进行了更换,把前后台分离,后台用一台服务器安装server 2008 ii7,前台单独用一台&nbsp;Dual Xeon E5410 16GB &nbsp; CentOS 6 x86_64 &nbsp;Nginx</p>
现在发现前台linux服务器到了高峰期的时候,几个网站打开速度都非常慢,查看服务器内存跟cpu均使用的非常少,但是io非常高<br />
<a href="http://static.oschina.net/uploads/space/2014/0310/154514_s7Bh_1465961.jpg" target="_blank"><img alt="" src="http://static.oschina.net/uploads/space/2014/0310/154514_s7Bh_1465961.jpg" /></a><br />
<a href="http://static.oschina.net/uploads/space/2014/0310/154547_CdU8_1465961.jpg" target="_blank"><img alt="" src="http://static.oschina.net/uploads/space/2014/0310/154547_CdU8_1465961.jpg" /></a><br />
像目前这个情况,我在网上查了,有两种办法,一种是换ssd硬盘的服务器,<br />
一种是把网站的一些经常访问的网页加载到内存中。<br />
第一种,我查了,ssd的服务器基本没有,有也只是有些vps,配置都不咋滴。<br />
第二种,不会弄啊,有什么其他的处理方法没?<br />
我最大并发才1万左右,我就纳闷了,我看到很多人拿nginx测试,随随便便一个低端的服务器都可以抗起三四万并发,我才一万左右,而且服务器还是买的比较好的了,都抗不住。表示不解!!!<br />
贴上我的配置文件:<br />
user &nbsp;www www;<br />
worker_processes 8;<br />
#worker_cpu_affinity auto;<br />
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;<br />
worker_rlimit_nofile 65535;<br />
#error_log &nbsp;logs/error.log;<br />
#error_log &nbsp;logs/error.log &nbsp;notice;<br />
#error_log &nbsp;logs/error.log &nbsp;info;<br />
<br />
#pid &nbsp; &nbsp; &nbsp; &nbsp;logs/nginx.pid;<br />
<br />
<br />
events {<br />
&nbsp; &nbsp; use epoll;<br />
&nbsp; &nbsp; worker_connections &nbsp;20480;<br />
}<br />
<br />
http {<br />
&nbsp; &nbsp; server_names_hash_bucket_size 512; &nbsp;<br />
&nbsp; &nbsp; server_names_hash_max_size 512;<br />
&nbsp; &nbsp; include &nbsp; &nbsp; &nbsp; mime.types;<br />
&nbsp; &nbsp; default_type &nbsp;application/octet-stream;<br />
<br />
<br />
&nbsp; &nbsp; #log_format &nbsp;main &nbsp;&#39;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#39;<br />
&nbsp; &nbsp; # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39;$status $body_bytes_sent &quot;$http_referer&quot; &#39;<br />
&nbsp; &nbsp; # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#39;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#39;;<br />
<br />
<br />
&nbsp; &nbsp; #access_log &nbsp;logs/access.log &nbsp;main;<br />
<br />
<br />
&nbsp; &nbsp; &nbsp;sendfile &nbsp; &nbsp; &nbsp; &nbsp;on;<br />
&nbsp; &nbsp; tcp_nopush &nbsp; &nbsp; on;<br />
<br />
<br />
&nbsp; &nbsp; #keepalive_timeout &nbsp;0;<br />
&nbsp; &nbsp; keepalive_timeout &nbsp;65;<br />
&nbsp; &nbsp; tcp_nodelay on;<br />
&nbsp; &nbsp; server_tokens off;<br />
&nbsp; &nbsp; gzip &nbsp;on;<br />
&nbsp; &nbsp; gzip_min_length &nbsp;1k;<br />
&nbsp; &nbsp; gzip_buffers &nbsp; &nbsp; 4 16k;<br />
&nbsp; &nbsp; gzip_http_version 1.1;<br />
&nbsp; &nbsp; gzip_comp_level 2;<br />
&nbsp; &nbsp; gzip_types &nbsp; &nbsp;text/plain application/x-javascript text/css application/xml;<br />
&nbsp; &nbsp; gzip_vary on;<br />
&nbsp; &nbsp;&nbsp;<br />
&nbsp; &nbsp; include vhost/*.conf;<br />
vhost 里面的网站的配置<br />
server {<br />
<br />
listen &nbsp; &nbsp; &nbsp; 80;<br />
server_name www.xxx.com *.xxx.com;<br />
&nbsp; location / {<br />
&nbsp; root /home/wwwroot/xxx.com;<br />
error_page &nbsp;404 &nbsp;/404.html;<br />
error_page &nbsp;500 502 503 504 &nbsp;/50x.html;<br />
}<br />
}
<hr />兄弟,可以开&nbsp;&nbsp;<strong>open_file_cache 。根据实际的调整:</strong>

<p>&nbsp;</p>

<pre>
<strong>## Set the OS file cache.         open_file_cache max=3000 inactive=120s;         open_file_cache_valid 45s;         open_file_cache_min_uses 2;         open_file_cache_errors off;</strong></pre>
<strong>改完看看效果。&nbsp;</strong><br />
open_file_cache max=65535 inactive=120s;&nbsp;<br />
open_file_cache_valid 45s;&nbsp;<br />
open_file_cache_min_uses 2;&nbsp;
<p>open_file_cache_errors off;</p>

<p>把这个添加进去了,好像没多大用!另外我还参照网上的一些修改了些内核设置:</p>

<p>net.ipv4.ip_forward = 0<br />
net.ipv4.conf.default.rp_filter = 1<br />
net.ipv4.conf.default.accept_source_route = 0<br />
kernel.sysrq = 0<br />
kernel.core_uses_pid = 1<br />
net.ipv4.tcp_syncookies = 1<br />
kernel.msgmnb = 65536<br />
kernel.msgmax = 65536<br />
kernel.shmmax = 68719476736<br />
kernel.shmall = 4294967296<br />
net.ipv4.tcp_max_tw_buckets = 6000<br />
net.ipv4.tcp_sack = 1<br />
net.ipv4.tcp_window_scaling = 1<br />
net.ipv4.tcp_rmem = 4096 &nbsp; &nbsp; &nbsp; &nbsp;87380 &nbsp; 4194304<br />
net.ipv4.tcp_wmem = 4096 &nbsp; &nbsp; &nbsp; &nbsp;16384 &nbsp; 4194304<br />
net.core.wmem_default = 8388608<br />
net.core.rmem_default = 8388608<br />
net.core.rmem_max = 16777216<br />
net.core.wmem_max = 16777216<br />
net.core.netdev_max_backlog = 262144<br />
net.core.somaxconn = 262144<br />
net.ipv4.tcp_max_orphans = 3276800<br />
net.ipv4.tcp_max_syn_backlog = 262144<br />
net.ipv4.tcp_timestamps = 0<br />
net.ipv4.tcp_synack_retries = 1<br />
net.ipv4.tcp_syn_retries = 1<br />
net.ipv4.tcp_tw_recycle = 1<br />
net.ipv4.tcp_tw_reuse = 1<br />
net.ipv4.tcp_mem = 94500000 915000000 927000000<br />
net.ipv4.tcp_fin_timeout = 1<br />
net.ipv4.tcp_keepalive_time = 30<br />
net.ipv4.ip_local_port_range = 1024 &nbsp; &nbsp;65000<br />
外加,把线程加大到24个线程,然后</p>

<p>worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;</p>

<hr />原文地址:http://www.oschina.net/question/1465961_146523?sort=default&amp;p=2#answers
页: [1]
查看完整版本: nginx io瓶颈问题