mirror of
https://github.com/zr-hebo/sniffer-agent.git
synced 2025-09-19 02:06:52 +08:00
fix bug of share memory
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/pingcap/tidb/util/hack"
|
"github.com/pingcap/tidb/util/hack"
|
||||||
"time"
|
"time"
|
||||||
@@ -82,8 +80,8 @@ func (bqp *BaseQueryPiece) GetSQL() (*string) {
|
|||||||
func (bqp *BaseQueryPiece) Recovery() {
|
func (bqp *BaseQueryPiece) Recovery() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
func marsharQueryPieceShareMemory(qp interface{}, cacheBuffer []byte) []byte {
|
func marsharQueryPieceShareMemory(qp interface{}, cacheBuffer []byte) []byte {
|
||||||
|
|
||||||
buffer := bytes.NewBuffer(cacheBuffer)
|
buffer := bytes.NewBuffer(cacheBuffer)
|
||||||
err := json.NewEncoder(buffer).Encode(qp)
|
err := json.NewEncoder(buffer).Encode(qp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -92,6 +90,7 @@ func marsharQueryPieceShareMemory(qp interface{}, cacheBuffer []byte) []byte {
|
|||||||
|
|
||||||
return buffer.Bytes()
|
return buffer.Bytes()
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func marsharQueryPieceMonopolize(qp interface{}) (content []byte) {
|
func marsharQueryPieceMonopolize(qp interface{}) (content []byte) {
|
||||||
content, err := jsonIterator.Marshal(qp)
|
content, err := jsonIterator.Marshal(qp)
|
||||||
|
@@ -1,19 +1,13 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/zr-hebo/sniffer-agent/util"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
localSliceBufferPool = util.NewSliceBufferPool("json cache", (128+1)*1024)
|
|
||||||
)
|
|
||||||
|
|
||||||
type PooledMysqlQueryPiece struct {
|
type PooledMysqlQueryPiece struct {
|
||||||
MysqlQueryPiece
|
MysqlQueryPiece
|
||||||
recoverPool *mysqlQueryPiecePool
|
recoverPool *mysqlQueryPiecePool
|
||||||
sliceBufferPool *util.SliceBufferPool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPooledMysqlQueryPiece(
|
func NewPooledMysqlQueryPiece(
|
||||||
@@ -22,7 +16,6 @@ func NewPooledMysqlQueryPiece(
|
|||||||
pmqp *PooledMysqlQueryPiece) {
|
pmqp *PooledMysqlQueryPiece) {
|
||||||
pmqp = mqpp.Dequeue()
|
pmqp = mqpp.Dequeue()
|
||||||
|
|
||||||
pmqp.sliceBufferPool = localSliceBufferPool
|
|
||||||
nowInMS := time.Now().UnixNano() / millSecondUnit
|
nowInMS := time.Now().UnixNano() / millSecondUnit
|
||||||
pmqp.SessionID = sessionID
|
pmqp.SessionID = sessionID
|
||||||
pmqp.ClientHost = clientIP
|
pmqp.ClientHost = clientIP
|
||||||
@@ -41,9 +34,6 @@ func NewPooledMysqlQueryPiece(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pmqp *PooledMysqlQueryPiece) Recovery() {
|
func (pmqp *PooledMysqlQueryPiece) Recovery() {
|
||||||
if pmqp.sliceBufferPool != nil {
|
|
||||||
pmqp.sliceBufferPool.Enqueue(pmqp.jsonContent[:0])
|
|
||||||
}
|
|
||||||
pmqp.jsonContent = nil
|
pmqp.jsonContent = nil
|
||||||
pmqp.recoverPool.Enqueue(pmqp)
|
pmqp.recoverPool.Enqueue(pmqp)
|
||||||
}
|
}
|
||||||
@@ -59,18 +49,8 @@ func (pmqp *PooledMysqlQueryPiece) Bytes() (content []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pmqp *PooledMysqlQueryPiece) GenerateJsonBytes() {
|
func (pmqp *PooledMysqlQueryPiece) GenerateJsonBytes() {
|
||||||
if pmqp.sliceBufferPool == nil {
|
|
||||||
pmqp.jsonContent = marsharQueryPieceMonopolize(pmqp)
|
pmqp.jsonContent = marsharQueryPieceMonopolize(pmqp)
|
||||||
return
|
return
|
||||||
}
|
|
||||||
|
|
||||||
var cacheBuffer = pmqp.sliceBufferPool.Dequeue()
|
|
||||||
if len(cacheBuffer) > 0 {
|
|
||||||
panic("there already have bytes in buffer")
|
|
||||||
}
|
|
||||||
|
|
||||||
pmqp.jsonContent = marsharQueryPieceShareMemory(pmqp, cacheBuffer)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type mysqlQueryPiecePool struct {
|
type mysqlQueryPiecePool struct {
|
||||||
|
Reference in New Issue
Block a user