From 01812144dd26a1583faa7198a2dd6782880a231f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 12 Jan 2023 19:09:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B8=A6=E5=AE=BD=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/client_conn.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/nodes/client_conn.go b/internal/nodes/client_conn.go index a229c5b..cc338a4 100644 --- a/internal/nodes/client_conn.go +++ b/internal/nodes/client_conn.go @@ -148,7 +148,7 @@ func (this *ClientConn) Write(b []byte) (n int, err error) { if len(b) == 0 { return 0, nil } - + if this.isDebugging { this.lastWriteAt = time.Now().Unix() @@ -177,13 +177,21 @@ func (this *ClientConn) Write(b []byte) (n int, err error) { } // 开始写入 + var before = time.Now() n, err = this.rawConn.Write(b) if n > 0 { + // 统计当前服务带宽 if this.serverId > 0 { if !this.isLO || Tea.IsTesting() { // 环路不统计带宽,避免缓存预热等行为产生带宽 atomic.AddUint64(&teaconst.OutTrafficBytes, uint64(n)) - stats.SharedBandwidthStatManager.Add(this.userId, this.serverId, int64(n)) + + var cost = time.Since(before).Seconds() + if cost > 1 { + stats.SharedBandwidthStatManager.Add(this.userId, this.serverId, int64(float64(n)/cost)) + } else { + stats.SharedBandwidthStatManager.Add(this.userId, this.serverId, int64(n)) + } } } }