Comments (22)
I made a test with using SQLAlchemy querying which is sync and asyncpg
It seems that sync db connector crashes when too many connection make at same time
boom -c 100 -n 1000 <url>
SQLAlchemy sync querying
asyncpg querying
boom -c 1000 -n 1000 <url>
SQLAlchemy sync querying
asyncpg querying
from sanic.
I have a repo up that could be used for a simple SQLAlchemy, Alembic & Class based views setup.
from sanic.
Might be worth considering https://github.com/MagicStack/asyncpg too. Supposedly a lot faster than aiopg.
from sanic.
I've tried sanic with sqlalchemy along with asyncpg. Both blueprint(master branch) and class based views are implemented. Hope someone can have me a better implementation
repo here
from sanic.
Should the example be updated instead so it doesn't pass an event loop to sanic?
from sanic.
Thank you so much for all your work!! Any possibility of a demo for asyncpg integration?
from sanic.
Awesome I'll make a PR to add a link to this from either the README or a separate documentation link.
from sanic.
@easydaniel Looks good, have you done some tests on performance using SQLAlchemy async vs sync?
from sanic.
@easydaniel Thanks for uploading that!
from sanic.
Should this be closed since we have a sqlalchemy example now?
https://github.com/channelcat/sanic/blob/master/examples/sanic_aiopg_sqlalchemy_example.py
from sanic.
However there is some discussion going on about whether there is a better way, since that recreates the connection for each request.
from sanic.
@easydaniel I notice the asyncpg querying api is /api/auth which the response status code is 404?
that means this test does not hit the database?
from sanic.
@saggit I wonder if your database is reachable or not cuz as you can see my blueprint doesn't do any other thing except querying, I suppose the result is database issue.
from sanic.
https://github.com/channelcat/sanic/blob/da924a359c849c2b2c90da31f9ce5abc9947d783/examples/sanic_aiopg_sqlalchemy_example.py is nice but I too wonder about the implications of having to create a connection on each request handler. Wouldn't be a problem if you use pgbouncer.
Would be awesome if you can have a global connection object with the ability to re-connect.
from sanic.
Another way to do it is to use https://github.com/CanopyTax/asyncpgsa/wiki/Examples and connection pooling. You create the pool using a before_server_start Blueprint (and close it during after_server_stop). Then in a request you acquire a connection from the pool.
from sanic.
@danpozmanter we have a local pool (pgbouncer). how would the sanic example work in this case ? im fairly concerned about having two pools (having seen it blow up in my face in the past)
from sanic.
@sandys That's a damn good question. I'm not sure? My hunch is that in that case you'd want to just grab a connection and let the pooling happen outside of the app?
from sanic.
@danpozmanter with SQLAlchemy, I use NullPool which is specifically designed for this. Not sure what it does. But this is the official way to use with external pooler. PGBouncer is a heavy duty production ready system, so it would not be nice to not use it.
I think you guys will need to build some abstraction around it - especially because of all these async semantics.
P.S. you guys are doing incredible work. Sanic is what we are looking to upgrade to from Flask in my startup versus golang.
from sanic.
@sandys Oh I haven't contributed to Sanic!! Agreed the people behind Sanic are doing incredible work. I've just made a framework that rests on Sanic.
from sanic.
Asyncpgsa is an important part of what we are hopeful about ;)
from sanic.
I believe this should be closed; have example currently. Will be included in wiki once its opened up.
https://github.com/stopspazzing/sanic/wiki/Examples#aiopg--sqlalchemy
from sanic.
Should have been closed a long time ago...
from sanic.
Related Issues (20)
- CLI: Terminal becomes no-echo if not entering REPL mode or exiting without Ctrl+D HOT 3
- Trusted proxies HOT 2
- Sanic stops working after trying to open a WS connection HOT 1
- How can I use the Response streaming technique in a POST method? HOT 2
- Shutdown never finishes when background tasks are cancelled but need some time to finish
- EOFError in Server Manager HOT 2
- Start-up exception HOT 1
- openapi json exception
- The RESTful API has redundant path parameters HOT 1
- Response streaming produces [ERROR] Invalid response type None (need HTTPResponse)
- Unexpected behavior with bp.middleware() using classes HOT 2
- δΈδΈͺζ±ε© HOT 1
- "body not consumed" error on GET request with content-length=0 HOT 1
- mypy error type for async get function in HTTPMethodView HOT 2
- Unexpected behaviour with REQUEST_MAX_HEADER_SIZE HOT 1
- Unexpected behavior when using blueprint groups and app.url_for HOT 1
- How to avoid abort when the code throw an Exception HOT 1
- Sanic drops part of HTTP response data HOT 7
- REQUEST_TIMEOUT & RESPONSE_TIMEOUT not working
- Documentation Hidden by Menu HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanic.