[Python] Connection error while running locust load testing using Gunicorn for FastAPI

Discussão em 'Python' iniciado por Stack, Abril 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to do load testing using locust for FastAPI application using gunicorn

    below is my load testing code

    from locust import HttpUser, task, between

    file_path = "file_path"

    class QuickstartUser(HttpUser):
    wait_time = between(3, 10)

    @task
    def test_compress(self):
    data = {
    'compress_quality' : 30,
    'compress_threshold' : 20
    }
    files = {
    'input_file': ( 'file.jpg', open(file_path, 'rb'), 'image/jpeg'),

    }
    result = self.client.post("/compress", files=files, data=data)


    i am running my fastapi application with following command

    gunicorn -k uvicorn.workers.UvicornWorker —-threads 16 chdir app main:app -b 0.0.0.0:7113


    when i start load testing after 1 or 2 requests, the requests starts getting Connection Error , while some of them run

    I want to remove this Connection Error

    ConnectionError(ProtocolError('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')))

    ConnectionError(ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')))

    Continue reading...

Compartilhe esta Página