2

New Mobc Release 0.8.1

 1 year ago
source link: https://www.garrensmith.com/new-mobc-release-0-8-1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Jan 21, 2023 1 min read

New Mobc Release 0.8.1

New Mobc Release 0.8.1

I'm very excited to announce a new release of Mobc. Mobc is a highly performant asynchronous connection pool for Rust.

Noteable changes:

  • A rewrite of the internals, moved from using Tokio channels to using a Tokio Sempahore to manage connections.
  • Added Tokio metrics for insight into the internals of Mobc. See the metric file for full list of metrics captured

This release is a port of the fixes I made in the Prisma Mobc fork and now merged into the main Mobc repo. These fixes have been battle tested in production with Prisma and other large systems using Mobc.

Background

While working at Prisma last year, I noticed a lot of connection pool error reports. Prisma is a Node.js ORM that internally has a Rust engine that handles database queries and uses Mobc to manage the connections to the databases.

After a fair amount of deep diving into Prisma and Mobc, I found the issue to be related to Mobc dropping existing connections, not creating new connections and causing Prisma to not be able to continue. Issue 63 gives a detailed blow by blow while I debugged the issue. The TLDR is that Tokio channels can be in a state that the message sent along the channel is dropped because the receiver has been dropped before the sender knows this.

To fix this issue, I changed Mobc to use a Semaphore to handle connection access and a mutex on a Vec to keep any free connections. A lot of the inspiration was taken from speaking to the Tokio community and the Deadpool connection pool manager that also uses a Semaphore.

I'm really excited to get this release out, I think it will really benefit the community of Mobc users. If you notice any issues, have questions or ideas for improvements to Mobc, please open an issue on the Mobc repo.

Published by:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK