addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwchatcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrosseditemptyheartfacebookfolderfullheartglobegmailgoogleimagesinstagramlinklocation-pinmagnifying-glassmailminusmoremuplabelShape 3 + Rectangle 1outlookpersonplusprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

Connection pools

From: Ryan D.
Sent on: Tuesday, August 28, 2012 7:48 PM
Hey everybody!

I have been using a couple different packages for communicating with MySQL and Redis, and I've found that the packages I've seen have a single connection to the server, which is a significant bottleneck if your application is parallel(I'm dealing with web connections).

I came up with an abstract ConnectionPool which allows you to create N connections to your datastore, and retrieve a connection from a pool. You can use that connection as long as necessary, then return it to the pool. I found this to be much easier than forking and modifying each package in your codebase that connects to a datastore.

I've got a gist here https://gist.github.com/3504674 and an example implementation here https://gist.github.com/3504712. The implementation is taken from our codebase and is for MySQL database connections. We put this into production just today. So I figured I'd share it and see if there are any comments, or maybe somebody sees a huge gotcha that I am totally overlooking.

Anyway, thanks for any advice or tips (or other packages where I don't recreate the wheel)!



Ryan

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy