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

Document connection pool best usage and caveats #129

Closed
mpaolini opened this issue Jul 21, 2016 · 5 comments
Closed

Document connection pool best usage and caveats #129

mpaolini opened this issue Jul 21, 2016 · 5 comments

Comments

@mpaolini
Copy link
Contributor

A wrong usage of connection pool may cause deadlocks. See #113 #127 #128 for reference. Expecially issue 128 comment.

We should document what's the best way of using connection pooling and also give some example of bad usage that leads to deadlocks.

@mpaolini
Copy link
Contributor Author

Also see aio-libs/aiohttp#981

@mpaolini
Copy link
Contributor Author

aiohttp demo polls app has been refactored lately to match the connection pool best practices.
I am doing similar work for aiopg examples too.

Basically it boils down to:

async def index(request): 
     # the view function acquires the connection
    async with request.app['db'].acquire() as conn:
        # the connection is passed down to db utlity functions
        db.do_some_query(conn)

While the approach is sound and simple, I think it may encourage taking the connection out of the pool for longer than needed. I will point it out in the docs.

@asvetlov
Copy link
Member

Good

@mpaolini
Copy link
Contributor Author

Proposed patch is in #133

@asvetlov
Copy link
Member

Fixed by #133

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