-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Tracking Issue for Asynchronous Database Pool Support #1117
Comments
Here's an updated list of things I think we would need to address in order to fully support async database pools. Importantly, I think it's not yet possible after all to set up a pool "the manual way" because some of Rocket's traits--such as
Some of these are more general changes than just databases that we will want to do anyway to support other use cases. |
This might turn out to be pretty tricky. Doing this safely requires either marshaling certain requests to a thread pool or using executor-specific functionality like djc/bb8#37 was just opened, which would make |
Hey, I just found this and it seems to give a pretty cool r2d2 style API for async connections. Works with async/await. https://github.com/animalsiknow/tokio-resource-pool Here's my example project where I tested it and seems to work: |
And btw. please be careful with |
|
Yeah, we're needing similar crates here in Prisma as you do in Rocket. I almost coughed my coffee to my keyboard when I found out that Moving ahead and using these primitives to make our dynamic query builder and connector interface async on this week! |
I have a personal use connection pool. It's basically a simplified bb8 and l337 with async/await enabled. The repo is: https://github.com/fakeshadow/tang_rs I'm not sure if it's in good quality though as I don't have any tests and I'm the only one who use it. |
|
I got around to looking at a few APIs more closely:
|
@fakeshadow Hi your library looks very well-developed! I'm not too sure on whether to use yours or tokio-resource-pool though. Could you elaborate on the differences and tradeoffs? Not sure which one would be better. I'm using postgres with Rocket and would like to just call something like |
@githubaccount624 I have not used |
Here are the
Last updated 2020-01-25
|
Not sure how much that's useful, but djc/bb8#37 has just got merged, which brings async/await to bb8 |
I'm currently reasoning if |
You make a good point in that issue - it should be easy (especially now with |
Deadpool 0.4 now supports timeouts: use deadpool::{Config, Timeouts};
use deadpool_postgres::Pool;
let pool_config = Config::new(16);
pool_config.timeouts = Timeouts::wait_millis(2000);
let pool = Pool::from_config(pool_config); I added this to deadpool as it is the only way to differentiate the timeouts for |
bb8 now has a released 0.4.0 version -- I am the new maintainer. |
Status update: everything exists in rocket's async branch that is necessary to implement asynchronous pools, and it's fairly straightforward to port
|
sqlx has recently added SQlite support which means it supports PostgreSQL, MySQL, and SQLite. It's runtime agnostic, supports connection pools and optionally you can have type checked queries without buying into a DSL. |
It would be nice to be able to use SQLx in rocket as a backend, yes, since currently Diesel seems to be the backend of choice. Not sure though if we could use the pool as the default pool, though, as it only supports 3 backends. |
My thinking is that
That being said, Alternatively, perhaps connection pooling in |
@jebrosen Give that you've done some work in the background on this issue, do you have any more insight into how we might proceed? |
I've been working on this proof-of-concept I called The high-level interface is described at https://git.jebrosen.com/jeb/sirus/src/tag/rocket-database-pool-20201102/rocket-database-pool/src/lib.rs#L370-L405, reproduced here:
It's more or less the same as
However I'm of two minds on most of the design and have been rewriting something about it every few weeks, such as:
I think the latest updates for configuration was the last "known big API change" on my list, so the next few weeks would be a perfect time to start making some of those decisions, getting more eyeballs on the code, and deciding on whether it or something similar should go in |
Why?
Creating a database connection can be an expensive operation. Connection pools can alleviate this and serve as an important performance optimization for web servers. The current connection pool in Rocket is synchronous. It would be desirable to have support for an asynchronous connection pool in the up-and-coming async Rocket.
How?
jebrosen elaborates in this issue reply. One of the main blockers is that Rocket and the database engine should first run within the same runtime (tokio 0.1 or tokio 0.2). This seems partially resolved as the async branch of tokio-postgres and Rocket are both currently using
tokio=0.2.0-alpha.4
.Jeb's second point is that
connect
may be an asynchronous operation and whether or notFromRequest
should return aFuture
. Connecting to a database can sometimes take 50+ milliseconds andtokio-postgres
has already madeconnect
an asynchronous operation, so it seems like a safe bet to accommodate this fact.I'll just paste the rest of Jeb's minimum required tasks for reference:
The text was updated successfully, but these errors were encountered: