rpc内存池优化

This commit is contained in:
boyce
2021-01-08 11:01:09 +08:00
parent 7e288ccdd8
commit 0475edbf9e
3 changed files with 9 additions and 6 deletions

View File

@@ -144,7 +144,7 @@ func (call *Call) Done() *Call{
} }
func MakeRpcRequest(rpcProcessor IRpcProcessor,seq uint64,rpcMethodId uint32,serviceMethod string,noReply bool,inParam []byte) *RpcRequest{ func MakeRpcRequest(rpcProcessor IRpcProcessor,seq uint64,rpcMethodId uint32,serviceMethod string,noReply bool,inParam []byte) *RpcRequest{
rpcRequest := rpcRequestPool.Get().(*RpcRequest).Clear() rpcRequest := rpcRequestPool.Get().(*RpcRequest)
rpcRequest.rpcProcessor = rpcProcessor rpcRequest.rpcProcessor = rpcProcessor
rpcRequest.RpcRequestData = rpcRequest.rpcProcessor.MakeRpcRequest(seq,rpcMethodId,serviceMethod,noReply,inParam) rpcRequest.RpcRequestData = rpcRequest.rpcProcessor.MakeRpcRequest(seq,rpcMethodId,serviceMethod,noReply,inParam)

View File

@@ -243,12 +243,12 @@ func (handler *RpcHandler) HandlerRpcRequest(request *RpcRequest) {
request.requestHandle(nil,rpcErr) request.requestHandle(nil,rpcErr)
} }
} }
if request.requestHandle == nil {
ReleaseRpcRequest(request)
}
}() }()
if request.requestHandle == nil {
defer ReleaseRpcRequest(request)
}
//如果是原始RPC请求 //如果是原始RPC请求
rawRpcId := request.RpcRequestData.GetRpcMethodId() rawRpcId := request.RpcRequestData.GetRpcMethodId()
if rawRpcId>0 { if rawRpcId>0 {

View File

@@ -1,6 +1,8 @@
package sync package sync
import sysSync "sync" import (
sysSync "sync"
)
type Pool struct { type Pool struct {
C chan interface{} //最大缓存的数量 C chan interface{} //最大缓存的数量
@@ -36,6 +38,7 @@ func (pool *Pool) Put(data interface{}){
default: default:
pool.syncPool.Put(data) pool.syncPool.Put(data)
} }
} }
func NewPool(C chan interface{},New func()interface{}) *Pool{ func NewPool(C chan interface{},New func()interface{}) *Pool{