djc / bb8

Full-featured async (tokio-based) postgres connection pool (like r2d2)
MIT License
753 stars 110 forks source link

Example usage with actix and actix-web? #26

Closed chachacha3 closed 5 years ago

chachacha3 commented 5 years ago

Currently I using actix_web + r2d2 and r2d2_postgres. The way I use it: Actix`s SyncArbiter creates 3 separated threads, each thread has it's own r2d2 pool of connections. But r2d2 isn't asynchronous. So going this way I will get bottle neck, if I understands correctly. How can I use bb8 crate with actix-web framework? Would be cool to see some examples. Thank you!

bikeshedder commented 5 years ago

I recently compared l337 with tokio-postgres, bb8 with tokio-postgres and r2d2 with postgres in an actix-web project. I also gave r2d2 with web::block a try after being told multiple times that all the hassle with async connection pooling libraries might not be worth the trouble.

You can view the code in my repository containing the three implementations: https://bitbucket.org/bikeshedder/actix_web_async_postgres/src/master/

Edit: Removed statement about r2d2 + postgres outperforming bb8 + tokio-postgres.

bikeshedder commented 5 years ago

In the original test r2d2 + postgres + web::block outperformed both l337 and bb8 with tokio-postgres. It seams that this was caused by different versions of the postgres library. See https://github.com/khuey/bb8/issues/29 and https://github.com/sfackler/rust-postgres/issues/469

I will go the full-async route myself now that I know that it was caused by a performance regression of the postgresql/tokio-postgresql crate rather than the connection pool.

chachacha3 commented 5 years ago

Close issue, examples of interaction between bb8 and actix_web can be found at @bikeshedder's bitbucket repository(link above)