集群服务设置中增加性能设置

This commit is contained in:
刘祥超
2023-01-01 19:27:38 +08:00
parent c42ff1e1e9
commit b4a4b2e9b1

View File

@@ -67,13 +67,17 @@ func NewClientConn(rawConn net.Conn, isTLS bool, quickClose bool, isInAllowList
} }
func (this *ClientConn) Read(b []byte) (n int, err error) { func (this *ClientConn) Read(b []byte) (n int, err error) {
this.lastReadAt = time.Now().Unix() var globalServerConfig = sharedNodeConfig.GlobalServerConfig
defer func() { if globalServerConfig != nil && globalServerConfig.Performance.Debug {
if err != nil { this.lastReadAt = time.Now().Unix()
this.lastErr = errors.New("read error: " + err.Error())
} defer func() {
}() if err != nil {
this.lastErr = errors.New("read error: " + err.Error())
}
}()
}
// 环路直接读取 // 环路直接读取
if this.isLO { if this.isLO {
@@ -122,21 +126,27 @@ func (this *ClientConn) Read(b []byte) (n int, err error) {
} }
func (this *ClientConn) Write(b []byte) (n int, err error) { func (this *ClientConn) Write(b []byte) (n int, err error) {
this.lastWriteAt = time.Now().Unix() var globalServerConfig = sharedNodeConfig.GlobalServerConfig
defer func() { if globalServerConfig != nil && globalServerConfig.Performance.Debug {
if err != nil { this.lastWriteAt = time.Now().Unix()
this.lastErr = errors.New("write error: " + err.Error())
} defer func() {
}() if err != nil {
this.lastErr = errors.New("write error: " + err.Error())
}
}()
}
// 设置超时时间 // 设置超时时间
// TODO L2 -> L1 写入时不限制时间 if globalServerConfig != nil && globalServerConfig.Performance.AutoWriteTimeout {
var timeoutSeconds = len(b) / 4096 // TODO L2 -> L1 写入时不限制时间
if timeoutSeconds < 3 { var timeoutSeconds = len(b) / 4096
timeoutSeconds = 3 if timeoutSeconds < 3 {
timeoutSeconds = 3
}
_ = this.rawConn.SetWriteDeadline(time.Now().Add(time.Duration(timeoutSeconds) * time.Second)) // TODO 时间可以设置
} }
_ = this.rawConn.SetWriteDeadline(time.Now().Add(time.Duration(timeoutSeconds) * time.Second)) // TODO 时间可以设置
n, err = this.rawConn.Write(b) n, err = this.rawConn.Write(b)
if n > 0 { if n > 0 {