Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

leak of amqp connections with gevent #73

Open
horpto opened this issue Jul 4, 2020 · 1 comment
Open

leak of amqp connections with gevent #73

horpto opened this issue Jul 4, 2020 · 1 comment

Comments

@horpto
Copy link

horpto commented Jul 4, 2020

Hello, we use bundle of gunicorn+django+dramatiq+gevent and rabbitmq as message broker. Gunicorn gevent worker class creates new greenlet for each new request. Dramatiq creates an amqp connection first time as it needs to send message. But after request is processed amqp connection remains opened and this connection will be not used again. Of course connection will be closed by rabbit. But it's not good and takes some time and resources. I've solved this issue with django middleware (i can create PR). Maybe is there some better solution ?

import dramatiq

def CloseRabbitConnMiddleware(get_response):

    def middleware(request):
        response = get_response(request)

        broker = dramatiq.get_broker()
        if broker.connections:
            conn = broker.connection
            del broker.connection
            conn.close()

        return response

    return middleware
@mohaiminul-sust
Copy link

@horpto
Can you post an example with implementation? Will adding this middleware to the end of the chain for DRAMATIQ_BROKER -> MIDDLEWARE solve the connection issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants