Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Nginx have separate queuing mechanism for requests?

Tags:

linux

nginx

epoll

Consider the following situation: you are deploying application that can serve 1 req./sec. What would happen if I send 10 request in 1 second? I wrote simple app to test that: https://github.com/amezhenin/nginx_slow_upstream . This test shows that your requests will be served _in_exact_same_order_ they were sent.

For now, this looks like Nginx have some kind of queue for requests, but my colleague(administrator) sayd that there is no any queues in Nginx. So I wrote another question about epoll here: Does epoll preserve the order in which fd's was registered? . From that discussion I figured that epoll does preserves the order of requests.

I have two questions:

1) Is there any mistakes in reasoning/code above?

2) Does Nginx have some sort of queue for requests on top of epoll? Or Nginx uses pure epoll functionality?

Thank you, and sorry for my English :)

like image 262
Artem Mezhenin Avatar asked Oct 02 '13 14:10

Artem Mezhenin


People also ask

Does nginx queue request?

queue (NGINX Plus) – Creates a queue in which requests are placed when all the available servers in the upstream group have reached their max_conns limit. This directive sets the maximum number of requests in the queue and, optionally, the maximum time they wait (60 seconds by default) before an error is returned.

How does nginx process requests?

In this configuration, nginx first tests the IP address and port of the request against the listen directives of the server blocks. It then tests the “Host” header field of the request against the server_name entries of the server blocks that matched the IP address and port.

How many requests nginx can handle?

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

How do I queue HTTP requests?

Queuing HTTP requests provides time for new connections to become available on the server, without performing the configured pool down action. HTTP request queuing is disabled by default. The feature can be enabled on a per pool basis. The default queue length is 128 requests (when the feature is enabled).


1 Answers

Nginx doesn't have it own queue, instead it pushes all requests to the application server, which have a listen socket:

#include <sys/types.h>
#include <sys/socket.h>

int listen(int sockfd, int backlog);

(http://linux.die.net/man/2/listen)

backlog defines the length of this queue. You can read the full conversation here.

like image 164
Artem Mezhenin Avatar answered Oct 16 '22 20:10

Artem Mezhenin