Welcome! Log In Create A New Profile

Advanced

Высокий IO на серверах с nginx

Alexey Malov
July 11, 2015 06:10PM
Добрый день,
Второй день наблюдаю проблему с высоким IO на серверах с nginx при не очень
большой нагрузке.
Схема такая - 11 серверов с nginx и tomcat. Nginx на каждому сервере
принимает трафик от CloudFlare CDN, большую часть отдаёт из кеша, остальное
балансирует на томкаты (и ещё один статический файлик отдаёт сам).
Всё было замечательно до вчера, трафик в пике был до 40 мегабайтов в
секунду, 40к параллельных соединений и ~1500 запросов в секунду на каждом
из серверов.
Вчера же трафик подскочил раза в полтора (сбрасывали кеш на CloudFlare и
сами запросы тоже поменялись), резко выроз IO на сервере (раньше его вообще
практически не было, а стало около 15-20%) и всё начало тупить.
Изначально думали на диск, но отключение логов практически никак не
повлияло.
В dmesg стали вылезать сообщения про synflood, увеличили бэклоги как в
nginx, так и в sysctl, сообщения про synflood пропали, но проблема с IO
осталась.

Немного помогло отключение лоад-балансинга в nginx, теперь каждый nginx
проксирует на локальный томкат. Нагрузка на сеть понизилась, IO понизилось,
но всё равно осталось.

Трафик с тех пор понизился даже ниже, чем был до проблемы, сейчас около
1100 запросов в секунду. Но IO осталось. Nginx даже иногда по нескольку
секунд отвечает на запросы к странице stub_status.
Пробовали разделять сервера с tomcat и nginx, IO оставалось на стороне
nginx.

Был бы очень признателен, если бы кто-нибудь подсказал хотя бы куда копать.
Потому что уже вроде как чем только не пробовали. Спасибо заранее!

Конфиги следующие:
nginx.conf:
user nginx;
worker_processes 8;
worker_rlimit_nofile 512000;
worker_rlimit_core 500M;

error_log /var/log/nginx/error.log;

pid /var/run/nginx.pid;

