[Python] Uvicorn workers greater than one apparently reduce performance by half

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

    My main test app:

    from starlette.applications import Starlette
    from starlette.responses import PlainTextResponse
    from starlette.routing import Route

    async def homepage(request):
    return PlainTextResponse("Hello world!")

    app = Starlette(routes=[Route("/", homepage)])


    Tests using wrk and bombardier:

    uvicorn --host 0.0.0.0 --port 8000 --workers 1 --log-level critical main:app

    wrk -t4 -c100 -d15s http://127.0.0.1:8000
    Running 15s test @ http://127.0.0.1:8000
    4 threads and 100 connections
    Thread Stats Avg Stdev Max +/- Stdev
    Latency 20.97ms 1.97ms 42.51ms 72.49%
    Req/Sec 1.20k 75.01 1.33k 81.00%
    71484 requests in 15.01s, 9.95MB read
    Requests/sec: 4763.71
    Transfer/sec: 679.21KB

    bombardier-linux-amd64 -c 125 -d 15s http://localhost:8000
    Bombarding http://localhost:8000 for 15s using 125 connection(s)
    [====================================================================================================================] 15s
    Done!
    Statistics Avg Stdev Max
    Reqs/sec 3554.25 1317.96 6167.59
    Latency 35.11ms 4.23ms 59.66ms
    HTTP codes:
    1xx - 0, 2xx - 53452, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
    Throughput: 722.57KB/s


    uvicorn --host 0.0.0.0 --port 8000 --workers 2 --log-level critical main:app

    wrk -t4 -c100 -d15s http://127.0.0.1:8000
    Running 15s test @ http://127.0.0.1:8000
    4 threads and 100 connections
    Thread Stats Avg Stdev Max +/- Stdev
    Latency 41.52ms 1.58ms 59.52ms 96.24%
    Req/Sec 603.89 33.36 720.00 73.50%
    36094 requests in 15.02s, 5.04MB read
    Requests/sec: 2403.45
    Transfer/sec: 343.55KB

    bombardier-linux-amd64 -c 125 -d 15s http://localhost:8000
    Bombarding http://localhost:8000 for 15s using 125 connection(s)
    [====================================================================================================================] 15s
    Done!
    Statistics Avg Stdev Max
    Reqs/sec 2905.55 432.64 5376.82
    Latency 42.99ms 2.20ms 74.43ms
    HTTP codes:
    1xx - 0, 2xx - 43671, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
    Throughput: 589.74KB/s


    From now on, increasing the number of workers does not make any difference. The results with ab is different. Increasing the number of workers actually increases the performance. Now my question is why?

    Continue reading...

Compartilhe esta Página