<div dir="ltr">Как выяснилось, IO было дисковое, перенос cache в RAM всё излечил. Странно только, почему раньше работало. Сейчас вариантов URL стало даже меньше. И трафик опустился.</div><div class="gmail_extra"><br><div class="gmail_quote">11 июля 2015 г., 17:57 пользователь Alexey Malov <span dir="ltr"><<a href="mailto:scukonick@gmail.com" target="_blank">scukonick@gmail.com</a>></span> написал:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">11 июля 2015 г., 17:09 пользователь Alexey Malov <span dir="ltr"><<a href="mailto:scukonick@gmail.com" target="_blank">scukonick@gmail.com</a>></span> написал:<div><div class="h5"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Добрый день,<br>Второй день наблюдаю проблему с высоким IO на серверах с nginx при не очень большой нагрузке.<br>Схема такая - 11 серверов с nginx и tomcat. Nginx на каждому сервере принимает трафик от CloudFlare CDN, большую часть отдаёт из кеша, остальное балансирует на томкаты (и ещё один статический файлик отдаёт сам).<br>Всё было замечательно до вчера, трафик в пике был до 40 мегабайтов в секунду, 40к параллельных соединений и ~1500 запросов в секунду на каждом из серверов.<br>Вчера же трафик подскочил раза в полтора (сбрасывали кеш на CloudFlare и сами запросы тоже поменялись), резко выроз IO на сервере (раньше его вообще практически не было, а стало около 15-20%) и всё начало тупить.<br>Изначально думали на диск, но отключение логов практически никак не повлияло.<br>В dmesg стали вылезать сообщения про synflood, увеличили бэклоги как в nginx, так и в sysctl, сообщения про synflood пропали, но проблема с IO осталась. <br><br>Немного помогло отключение лоад-балансинга в nginx, теперь каждый nginx проксирует на локальный томкат. Нагрузка на сеть понизилась, IO понизилось, но всё равно осталось.<br><br>Трафик с тех пор понизился даже ниже, чем был до проблемы, сейчас около 1100 запросов в секунду. Но IO осталось. Nginx даже иногда по нескольку секунд отвечает на запросы к странице stub_status.<br>Пробовали разделять сервера с tomcat и nginx, IO оставалось на стороне nginx.<br><br>Был бы очень признателен, если бы кто-нибудь подсказал хотя бы куда копать. Потому что уже вроде как чем только не пробовали. Спасибо заранее!<br><br>Конфиги следующие:<br>nginx.conf:<br><div>user              nginx;</div><div>worker_processes  8;</div><div>worker_rlimit_nofile 512000;</div><div>worker_rlimit_core  500M;</div><div><br></div><div>error_log  /var/log/nginx/error.log;</div><div><br></div><div>pid        /var/run/nginx.pid;</div><div><br></div><div>events {</div><div>    worker_connections  256000;</div><div>}</div><div><br></div><div>http {</div><div>    include       /etc/nginx/mime.types;</div><div>    default_type  application/octet-stream;</div><div><br></div><div>    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;</div><div>    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '</div><div>                      '$status $body_bytes_sent "$http_referer" '</div><div>                      '"$http_user_agent" "$http_x_forwarded_for"';</div><div>    log_format upstream_balancing   '$remote_addr - $remote_user [$time_local] '</div><div>                    '"$request" $status $bytes_sent '</div><div>                    '"$http_referer" "$http_user_agent" '</div><div>                    '"$upstream_addr" "$upstream_response_time" "$geoip_country_code/$http_cf_ipcountry" "$http_host" "$upstream_cache_status" '</div><div><span style="white-space:pre-wrap">         </span>    '"$http_cf_connecting_ip"';</div><div>    log_format ub_cloudflare   '$http_cf_connecting_ip - $remote_user [$time_local] '</div><div>                    '"$request" $status $bytes_sent '</div><div>                    '"$http_referer" "$http_user_agent" '</div><div>                    '"$upstream_addr" "$upstream_response_time" "$geoip_country_code/$http_cf_ipcountry" "$http_host" "$upstream_cache_status" '</div><div><span style="white-space:pre-wrap">              </span>    '"$remote_addr" "$cookie___cfduid" "$cookie_uid"';</div><div>    access_log  /var/log/nginx/access.log  main;</div><div><br></div><div>    sendfile        on;</div><div><br></div><div>    keepalive_timeout  65;</div><div><br></div><div>    proxy_cache_methods GET;</div><div><br></div><div>    include /etc/nginx/conf.d/*.conf;</div><div>    include /etc/nginx/sites-enabled/*;</div><div><br></div><div>}</div><div><br></div><div>virtual host:<br><div>server {</div><div>    listen       <a href="http://1.1.1.1:80" target="_blank">1.1.1.1:80</a>;</div><div>    listen       <a href="http://1.1.1.1:443" target="_blank">1.1.1.1:443</a> ssl;</div><div>    ssl_certificate /etc/nginx/ssl/cert.crt;</div><div>    ssl_certificate_key /etc/nginx/ssl/key.key;</div><div>    server_name  <a href="http://example.com" target="_blank">example.com</a>;</div><div>    proxy_set_header clientCountryCode $http_cf_ipcountry ;</div><div>    proxy_ignore_headers "Set-Cookie";</div><div>    proxy_hide_header "Set-Cookie";</div><div>    proxy_next_upstream error timeout http_500;</div><div><br></div><div>    location / {</div><div>        deny all;</div><div>    }</div><div>    location /manager {</div><div>        proxy_pass <a href="http://127.0.0.1:5885" target="_blank">http://127.0.0.1:5885</a>;</div><div>    }</div><div>    location /crossdomain.xml {</div><div>        root /tomcat/static_xml;</div><div>        expires 31d;</div><div>    }</div><div>    location ~ ^(/display.htm)$ {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/$1$is_args$args" target="_blank">http://127.0.0.1:5885/banners/$1$is_args$args</a>;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 2h;</div><div><br></div><div>        expires 24h;</div><div>    }</div><div>    location ~ ^(/secure.jsp)$ {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/mojo/$1$is_args$args" target="_blank">http://127.0.0.1:5885/banners/mojo/$1$is_args$args</a>;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 2h;</div><div>        expires 12h;</div><div><br></div><div>    }</div><div>    location ~ ^(/hela.jsp)$ {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/hela$1$is_args$args" target="_blank">http://127.0.0.1:5885/banners/hela$1$is_args$args</a>;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 2h;</div><div>        expires 12h;</div><div><br></div><div>    }</div><div>    location ~ ^(/hela.exe)$ {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/hela$1$is_args$args" target="_blank">http://127.0.0.1:5885/banners/hela$1$is_args$args</a>;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 24h;</div><div><br></div><div>    }</div><div>    location /wl/ba.jsp {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/wl/ba.jsp" target="_blank">http://127.0.0.1:5885/banners/wl/ba.jsp</a>;</div><div>        #proxy_cache_key proxy_cache_key;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 200 48h;</div><div>        expires 1w;</div><div>    }</div><div>    location /wl/po.jsp {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/wl/po.jsp" target="_blank">http://127.0.0.1:5885/banners/wl/po.jsp</a>;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 200 48h;</div><div>        expires 1w;</div><div>    }</div><div>    location /tg.jsp {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/ba/tg.jsp" target="_blank">http://127.0.0.1:5885/banners/ba/tg.jsp</a>;</div><div>        #proxy_cache_key proxy_cache_key;</div><div>        proxy_cache_key $http_host$scheme$proxy_host$uri$is_args$arg_ger$arg_cst$arg__v$arg_t;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 200 48h;</div><div>        proxy_ignore_headers "Set-Cookie";</div><div>        add_header Cache-Control public;</div><div>        expires 36h;</div><div>    }</div><div>    location ~ ^/_(a|b|c|d|e|f|m|x|i|h)\.jsp$ {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/ba/_$1.jsp$is_args$args" target="_blank">http://127.0.0.1:5885/banners/ba/_$1.jsp$is_args$args</a>;</div><div>        proxy_cache_key $http_host$scheme$proxy_host$uri$is_args$arg_tc$arg_t$arg_callback;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 200 8h;</div><div>        proxy_ignore_headers "Set-Cookie";</div><div>        expires 8h;</div><div>        deny all;</div><div>    }</div><div>    location /api/v1/stabucket {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/adsnetto_backend/api/v1/stabucket$is_args$args" target="_blank">http://127.0.0.1:5885/adsnetto_backend/api/v1/stabucket$is_args$args</a>;</div><div>        proxy_cache_key $http_host$scheme$proxy_host$uri$is_args$arg_tc$arg_t$arg_callback$arg_r;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 200 8h;</div><div>        proxy_ignore_headers "Set-Cookie";</div><div>        expires 8h;</div><div>    }</div><div>    location /_.jsp {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/ba/_.jsp" target="_blank">http://127.0.0.1:5885/banners/ba/_.jsp</a>;</div><div>        proxy_cache_key $http_host$scheme$proxy_host$uri$is_args$arg_tc$arg_t$arg_callback;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 200 12h;</div><div>        proxy_ignore_headers "Set-Cookie";</div><div>        expires 12h;</div><div>    }</div><div>    location /tag_test.jsp {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/ba/tag_test.jsp" target="_blank">http://127.0.0.1:5885/banners/ba/tag_test.jsp</a>;</div><div>        expires 36h;</div><div>    }</div><div>    location /clk.action {</div><div>        proxy_pass <a href="http://search.utop.it" target="_blank">http://search.utop.it</a>;</div><div>        proxy_set_header Host <a href="http://search.utop.it" target="_blank">search.utop.it</a>;</div><div>    }</div><div>    location /exe {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/exe" target="_blank">http://127.0.0.1:5885/banners/exe</a>; </div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 200 24h;</div><div>    }</div><div>    location /ini.jsp {</div><div>        proxy_pass <a href="http://127.0.0.1:5885/banners/loca/ini.jsp" target="_blank">http://127.0.0.1:5885/banners/loca/ini.jsp</a>;</div><div>        proxy_cache exe_cache;</div><div>        proxy_cache_valid 4h;</div><div>        expires 12h;</div><div>    }</div><div>    location /img/px.png {</div><div>        alias /tomcat/webapps/banners##1.3/img/px.png;</div><div>        userid         on;</div><div>        userid_name    uid;</div><div>        userid_domain "<a href="http://example.com" target="_blank">example.com</a>; HttpOnly";</div><div>        userid_expires max;</div><div>        expires epoch;</div><div>    }</div><div>    access_log /var/log/nginx/example.com_access.log ub_cloudflare buffer=10m flush=1m;</div><div>    error_log /var/log/nginx/example.com_error.log error;</div><div>}</div></div><div><br></div><div>nginx -V:<br><div># nginx -V</div><div>nginx version: nginx/1.6.2</div><div>built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) </div><div>TLS SNI support enabled</div><div>configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'</div></div><div><br>В sysctl подкручивали:<br><div>net.ipv4.tcp_fin_timeout = 15</div><div>net.ipv4.tcp_tw_reuse = 1</div><div>net.ipv4.tcp_tw_recycle = 0</div><div>net.core.netdev_max_backlog = 65536</div><div>net.ipv4.tcp_max_syn_backlog = 262144</div><div>net.core.somaxconn = 262144</div><div>net.core.rmem_max = 8388608</div><div>net.core.wmem_max = 8388608</div><div>net.core.rmem_default = 65536</div><div>net.core.wmem_default = 65536</div><div>net.ipv4.tcp_rmem = 8192 873800 8388608</div><div>net.ipv4.tcp_wmem = 4096 655360 8388608</div><div>net.ipv4.tcp_synack_retries = 2</div><div>net.ipv4.tcp_syn_retries=2</div></div><div><br>Картина в netstat:<br><div># netstat -ant | grep tcp | tr -s ' ' ' ' | awk '{print $6}' | sort | uniq -c</div><div>      8 CLOSE_WAIT</div><div>  32970 ESTABLISHED</div><div>     22 FIN_WAIT1</div><div>      3 LAST_ACK</div><div>     17 LISTEN</div><div>     23 SYN_RECV</div><div>  27976 TIME_WAIT</div></div><span><font color="#888888"><div><br></div>-- <br><div>Alexey Malov</div>
</font></span></div>
</blockquote></div></div></div><br>Забыл уточнить, сервера примерно такой конфигурации:<br>Intel(R) Xeon(R) CPU E5-1620 v2 (8 core)<br>64GB RAM<br><br>Tomcat нагрузку почти не создает, до него доходит в лучшем случае запросов 10-15 в секунду.<span class="HOEnZb"><font color="#888888"><br clear="all"><div><br></div>-- <br><div>Alexey Malov</div>
</font></span></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Alexey Malov</div>
</div>