Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between workers and worker_connections in gunicorn?

Reading Gunicorn's docs I see two parameters, worker being the value of WEB_CONCURRENCY and worker_connections being the number of simultaneous clients.

Wouldn't the number of workers be the same as the number of clients it can handle at the same time? [assuming worker class as gevent].

It seems to be pretty clear that I'm wrong in my assumption, could someone please explain what the difference is between them?

like image 685
Projjol Avatar asked Jun 24 '17 09:06

Projjol


People also ask

What is workers in gunicorn?

Gunicorn is based on the pre-fork worker model. This means that there is a central master process that manages a set of worker processes. The master never knows anything about individual clients. All requests and responses are handled completely by worker processes.

How many requests can a gunicorn worker handle?

If each request takes exactly 1 millisecond to handle, then a single worker can serve 1000 RPS.

Do gunicorn workers share memory?

Gunicorn also allows for each of the workers to have multiple threads. In this case, the Python application is loaded once per worker, and each of the threads spawned by the same worker shares the same memory space. Gunicorn with threads setting, which uses the gthread worker class.

What is graceful timeout in gunicorn?

After 30 seconds (configurable with timeout ) of request processing, gunicorn master process sends SIGTERM to the worker process, to initiate a graceful restart. If worker does not shutdown during another 30 seconds (configurable with graceful_timeout ), master process sends SIGKILL .


1 Answers

workers — is a number of OS processes for handling requests. By default it is equal to the value of WEB_CONCURRENCY environment variable, and if it is not defined, the default is 1.
worker_connections — is a maximum count of active greenlets grouped in a pool that will be allowed in each process (for "gevent" worker class).

By the way, the documentation recommends:
DO NOT scale the number of workers to the number of clients you expect to have. Gunicorn should only need 4-12 worker processes to handle hundreds or thousands of requests per second.

like image 103
Delimitry Avatar answered Sep 22 '22 15:09

Delimitry