events {
worker_connections 256000;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
log_format main '$remote_addr - $remote_user [$time_local] "$request"
'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format upstream_balancing '$remote_addr - $remote_user
[$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$upstream_addr" "$upstream_response_time"
"$geoip_country_code/$http_cf_ipcountry" "$http_host"
"$upstream_cache_status" '
'"$http_cf_connecting_ip"';
log_format ub_cloudflare '$http_cf_connecting_ip - $remote_user
[$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$upstream_addr" "$upstream_response_time"
"$geoip_country_code/$http_cf_ipcountry" "$http_host"
"$upstream_cache_status" '
'"$remote_addr" "$cookie___cfduid" "$cookie_uid"';
access_log /var/log/nginx/access.log main;

sendfile on;

keepalive_timeout 65;

proxy_cache_methods GET;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

}

virtual host:
server {
listen 1.1.1.1:80;
listen 1.1.1.1:443 ssl;
ssl_certificate /etc/nginx/ssl/cert.crt;
ssl_certificate_key /etc/nginx/ssl/key.key;
server_name example.com;
proxy_set_header clientCountryCode $http_cf_ipcountry ;
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
proxy_next_upstream error timeout http_500;

location / {
deny all;
}
location /manager {
proxy_pass http://127.0.0.1:5885;
}
location /crossdomain.xml {
root /tomcat/static_xml;
expires 31d;
}
location ~ ^(/display.htm)$ {
proxy_pass http://127.0.0.1:5885/banners/$1$is_args$args;
proxy_cache exe_cache;
proxy_cache_valid 2h;

expires 24h;
}
location ~ ^(/secure.jsp)$ {
proxy_pass http://127.0.0.1:5885/banners/mojo/$1$is_args$args;
proxy_cache exe_cache;
proxy_cache_valid 2h;
expires 12h;

}
location ~ ^(/hela.jsp)$ {
proxy_pass http://127.0.0.1:5885/banners/hela$1$is_args$args;
proxy_cache exe_cache;
proxy_cache_valid 2h;
expires 12h;

}
location ~ ^(/hela.exe)$ {
proxy_pass http://127.0.0.1:5885/banners/hela$1$is_args$args;
proxy_cache exe_cache;
proxy_cache_valid 24h;

}
location /wl/ba.jsp {
proxy_pass http://127.0.0.1:5885/banners/wl/ba.jsp;
#proxy_cache_key proxy_cache_key;
proxy_cache exe_cache;
proxy_cache_valid 200 48h;
expires 1w;
}
location /wl/po.jsp {
proxy_pass http://127.0.0.1:5885/banners/wl/po.jsp;
proxy_cache exe_cache;
proxy_cache_valid 200 48h;
expires 1w;
}
location /tg.jsp {
proxy_pass http://127.0.0.1:5885/banners/ba/tg.jsp;
#proxy_cache_key proxy_cache_key;
proxy_cache_key
$http_host$scheme$proxy_host$uri$is_args$arg_ger$arg_cst$arg__v$arg_t;
proxy_cache exe_cache;
proxy_cache_valid 200 48h;
proxy_ignore_headers "Set-Cookie";
add_header Cache-Control public;
expires 36h;
}
location ~ ^/_(a|b|c|d|e|f|m|x|i|h)\.jsp$ {
proxy_pass http://127.0.0.1:5885/banners/ba/_$1.jsp$is_args$args;
proxy_cache_key
$http_host$scheme$proxy_host$uri$is_args$arg_tc$arg_t$arg_callback;
proxy_cache exe_cache;
proxy_cache_valid 200 8h;
proxy_ignore_headers "Set-Cookie";
expires 8h;
deny all;
}
location /api/v1/stabucket {
proxy_pass
http://127.0.0.1:5885/adsnetto_backend/api/v1/stabucket$is_args$args;
proxy_cache_key
$http_host$scheme$proxy_host$uri$is_args$arg_tc$arg_t$arg_callback$arg_r;
proxy_cache exe_cache;
proxy_cache_valid 200 8h;
proxy_ignore_headers "Set-Cookie";
expires 8h;
}
location /_.jsp {
proxy_pass http://127.0.0.1:5885/banners/ba/_.jsp;
proxy_cache_key
$http_host$scheme$proxy_host$uri$is_args$arg_tc$arg_t$arg_callback;
proxy_cache exe_cache;
proxy_cache_valid 200 12h;
proxy_ignore_headers "Set-Cookie";
expires 12h;
}
location /tag_test.jsp {
proxy_pass http://127.0.0.1:5885/banners/ba/tag_test.jsp;
expires 36h;
}
location /clk.action {
proxy_pass http://search.utop.it;
proxy_set_header Host search.utop.it;
}
location /exe {
proxy_pass http://127.0.0.1:5885/banners/exe;
proxy_cache exe_cache;
proxy_cache_valid 200 24h;
}
location /ini.jsp {
proxy_pass http://127.0.0.1:5885/banners/loca/ini.jsp;
proxy_cache exe_cache;
proxy_cache_valid 4h;
expires 12h;
}
location /img/px.png {
alias /tomcat/webapps/banners##1.3/img/px.png;
userid on;
userid_name uid;
userid_domain "example.com; HttpOnly";
userid_expires max;
expires epoch;
}
access_log /var/log/nginx/example.com_access.log ub_cloudflare
buffer=10m flush=1m;
error_log /var/log/nginx/example.com_error.log error;
}

nginx -V:
# nginx -V
nginx version: nginx/1.6.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
TLS SNI support enabled
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'

В sysctl подкручивали:
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.core.netdev_max_backlog = 65536
net.ipv4.tcp_max_syn_backlog = 262144
net.core.somaxconn = 262144
net.core.rmem_max = 8388608
net.core.wmem_max = 8388608
net.core.rmem_default = 65536
net.core.wmem_default = 65536
net.ipv4.tcp_rmem = 8192 873800 8388608
net.ipv4.tcp_wmem = 4096 655360 8388608
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries=2

Картина в netstat:
# netstat -ant | grep tcp | tr -s ' ' ' ' | awk '{print $6}' | sort | uniq
-c
8 CLOSE_WAIT
32970 ESTABLISHED
22 FIN_WAIT1
3 LAST_ACK
17 LISTEN
23 SYN_RECV
27976 TIME_WAIT

--
Alexey Malov
_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

Высокий IO на серверах с nginx

Alexey Malov July 11, 2015 06:10PM

Re: Высокий IO на серверах с nginx

Alexey Malov July 11, 2015 06:58PM

Re: Высокий IO на серверах с nginx

Alexey Malov July 11, 2015 07:54PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 121
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready