mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化新增Rpc压缩与自定义超时功能
This commit is contained in:
@@ -12,7 +12,7 @@ var memPool network.INetMempool = network.NewMemAreaPool()
|
|||||||
|
|
||||||
type ICompressor interface {
|
type ICompressor interface {
|
||||||
CompressBlock(src []byte) ([]byte, error) //dst如果有预申请使用dst内存,传入nil时内部申请
|
CompressBlock(src []byte) ([]byte, error) //dst如果有预申请使用dst内存,传入nil时内部申请
|
||||||
UncompressBlock(src []byte) ([]byte, error)//dst如果有预申请使用dst内存,传入nil时内部申请
|
UncompressBlock(src []byte) ([]byte, error) //dst如果有预申请使用dst内存,传入nil时内部申请
|
||||||
|
|
||||||
CompressBufferCollection(buffer []byte) //压缩的Buffer内存回收
|
CompressBufferCollection(buffer []byte) //压缩的Buffer内存回收
|
||||||
UnCompressBufferCollection(buffer []byte) //解压缩的Buffer内存回收
|
UnCompressBufferCollection(buffer []byte) //解压缩的Buffer内存回收
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ func (rc *RClient) Go(timeout time.Duration,rpcHandler IRpcHandler,noReply bool,
|
|||||||
return rc.RawGo(rpcHandler,processor, noReply, 0, serviceMethod, InParam, reply)
|
return rc.RawGo(rpcHandler,processor, noReply, 0, serviceMethod, InParam, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (rc *RClient) RawGo(rpcHandler IRpcHandler,processor IRpcProcessor, noReply bool, rpcMethodId uint32, serviceMethod string, rawArgs []byte, reply interface{}) *Call {
|
func (rc *RClient) RawGo(rpcHandler IRpcHandler,processor IRpcProcessor, noReply bool, rpcMethodId uint32, serviceMethod string, rawArgs []byte, reply interface{}) *Call {
|
||||||
call := MakeCall()
|
call := MakeCall()
|
||||||
call.ServiceMethod = serviceMethod
|
call.ServiceMethod = serviceMethod
|
||||||
@@ -107,9 +106,6 @@ func (rc *RClient) RawGo(rpcHandler IRpcHandler,processor IRpcProcessor, noReply
|
|||||||
if cap(compressBuff) >0 {
|
if cap(compressBuff) >0 {
|
||||||
compressor.CompressBufferCollection(compressBuff)
|
compressor.CompressBufferCollection(compressBuff)
|
||||||
}
|
}
|
||||||
if cap(compressBuff) >0 {
|
|
||||||
compressor.CompressBufferCollection(compressBuff)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rc.selfClient.RemovePending(call.Seq)
|
rc.selfClient.RemovePending(call.Seq)
|
||||||
|
|
||||||
@@ -228,9 +224,9 @@ func (rc *RClient) Run() {
|
|||||||
//解压缩
|
//解压缩
|
||||||
byteData := bytes[1:]
|
byteData := bytes[1:]
|
||||||
var compressBuff []byte
|
var compressBuff []byte
|
||||||
|
|
||||||
if bCompress == true {
|
if bCompress == true {
|
||||||
var unCompressErr error
|
var unCompressErr error
|
||||||
|
|
||||||
compressBuff,unCompressErr = compressor.UncompressBlock(byteData)
|
compressBuff,unCompressErr = compressor.UncompressBlock(byteData)
|
||||||
if unCompressErr!= nil {
|
if unCompressErr!= nil {
|
||||||
rc.conn.ReleaseReadMsg(bytes)
|
rc.conn.ReleaseReadMsg(bytes)
|
||||||
@@ -244,6 +240,7 @@ func (rc *RClient) Run() {
|
|||||||
if cap(compressBuff) > 0 {
|
if cap(compressBuff) > 0 {
|
||||||
compressor.UnCompressBufferCollection(compressBuff)
|
compressor.UnCompressBufferCollection(compressBuff)
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.conn.ReleaseReadMsg(bytes)
|
rc.conn.ReleaseReadMsg(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
processor.ReleaseRpcResponse(response.RpcResponseData)
|
processor.ReleaseRpcResponse(response.RpcResponseData)
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ func (agent *RpcAgent) Run() {
|
|||||||
processor := GetProcessor(data[0]&0x7f)
|
processor := GetProcessor(data[0]&0x7f)
|
||||||
if processor == nil {
|
if processor == nil {
|
||||||
agent.conn.ReleaseReadMsg(data)
|
agent.conn.ReleaseReadMsg(data)
|
||||||
log.SError("remote rpc ", agent.conn.RemoteAddr(), " cannot find processor:", data[0])
|
log.SError("remote rpc ", agent.conn.RemoteAddr().String(), " cannot find processor:", data[0])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ func (agent *RpcAgent) Run() {
|
|||||||
compressBuff,unCompressErr = compressor.UncompressBlock(byteData)
|
compressBuff,unCompressErr = compressor.UncompressBlock(byteData)
|
||||||
if unCompressErr!= nil {
|
if unCompressErr!= nil {
|
||||||
agent.conn.ReleaseReadMsg(data)
|
agent.conn.ReleaseReadMsg(data)
|
||||||
log.SError("rpcClient ", agent.conn.RemoteAddr(), " ReadMsg head error:", unCompressErr.Error())
|
log.SError("rpcClient ", agent.conn.RemoteAddr().String(), " ReadMsg head error:", unCompressErr.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
byteData = compressBuff
|
byteData = compressBuff
|
||||||
|
|||||||
Reference in New Issue
Block a user