三台服务器 : 1测试 1web 1数据库
全内网,相互访问速度10.7m/s
web: nginx + php
mysql : version - 5.6.3-m6-log
测试程序 webbench
问题
------------------------------
webbench 并发超过1000 访问 web上的html静态页(或纯php不带db操作页) ,此时一切正常,在我笔记本上手动刷新html和不带db操作的php页,都很正常。但只要刷新带DB操作的php页面就一直在loading直至timeout could not connect db server出现。此时我去看db sever的负载和mysql的连接数全部很低,甚至mysql的连接数为1,这个1是我在笔记本上用软件连上数据库。
在mysql上使用show processlist 看连接状况。凡是loading中的连接都处于 writing to net | connect | unauthenticated ,一直都是这样直至连接关闭。我想这说明php的连接连mysql没有成功。
以为是php的问题,后来在机器 上放了个cgi的程序来连。。并发到1000 .也是一样。html和纯php页可以打开。一做数据库操作就连不上...
直到我将并发降到700后,才能正常访问带db操作的页面,延迟1~2秒(用 webbench直接并发测带db操作的页面,大约也是700个并发后,我刷新笔记本上的db操作页面也会连接不上db)
我的问题很奇怪。道理说我1000并发html静态的时候php应该可以连得上数据库.可为什么 连不上呢。。
首先三台机器的内核参数均调整过如下(最大打开文件数已经修改过):
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
net.ipv4.tcp_max_syn_backlog = 4096
net.core.netdev_max_backlog = 4096
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 32768 65000
net.ipv4.tcp_keepalive_time = 12000
net.ipv4.tcp_max_tw_buckets = 180000
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_wmem = 8192 436600 873200
net.ipv4.tcp_rmem = 32768 436600 873200
net.ipv4.tcp_mem = 786432 1048576 1572864
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_fin_timeout = 5
web nginx.conf如下
------------------------------------------------------
worker_processes 4;
worker_rlimit_nofile 65536;
worker_cpu_affinity 0001 0010 0100 1000;
events {
use epoll;
worker_connections 51200 ;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-8;
client_max_body_size 1024m;
sendfile on;
keepalive_timeout 60;
gzip on;
server {
listen 80;
server_name localhost;
location / {
root /appdata/web;
index index.html index.php;