diff --git a/dfget/core/downloader/p2p_downloader/power_client.go b/dfget/core/downloader/p2p_downloader/power_client.go index 70ceb14c6..3ffffd0fe 100644 --- a/dfget/core/downloader/p2p_downloader/power_client.go +++ b/dfget/core/downloader/p2p_downloader/power_client.go @@ -38,6 +38,12 @@ import ( "github.com/sirupsen/logrus" ) +const ( + // downloadPieceTimeout specifies the timeout for piece downloading. + // If the actual execution time exceeds this threshold, a warning will be thrown. + downloadPieceTimeout = 2.0 * time.Second +) + // PowerClient downloads file from dragonfly. type PowerClient struct { // taskID is a string which represents a unique task. @@ -149,9 +155,9 @@ func (pc *PowerClient) downloadPiece() (content *bytes.Buffer, e error) { pc.pieceTask.Range, pieceMD5, realMd5) } - if timeDuring := time.Since(startTime).Seconds(); timeDuring > 2.0 { + if timeDuring := time.Since(startTime); timeDuring > downloadPieceTimeout { logrus.Warnf("client range:%s cost:%.3f from peer:%s, readCost:%.3f, length:%d", - pc.pieceTask.Range, timeDuring, dstIP, pc.readCost.Seconds(), pc.total) + pc.pieceTask.Range, timeDuring.Seconds(), dstIP, pc.readCost.Seconds(), pc.total) } return content, nil } diff --git a/supernode/daemon/mgr/gc/gc_peer.go b/supernode/daemon/mgr/gc/gc_peer.go index b74d7b9ac..19e3ae005 100644 --- a/supernode/daemon/mgr/gc/gc_peer.go +++ b/supernode/daemon/mgr/gc/gc_peer.go @@ -27,8 +27,15 @@ import ( "github.com/sirupsen/logrus" ) +const ( + // gcPeersTimeout specifies the timeout for peers gc. + // If the actual execution time exceeds this threshold, a warning will be thrown. + gcPeersTimeout = 2.0 * time.Second +) + func (gcm *Manager) gcPeers(ctx context.Context) { var gcPeerCount int + startTime := time.Now() peerIDs := gcm.peerMgr.GetAllPeerIDs(ctx) for _, peerID := range peerIDs { @@ -51,7 +58,13 @@ func (gcm *Manager) gcPeers(ctx context.Context) { gcPeerCount++ } + // slow GC detected, report it with a log warning + if timeDuring := time.Since(startTime); timeDuring > gcPeersTimeout { + logrus.Warnf("gc peers:%d cost:%.3f", gcPeerCount, timeDuring.Seconds()) + } + gcm.metrics.gcPeersCount.WithLabelValues().Add(float64(gcPeerCount)) + logrus.Infof("gc peers: success to gc peer count(%d), remainder count(%d)", gcPeerCount, len(peerIDs)-gcPeerCount) } diff --git a/supernode/daemon/mgr/gc/gc_task.go b/supernode/daemon/mgr/gc/gc_task.go index 8804896f2..67660f391 100644 --- a/supernode/daemon/mgr/gc/gc_task.go +++ b/supernode/daemon/mgr/gc/gc_task.go @@ -26,8 +26,15 @@ import ( "github.com/sirupsen/logrus" ) +const ( + // gcTasksTimeout specifies the timeout for tasks gc. + // If the actual execution time exceeds this threshold, a warning will be thrown. + gcTasksTimeout = 2.0 * time.Second +) + func (gcm *Manager) gcTasks(ctx context.Context) { var removedTaskCount int + startTime := time.Now() // get all taskIDs and the corresponding accessTime taskAccessMap, err := gcm.taskMgr.GetAccessTime(ctx) @@ -53,7 +60,13 @@ func (gcm *Manager) gcTasks(ctx context.Context) { removedTaskCount++ } + // slow GC detected, report it with a log warning + if timeDuring := time.Since(startTime); timeDuring > gcTasksTimeout { + logrus.Warnf("gc tasks:%d cost:%.3f", removedTaskCount, timeDuring.Seconds()) + } + gcm.metrics.gcTasksCount.WithLabelValues().Add(float64(removedTaskCount)) + logrus.Infof("gc tasks: success to full gc task count(%d), remainder count(%d)", removedTaskCount, totalTaskNums-removedTaskCount) }