Golang database/sql.DB.SetMaxIdleConns function example
package database/sql
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
If MaxOpenConns is greater than 0 but less than the new MaxIdleConns then the new MaxIdleConns will be reduced to match the MaxOpenConns limit
If n <= 0, no idle connections are retained.
Golang database/sql.DB.SetMaxIdleConns function usage example
const concurrencyLevel = 10
db := initDB(b,
"DROP TABLE IF EXISTS foo",
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))",
`INSERT INTO foo VALUES (1, "one")`,
`INSERT INTO foo VALUES (2, "two")`,
)
db.SetMaxIdleConns(concurrencyLevel) // <-- here
defer db.Close()
Reference :
Advertisement
Something interesting
Tutorials
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+5.8k Golang : Find change in a combination of coins example
+9.7k Golang : interface - when and where to use examples
+4.9k HTTP common errors and their meaning explained
+7.4k Golang : Example of custom handler for Gorilla's Path usage.
+40.1k Golang : UDP client server read write example
+10.3k Golang : Detect number of faces or vehicles in a photo
+8.5k PHP : How to parse ElasticSearch JSON ?
+48.5k Golang : Upload file from web browser to server
+7.4k Golang : How to detect if a sentence ends with a punctuation?
+13.2k Golang : How to calculate the distance between two coordinates using Haversine formula
+6.9k Golang : How to solve "too many .rsrc sections" error?