Connection pooling, rate limiting, and timeouts for SQL
Although the database/sql
package provides support for connection pooling, rate limiting, and timeouts, it's often important to tweak the defaults to better accommodate your database configuration. This can become important when you have horizontal scaling on microservices and don't want to hold too many active connections to the database.
Getting ready
Configure your environment according to these steps:
- Refer to the steps given in the Getting ready section of the The database/sql package with MySQL recipe.
- Run the
go get https://github.com/agtorre/go-cookbook/tree/master/chapter5/database
command or write your own using the The database/sql package with MySQL recipe.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create and navigate to the
chapter5/pools
directory. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter5/pools or use this as an exercise to...