client-tracker-announcer.go | 16 +++++++++++++--- diff --git a/client-tracker-announcer.go b/client-tracker-announcer.go index c6b98d019a140b35b8fd60e5bc5c5db9103d48f4..a87bd39fbcda1f2fc7baf86898e9e09e4b523429 100644 --- a/client-tracker-announcer.go +++ b/client-tracker-announcer.go @@ -14,6 +14,7 @@ g "github.com/anacrolix/generics" analog "github.com/anacrolix/log" "github.com/anacrolix/missinggo/v2/panicif" + "github.com/anacrolix/torrent/internal/amortize" "github.com/anacrolix/torrent/internal/extracmp" "github.com/anacrolix/torrent/internal/indexed" "github.com/anacrolix/torrent/internal/mytimer" @@ -27,6 +28,7 @@ // we can get websocket trackers to use this too. type regularTrackerAnnounceDispatcher struct { torrentClient *Client logger *slog.Logger + slow amortize.Value trackerClients map[trackerAnnouncerKey]*trackerClientsValue announceStates map[torrentTrackerAnnouncerKey]*announceState @@ -416,9 +418,17 @@ } // The progress method, called by the timer. func (me *regularTrackerAnnounceDispatcher) step() mytimer.TimeValue { - for t := range me.pendingTorrentInputUpdates { - me.updateTorrentInput(t) - delete(me.pendingTorrentInputUpdates, t) + if len(me.pendingTorrentInputUpdates) != 0 { + started := time.Now() + inputs := len(me.pendingTorrentInputUpdates) + for t := range me.pendingTorrentInputUpdates { + me.updateTorrentInput(t) + delete(me.pendingTorrentInputUpdates, t) + } + since := time.Since(started) + if since >= 20*time.Millisecond && me.slow.Try() { + me.logger.Warn("updating torrent inputs was slow", "took", since, "torrents", inputs) + } } me.dispatchAnnounces() // We *are* the Sen... Timer.