Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how many uvicorn workers do I have to have in production?

My Environment

  • FastAPI
  • Gunicorn & Uvicorn Worker
  • AWS EC2 c5.2xlarge (8 vCPU)

Document

https://fastapi.tiangolo.com/deployment/server-workers/

Question

Currently I'm using 24 Uvicorn workers in production server. (c5.2xlarge)

gunicorn main:app --workers 24 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:80

I've learn that one process runs on one core. Therefore If i have 8 processes, I can make use of whole cores (c5.2xlarge's vCpu == 8)

I'm curious that in this situation, Is there any performance benefit if I got more processes than 8?

like image 842
Jerry Avatar asked Dec 03 '25 15:12

Jerry


1 Answers

Number of recommended workers is 2 x number_of_cores +1

You can more about it in the official documentation.

In your case with 8 CPU cores, you should be using 17 worker threads.

Additional thoughts on async systems:

The two times core is not a scientific figure as says in the article. But the idea is that one thread can do I/O and another CPU processing at the same time. This makes maximum use of simultaneous threads. Even with async systems, conceptually this works and should give you maximum efficiency.

like image 128
John S John Avatar answered Dec 05 '25 12:12

John S John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!