mirror of
https://github.com/zr-hebo/sniffer-agent.git
synced 2025-08-12 02:01:57 +08:00
use cache reduce malloc
This commit is contained in:
39
model/query_piece_pool.go
Normal file
39
model/query_piece_pool.go
Normal 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user