You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bad connection
$ wrk -c300 -d10m -t8 url
SetMaxOpenConns(100)
When wrk just started, Occasional bad connection error, And the number of mysql PROCESSLIST is less than 100, around 70
I modified the file
database/sql/sql.go
func OpenDB(c driver.Connector) *DB {
ctx, cancel := context.WithCancel(context.Background())
db := &DB{
connector: c,
openerCh: make(chan struct{}, connectionRequestQueueSize),
resetterCh: make(chan *driverConn, 50),
lastPut: make(map[*driverConn]string),
connRequests: make(map[uint64]chan connRequest),
stop: cancel,
}
go db.connectionOpener(ctx)
go db.connectionResetter(ctx)
return db
}
Changed the buffer length of resetterCh
resetterCh: make(chan *driverConn, 100),
Solved the bad connection problem, and the number of mysql PROCESSLIST instantly reached 100
When the server resource consumption is small, a small number of errors are reported during the pressure test: the error rate is lower than 0.01%, but this error will occur every time;
qps:5000/s
I found that when I get a connection from the connection pool, I must judge whether the connection is expired, resulting in bad connection
in func (db *DB) conn() {
conn.inUse = true
if conn.expired(lifetime) {
db.maxLifetimeClosed++
db.mu.Unlock()
conn.Close()
return nil, driver.ErrBadConn
}
}
Issue description
bad connection
$ wrk -c300 -d10m -t8 url
SetMaxOpenConns(100)
When wrk just started, Occasional bad connection error, And the number of mysql PROCESSLIST is less than 100, around 70
I modified the file
Changed the buffer length of resetterCh
Solved the bad connection problem, and the number of mysql PROCESSLIST instantly reached 100
Example code
Error log
Configuration
Driver version (or git SHA):
Go version: run
go version
in your console1.14
Server version: E.g. MySQL 5.6, MariaDB 10.0.20
Server OS: E.g. Debian 8.1 (Jessie), Windows 10
The text was updated successfully, but these errors were encountered: