我的网站开始加载4-5秒(高峰时间) – 几乎不可用。 stream量:40MB / s输出,6MB / s英寸(几乎95%的下载文件0.5-2GB大)。 超过100个同时连接。 机器工作正常,没有问题,我通过网站非常缓慢地上传,大约50KB / s,通过FTP下载50KB / s,一切正常,并且KB / s的嗡嗡声,所以我认为问题可能会在nginx,php-fpm或mysql的configuration中。 但我实际上不知道如何debugging这个问题。 我已经search并增加了价值,以同时拥有数以千计的客户端,但问题仍然是一样的。
netstat -na |grep :80 |wc -l 250 //if it is something like 150 AND netstat -an | grep 80 | grep ESTA | wc 150 //this is less than 100, then it is okay, otherwise website is loading 3 times longer than usually
nginx.conf:
user www-data; worker_processes 8; pid /var/run/nginx.pid; worker_rlimit_nofile 200000; events { worker_connections 32768; multi_accept on; use epoll; } http { access_log off; limit_conn_zone $binary_remote_addr zone=conn:10m; #limit_req_zone $binary_remote_addr zone=req:10m rate=250r/s; #limit_req zone=req burst=20 nodelay; upload_progress uploads 5m; upload_progress_json_output; sendfile on; send_timeout 60s; tcp_nopush on; tcp_nodelay on; keepalive_timeout 20; client_max_body_size 10G; client_body_buffer_size 256k; types_hash_max_size 2048; server_tokens off; proxy_buffer_size 128k; proxy_buffers 4 256k; proxy_busy_buffers_size 256k; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; #access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log crit; gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
mysite的-virtual.conf
location ~ \.php$ { #limit_req zone=req; fastcgi_buffer_size 128k; fastcgi_busy_buffers_size 256k; fastcgi_buffers 256 16k; fastcgi_pass 127.0.0.1:9000; fastcgi_temp_file_write_size 256k; include fastcgi_params; }
/etc/php5/fpm/pool.d/www.conf
pm = dynamic pm.max_children = 50 pm.start_servers = 25 pm.min_spare_servers = 25 pm.max_spare_servers = 50
Sysctl Tunning
net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_rmem = 4096 87380 16777216 net.ipv4.tcp_wmem = 4096 16384 16777216 net.core.somaxconn = 4096 net.core.netdev_max_backlog = 16384 net.ipv4.tcp_max_syn_backlog = 8192 net.ipv4.tcp_syncookies = 1 net.ipv4.ip_local_port_range = 1024 65535 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_congestion_control = cubic
nofile限制
root hard nofile 40000 root soft nofile 40000 www-data hard nofile 40000 www-data soft nofile 40000
Mysql状态 – 中止连接?
Connections ø per hour % max. concurrent connections 25 --- --- Failed attempts 0 0.00 0.00% Aborted 21 4.19 0.08% Total 25 k 5,040.80 100.00%
在网页加载几秒钟的高峰时段,可以在Mytop或Phpmyadmin中监控: Copying to tmp table ,所以我增加了tmp_table_size和max_heap_table_size
请给我一些build议,瓶颈在哪里,因为我迷路了。 这是我在这个configuration中的第一台服务器,也许我可以忘记调整一些东西。
Nginx 1.2.1,php5-fpm
Debian 7.1 Wheezy
2x L5420 @ 2.50GHz
8GB内存
解决了! 一切都在MySQL(查询问题 – 缺乏索引(查询速度慢20倍)。
更新:
必须在Linux中调整预读以提高吞吐量。 从256(默认)到16384。
blockdev --setra 16384 /dev/sda
在这个操作之后,读取速度从40MBps增加到260MBps,并且我在MRTG中监测到stream量增加了近两倍。 所以请求的stream量(之前)不能由硬盘服务,这是IO瓶颈,网站加载了几秒钟!