Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
feature: add a warn log for long gc duration
Browse files Browse the repository at this point in the history
Signed-off-by: SataQiu <[email protected]>
  • Loading branch information
SataQiu committed Oct 17, 2019
1 parent e6351e3 commit f1a4882
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dfget/core/downloader/p2p_downloader/power_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions supernode/daemon/mgr/gc/gc_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down
13 changes: 13 additions & 0 deletions supernode/daemon/mgr/gc/gc_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down

0 comments on commit f1a4882

Please sign in to comment.