O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Connection pooling with r2d2

If an application requires any sort of efficiency, opening and closing a database connection every time something happens becomes a bottleneck really fast. A technique called connection pooling helps with this; when a process needs a new connection, a pool gives out an existing connection if any exists, and when a process no longer needs the connection, it hands it over back to the pool.

A crate called r2d2 provides a generic way of maintaining such connections. Currently, it contains backend support for PostgreSQL, Redis, MySQL, SQLite, and a few lesser known options. We'll cover r2d2 here by first checking out how to connect to PostgreSQL using a pool and then by investigating how to implement a pool for our ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required