-
Notifications
You must be signed in to change notification settings - Fork 546
Chapter 3.8.2: DB Choice - async vs connection pooling #65
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
Comments
For anyone following at home... it would appear that an async DB API, which rustaceans view as |
The issue you linked explains what
Which boils down to "a transaction will always be committed/rolled back as long the connection is used again". A synchronous API, on the other side, is much more prone to misuse: you need to go and inspect all functions you are calling from an asynchronous context to make sure none of those is performing a query because, if they are, they have to be wrapped in a The latter case worries me much more than the former. It's not a conversation about performance or throughput. I haven't added an extensive discussion about the topic because it's a fast changing subject and it's probably mostly of interest to advanced Rust users, but I am happy to add a footnote if you think that would be beneficial. |
Sure, but this isn't my baby. Maybe something like:
One could also argure the last sentence could be:
|
Why are you suggesting that
Oh, it's definitely mine 😁 |
Ignorance? More seriously, I didn't revise that because I took the deadpool claim of 100 line implementation at psuedo-face value - i.e. on inspection of managed code it seemed about right. The sqlx PgPool implementation (ignoring comments) looked even more elegant. From experience that code usually hides/locates the implementation detail elsewhere and since they don't make any claims about their implementation and don't point to the relevant functions I didn't investigate further. With my Rust skill-level that is about all that could be done. On a related note you have repeatedly put words in my mouth, I've tended to let it slide, but it is not common courtesy. "more robust" is not what I said. "least vulnerable" is not the same thing, and note I do refer to not just the code but working examples of a specific use case. Incase you take that too far - I note that I'm providing a suggestion aligned with your recommendation to use async DB crates. Hopefully it is clear I disagree with that assessment. Unfortunately I cut my async teeth on MPI in the 90's. I still have nightmares about the dragons ;) |
My bad indeed, I am sorry 🙇🏼 |
Closing as resolved. |
Uh oh!
There was an error while loading. Please reload this page.
Obviously I'm a Rust noob, so please bear that in mind. Specifically I have not used any Rust DB library.
Many readers will be too and will be relying on choices made here.
After a cursory review of Diesel issue: diesel-rs/diesel/issues/399 I'm nervous about sqlx.
I don't think you addressed their substantive reasons for not offering an async API.
Are you indicating the sqlx has resolved those issues in their crate?
If so could you say so explicitly? It would also be informative to know if it is your opinion that the Diesel reservations are unfounded? Unreasonably conservative? You didn't hold back on the use of executable business documents ;)
Frank and forthright is generally valuable.
In fact the Diesel reasons for their choice of sync and your reasons for recommending a relational DB are pretty much the same. Repurposing you relational DB statement, one could say this is reasonable description of the state-of-play in Diesel:
Yet when it comes to a DB library you guide to a choice, sqlx, that IMO is high risk, for no return that I'm aware of. The risk is some less experienced user relying on the async API while using transactions. I could be wrong but there is no reasonable assurance that your app will only hit issues with transaction issues that leave incomplete transactions at very high 'Google' scale volumes.
The risk-return trade-off gets worse for sqlx when you consider that there are Rust crates
r2d2
andbb8
, helping you handle increased workloads. If your app scales beyond that capacity, (+sharding) then you should be looking at the toys the big kids are playing with.While I haven't read the whole book, I wonder if there isn't a lost opportunity to add
r2d2
,bb8
, or some such crate, as a step to production? Perhaps this comes up later?The text was updated successfully, but these errors were encountered: