Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

[aiohttp] Use SQLAlchemy directly (rather than aiopg) - #6248

Merged
NateBrady23 merged 7 commits into
TechEmpower:masterfrom
Dreamsorcerer:sqlalchemy
Jan 8, 2021
Merged

NateBrady23 merged 7 commits into
TechEmpower:masterfrom
Dreamsorcerer:sqlalchemy

Conversation

@Dreamsorcerer

@Dreamsorcerer Dreamsorcerer commented Dec 29, 2020 •

Copy link
Copy Markdown
Contributor

One more update. This replaces aiopg with modern sqlalchemy. Because we are using asyncio this requires 1.4+.
This should obviously become the standard approach as 1.4 matures. It's also changed the API usage to actually use ORM, the previous code is only Core.

I've also marked with TODOs very minor improvements that can be made once another beta release is made available.

@samuelcolvin

min_size = max(int(max_size / 2), 1)
print(f'connection pool: min size: {min_size}, max size: {max_size}, orm: {CONNECTION_ORM}')
if CONNECTION_ORM:
app['pg'] = await aiopg.sa.create_engine(dsn=dsn, minsize=min_size, maxsize=max_size, loop=app.loop)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how these min/max size values translate into sqlalchemy directly..

@NateBrady23

Copy link
Copy Markdown
Member

Closing and re-opening for new CI

@NateBrady23 NateBrady23 closed this Jan 8, 2021
@NateBrady23 NateBrady23 reopened this Jan 8, 2021
@NateBrady23

Copy link
Copy Markdown
Member

Looks like a lot of errors here for the default test

@Dreamsorcerer

Copy link
Copy Markdown
Contributor Author

Thanks, I'll take a look. I tested the web app itself, but struggled to get the tests working locally.

@Dreamsorcerer

Copy link
Copy Markdown
Contributor Author

OK, that's the tests fixed.

I can try and play with the pool size thing, but I don't see any pool being used in (for example) the Flask code, so I'm not sure it's a fair comparison if we use a pool and other tests don't..

@NateBrady23

Copy link
Copy Markdown
Member

@Dreamsorcerer I'll merge this in but feel free to work on that. If it improves performance here, the goal would be for the other frameworks to also implement the same strategy and lift the group up as a whole.

@NateBrady23
NateBrady23 merged commit fe99c80 into TechEmpower:master Jan 8, 2021
@samuelcolvin

Copy link
Copy Markdown
Contributor

This looks great, thank you @Dreamsorcerer. Sorry not to reply earlier.

Do we have any provisional or indicative results for this? Or feeling about how it will perform relative to aiopg?

@Dreamsorcerer

Copy link
Copy Markdown
Contributor Author

Going by some results in the CI tests, it looks pretty similar. The one thing we've lost at the moment is the connection pool params. I've opened a PR to set the max size again, now I have some understanding of what I'm looking at. But, the min_size in aiopg appears to be an option to pre create a number of connections, so the aiopg code appears to be creating 100s of connections before the benchmark is actually run.

I'm not seeing any obvious way to pre create them in sqlalchemy, so we're probably losing a little bit of time as they get created during the benchmark.

andreasrueb pushed a commit to digitallyinduced/IHP-FrameworkBenchmarks that referenced this pull request Apr 13, 2021
* Update aiohttp test.

* Update aiohttp to use async sqlalchemy.

* Update main.py

* Update drivername

* Stop cheating in ORM updates.

* Remove unused import.

Co-authored-by: Sam Bull <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants