Connection pool
A set of open database connections that requests borrow and return. *sql.DB is one: open it once, cap it with SetMaxOpenConns, recycle with SetConnMaxLifetime, and remember that N instances multiply the connections MySQL sees.
Minimal example
db.SetMaxOpenConns(20)
db.SetMaxIdleConns(10)
db.SetConnMaxLifetime(5 * time.Minute)Learn this concept
Lesson 2.4 · database/sql: pools, contexts and timeoutsUsed in exercises
Exercise 2.7 · Seed 50 restaurants and one full menu Exercise 6.12 · Find and fix the first bottleneckPrerequisite conceptsdatabase/sql
RelatedQuery timeout