最近发现当upstream后端服务故障后,nginx的cpu占用就会飙升,后端服务故障的数量越多,cpu飙升就会越高。当后端有超过接近10台服务故障时,8个进程的nginx,有之前平均每个进程5-10%的cpu占用,直接飙升到99-100%,当注释掉故障后端服务后,cpu占用马上就正常了。 配置大致如下:
upstream https_backend {
consistent_hash $real_uri;
server 172.29.184.4:40443 weight=100;
server 172.29.184.5:40443 weight=100;
...serverlist...
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_keepalive_requests 100;
check_http_send "HEAD /xxxx.jpg HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";
check_http_expect_alive http_2xx http_3xx http_4xx;
}