From b4a4b2e9b19d3ddb4a01fc6b34a9d2c6695644b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Sun, 1 Jan 2023 19:27:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E7=BE=A4=E6=9C=8D=E5=8A=A1=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E5=A2=9E=E5=8A=A0=E6=80=A7=E8=83=BD=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/client_conn.go | 44 +++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/internal/nodes/client_conn.go b/internal/nodes/client_conn.go index a8c802a..d35d723 100644 --- a/internal/nodes/client_conn.go +++ b/internal/nodes/client_conn.go @@ -67,13 +67,17 @@ func NewClientConn(rawConn net.Conn, isTLS bool, quickClose bool, isInAllowList } func (this *ClientConn) Read(b []byte) (n int, err error) { - this.lastReadAt = time.Now().Unix() + var globalServerConfig = sharedNodeConfig.GlobalServerConfig - defer func() { - if err != nil { - this.lastErr = errors.New("read error: " + err.Error()) - } - }() + if globalServerConfig != nil && globalServerConfig.Performance.Debug { + this.lastReadAt = time.Now().Unix() + + defer func() { + if err != nil { + this.lastErr = errors.New("read error: " + err.Error()) + } + }() + } // 环路直接读取 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) { - this.lastWriteAt = time.Now().Unix() + var globalServerConfig = sharedNodeConfig.GlobalServerConfig - defer func() { - if err != nil { - this.lastErr = errors.New("write error: " + err.Error()) - } - }() + if globalServerConfig != nil && globalServerConfig.Performance.Debug { + this.lastWriteAt = time.Now().Unix() + + defer func() { + if err != nil { + this.lastErr = errors.New("write error: " + err.Error()) + } + }() + } // 设置超时时间 - // TODO L2 -> L1 写入时不限制时间 - var timeoutSeconds = len(b) / 4096 - if timeoutSeconds < 3 { - timeoutSeconds = 3 + if globalServerConfig != nil && globalServerConfig.Performance.AutoWriteTimeout { + // TODO L2 -> L1 写入时不限制时间 + var timeoutSeconds = len(b) / 4096 + 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) if n > 0 {