mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
1.删除msgp序列化方式
2.优化临时内存池减少GC
This commit is contained in:
27
rpc/rpc.go
27
rpc/rpc.go
@@ -19,6 +19,20 @@ type RpcResponse struct {
|
||||
RpcResponeData IRpcResponseData
|
||||
}
|
||||
|
||||
func (slf *RpcRequest) Clear() *RpcRequest{
|
||||
slf.RpcRequestData = nil
|
||||
slf.localReply = nil
|
||||
slf.localParam = nil
|
||||
slf.requestHandle = nil
|
||||
slf.callback = nil
|
||||
return slf
|
||||
}
|
||||
|
||||
func (slf *RpcResponse) Clear() *RpcResponse{
|
||||
slf.RpcResponeData = nil
|
||||
return slf
|
||||
}
|
||||
|
||||
type IRpcRequestData interface {
|
||||
GetSeq() uint64
|
||||
GetServiceMethod() string
|
||||
@@ -49,7 +63,7 @@ type Call struct {
|
||||
calltime time.Time
|
||||
}
|
||||
|
||||
func (slf *Call) Clear(){
|
||||
func (slf *Call) Clear() *Call{
|
||||
slf.Seq = 0
|
||||
slf.ServiceMethod = ""
|
||||
slf.Arg = nil
|
||||
@@ -59,6 +73,7 @@ func (slf *Call) Clear(){
|
||||
slf.connid = 0
|
||||
slf.callback = nil
|
||||
slf.rpcHandler = nil
|
||||
return slf
|
||||
}
|
||||
|
||||
func (slf *Call) Done() *Call{
|
||||
@@ -74,6 +89,8 @@ var rpcResponePool sync.Pool
|
||||
var rpcRequestPool sync.Pool
|
||||
var rpcCallPool sync.Pool
|
||||
|
||||
|
||||
|
||||
func init(){
|
||||
rpcResponePool.New = func()interface{}{
|
||||
return &RpcResponse{}
|
||||
@@ -89,17 +106,15 @@ func init(){
|
||||
}
|
||||
|
||||
func MakeRpcResponse() *RpcResponse{
|
||||
return rpcResponePool.Get().(*RpcResponse)
|
||||
return rpcResponePool.Get().(*RpcResponse).Clear()
|
||||
}
|
||||
|
||||
func MakeRpcRequest() *RpcRequest{
|
||||
return rpcRequestPool.Get().(*RpcRequest)
|
||||
return rpcRequestPool.Get().(*RpcRequest).Clear()
|
||||
}
|
||||
|
||||
func MakeCall() *Call {
|
||||
call := rpcCallPool.Get().(*Call)
|
||||
|
||||
return call
|
||||
return rpcCallPool.Get().(*Call).Clear()
|
||||
}
|
||||
|
||||
func ReleaseRpcResponse(rpcRespone *RpcResponse){
|
||||
|
||||
Reference in New Issue
Block a user