gorm官方是给出了关于mysql的线程池的配置。
官方文档地址: https://gorm.io/zh_CN/docs/connecting_to_the_database.html
ps: 可知,mysql/sqlLite/TiDB进行了支持。
Connection Pool
GORM using database/sql to maintain connection pool
sqlDB, err := db.DB()
// SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
//最大空闲连接数
sqlDB.SetMaxIdleConns(10)
// SetMaxOpenConns sets the maximum number of open connections to the database.
//最大连接数
sqlDB.SetMaxOpenConns(100)
//空闲链接最大空闲超时
// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
sqlDB.SetConnMaxLifetime(time.Hour)
本身,mysql就会配置以上相关的链接,所以本身关于gorm的db配置,不能超过关于mysql服务的配置。
同时,需要注意的是,由于go常常所谓服务器的存在,那么对应的需要单例功能,单次请求中,消耗完所有的mysql链接。
最后,是否主动关闭mysql链接,需要进一步排查。
标签:maximum,sqlDB,mysql,go,gorm,pool From: https://www.cnblogs.com/supermarx/p/17149994.html