use cache reduce malloc

This commit is contained in:
hebo
2019-09-09 21:36:18 +08:00
parent 3294a0fc5f
commit 4086028217
12 changed files with 280 additions and 169 deletions

39
model/query_piece_pool.go Normal file
View File

@@ -0,0 +1,39 @@
package model
import (
"sync"
)
type mysqlQueryPiecePool struct {
queue chan *PooledMysqlQueryPiece
lock sync.Mutex
}
func NewMysqlQueryPiecePool() (mqpp *mysqlQueryPiecePool) {
return &mysqlQueryPiecePool{
queue: make(chan *PooledMysqlQueryPiece, 1024),
}
}
func (mqpp *mysqlQueryPiecePool) Enqueue(pmqp *PooledMysqlQueryPiece) {
mqpp.lock.Lock()
defer mqpp.lock.Unlock()
mqpp.queue <- pmqp
}
func (mqpp *mysqlQueryPiecePool) Dequeue() (pmqp *PooledMysqlQueryPiece) {
mqpp.lock.Lock()
defer mqpp.lock.Unlock()
select {
case pmqp = <- mqpp.queue:
return
default:
pmqp = &PooledMysqlQueryPiece{
MysqlQueryPiece: MysqlQueryPiece{},
}
return
}
}