# Uvicorn: How Many Workers to Run in Production

> Calculate Uvicorn workers using Gunicorn's (2 x cores) + 1 formula as a starting point, then tune with load testing since most services need only 4-12 workers

**URL:** https://sentry.io/answers/number-of-uvicorn-workers-needed-in-production/

---

## The Problem

How many Uvicorn workers should I use for a production deployment of a Python web service? How does the number of workers relate to the number of CPU cores I have, and what are the benefits of running additional workers?

## The Solution

The recommended [baseline number of Uvicorn workers](https://gunicorn.org/design/#how-many-workers) follows Gunicorn's `(2 x cores) + 1` formula. Therefore, a 4-core server should be running 9 workers, an 8-core 17 workers, and a 16-core 33 workers, according to the formula below:

```
number of workers = (2 * number of cores) + 1
```

This gives each core one worker to read and write to and from the network socket and another to process requests, since modern CPUs generally use hyperthreading and each core has two threads. Make sure not to confuse the physical number of CPU cores with the system's vCPUs (i.e. its threads) or you may start up too many.

However, the optimal number of workers will depend on the nature of the service and the hardware it's running on, as well as how it is used. Gunicorn's own guidance notes that most services need only 4-12 workers to handle even heavy traffic, so treat the formula above as a starting point rather than a target. A good way to figure out the optimal number of workers for a particular service is to increase and decrease the number of workers while it's operating under load, using the [TTIN and TTOU signals](https://gunicorn.org/design/#signal-communication) and noting the points at which performance is enhanced and degraded.

Starting up too many workers can cause the server to run out of resources, which will slow down all operations.

Note that this guidance applies to both the asynchronous Uvicorn and the synchronous Gunicorn.

---

*Source: [sentry.io/answers/number-of-uvicorn-workers-needed-in-production/](https://sentry.io/answers/number-of-uvicorn-workers-needed-in-production/)*
