Git Product home page Git Product logo

Comments (22)

easydaniel avatar easydaniel commented on April 27, 2024 4

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

2017-01-04 9 21 13

asyncpg querying

2017-01-04 9 21 27

boom -c 1000 -n 1000 <url>

SQLAlchemy sync querying

2017-01-04 9 20 57

asyncpg querying

2017-01-04 9 20 42

from sanic.

seanpar203 avatar seanpar203 commented on April 27, 2024 2

I have a repo up that could be used for a simple SQLAlchemy, Alembic & Class based views setup.

It can be found here

from sanic.

peterbe avatar peterbe commented on April 27, 2024 1

Might be worth considering https://github.com/MagicStack/asyncpg too. Supposedly a lot faster than aiopg.

from sanic.

easydaniel avatar easydaniel commented on April 27, 2024 1

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.

gpip avatar gpip commented on April 27, 2024 1

Should the example be updated instead so it doesn't pass an event loop to sanic?

from sanic.

jackfischer avatar jackfischer commented on April 27, 2024

Thank you so much for all your work!! Any possibility of a demo for asyncpg integration?

from sanic.

seemethere avatar seemethere commented on April 27, 2024

Awesome I'll make a PR to add a link to this from either the README or a separate documentation link.

from sanic.

seanpar203 avatar seanpar203 commented on April 27, 2024

@easydaniel Looks good, have you done some tests on performance using SQLAlchemy async vs sync?

from sanic.

seanpar203 avatar seanpar203 commented on April 27, 2024

@easydaniel Thanks for uploading that!

from sanic.

r0fls avatar r0fls commented on April 27, 2024

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.

r0fls avatar r0fls commented on April 27, 2024

@gpip I've done so here: #335

However there is some discussion going on about whether there is a better way, since that recreates the connection for each request.

from sanic.

saggit avatar saggit commented on April 27, 2024

@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.

easydaniel avatar easydaniel commented on April 27, 2024

@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.

peterbe avatar peterbe commented on April 27, 2024

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.

danpozmanter avatar danpozmanter commented on April 27, 2024

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.

sandys avatar sandys commented on April 27, 2024

@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.

danpozmanter avatar danpozmanter commented on April 27, 2024

@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.

sandys avatar sandys commented on April 27, 2024

@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.

danpozmanter avatar danpozmanter commented on April 27, 2024

@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.

sandys avatar sandys commented on April 27, 2024

Asyncpgsa is an important part of what we are hopeful about ;)

from sanic.

stopspazzing avatar stopspazzing commented on April 27, 2024

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.

seemethere avatar seemethere commented on April 27, 2024

Should have been closed a long time ago...

from sanic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.