Welcome! Log In Create A New Profile

Advanced

nginx does not send response in time

Posted by liangrubo 
nginx does not send response in time
August 22, 2012 05:12AM
Hi folks, I have nginx reverse proxy to an uwsgi(on the same server). I got slow response from computer in the same LAN sometimes. Here is the information on one typical request I got from uwsgi and nginx log:
time for handling the request logged by uwsgi: 0.1622s
time logged in nginx access log: 0.421s
time seen from the client(time wget ....): 2.1s

tcpdump(on the server) tells nginx sends response to client almost 2 seconds after it gets the request.

why does nginx not send reponse in time? the server has some traffic (about 1200 requests per second) but has a lot of cpu, memory and IO resources.

your help is appreciated.



Edited 4 time(s). Last edit at 08/22/2012 05:16AM by liangrubo.
Re: nginx does not send response in time
August 22, 2012 09:06AM
Try shutting the logging of nginx. It would reduce the disk write load. Also check any other thing doing disk activity. Something like Java Messaging Service or logger.
Re: nginx does not send response in time
August 22, 2012 09:47AM
Thanks for your reply. It shouldn't caused by disk write load. tcpdump gives more information:

uwsgi actively close the tcp connection with nginx after sending the response, but the close takes too long to finish: uwsgi send FIN packet to nginx, nginx respond with ACK packet, but nginx sometimes sends its FIN packet long(about 1 second) after it sends the previous ACK packet (ACK for uwsgi FIN), nginx seems only send response to client after its connection with uwsgi cleanly closed.

What can cause this to happen?
Re: nginx does not send response in time
August 22, 2012 10:40AM
after more experiments, it seems nginx is experiencing some kind of tcp bottleneck, it sometimes try to connect(send SYN packet) to uwsgi after a long delay(about 1 second after it got response from the client).

I also tried to start another nginx instance on the same server, which didn't have other traffic except for my tests, this nginx instance worked without any problem. Only the nginx instance with high traffic has the problem.

I may need to tweak some tcp parameters for nginx or for the kernel, any advice?



Edited 2 time(s). Last edit at 08/22/2012 10:50AM by liangrubo.
Re: nginx does not send response in time
August 22, 2012 10:52AM
liangrubo Wrote:
-------------------------------------------------------
> after a long delay(about 1 second after it got response from the client
--- typo, "response" should be "request"



Edited 1 time(s). Last edit at 08/22/2012 10:53AM by liangrubo.
Re: nginx does not send response in time
August 27, 2012 05:48PM
I'm experiencing something similar with nginx proxying using proxy_pass. Your situation might have to do with kernal tuning params. You might want to use these params before your perform your next test. Thanks.

echo “10152 65535″ > /proc/sys/net/ipv4/ip_local_port_range
sysctl -w fs.file-max=128000
sysctl -w net.ipv4.tcp_keepalive_time=300
sysctl -w net.core.somaxconn=250000
sysctl -w net.ipv4.tcp_max_syn_backlog=2500
sysctl -w net.core.netdev_max_backlog=2500
ulimit -n 10240
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 278
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