Fix prepared statement performance with database/sql

scan-io
Jack Christensen 2014-06-21 18:28:56 -05:00
parent 6bb0a9fa75
commit b1834a527d
1 changed files with 7 additions and 1 deletions

View File

@ -60,7 +60,13 @@ func OpenFromConnPool(pool *pgx.ConnPool) (*sql.DB, error) {
return nil, err
}
db.SetMaxIdleConns(0)
// Presumably OpenFromConnPool is being used because the user wants to use
// database/sql most of the time, but fast path with pgx some of the time.
// Allow database/sql to use all the connections, but release 2 idle ones.
// Don't have database/sql immediately release all idle connections because
// that would mean that prepared statements would be lost (which kills
// performance if the prepared statements constantly have to be reprepared)
db.SetMaxIdleConns(pool.MaxConnectionCount() - 2)
db.SetMaxOpenConns(pool.MaxConnectionCount())
return db, nil