优化rpc内存池

This commit is contained in:
boyce
2021-01-08 10:21:54 +08:00
parent f88423c7ab
commit 7e288ccdd8
5 changed files with 38 additions and 49 deletions

View File

@@ -28,7 +28,6 @@ func (r *Responder) IsInvalid() bool {
return reflect.ValueOf(*r).Pointer() == reflect.ValueOf(reqHandlerNull).Pointer()
}
//var rpcResponsePool sync.Pool
var rpcRequestPool = sync.NewPoolEx(make(chan sync.IPoolData,10240),func()sync.IPoolData{
return &RpcRequest{}
})
@@ -148,31 +147,20 @@ func MakeRpcRequest(rpcProcessor IRpcProcessor,seq uint64,rpcMethodId uint32,ser
rpcRequest := rpcRequestPool.Get().(*RpcRequest).Clear()
rpcRequest.rpcProcessor = rpcProcessor
rpcRequest.RpcRequestData = rpcRequest.rpcProcessor.MakeRpcRequest(seq,rpcMethodId,serviceMethod,noReply,inParam)
rpcRequest.ref = true
return rpcRequest
}
func ReleaseRpcRequest(rpcRequest *RpcRequest){
if rpcRequest.ref == false {
panic("Duplicate memory release!")
}
rpcRequest.ref = false
rpcRequest.rpcProcessor.ReleaseRpcRequest(rpcRequest.RpcRequestData)
rpcRequestPool.Put(rpcRequest)
}
func MakeCall() *Call {
call := rpcCallPool.Get().(*Call).Clear()
call.ref = true
return call
return rpcCallPool.Get().(*Call)
}
func ReleaseCall(call *Call){
if call.ref == false {
panic("Duplicate memory release!")
}
call.ref = false
rpcCallPool.Put(call)
}