From 3ace196a0ee270f8705328fbd70c30fd9533a744 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 4 Aug 2025 22:15:41 +1000 Subject: [PATCH] Include webseed update reason and some extra debug stuff --- webseed-peer.go | 5 +++-- webseed-requesting.go | 16 ++++++++-------- webseed/client.go | 5 +++++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/webseed-peer.go b/webseed-peer.go index 3a407d5f..230df90a 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -54,7 +54,8 @@ func (me *webseedPeer) isLowOnRequests() bool { // Webseed requests are issued globally so per-connection reasons or handling make no sense. func (me *webseedPeer) onNeedUpdateRequests(reason updateRequestReason) { - me.peer.cl.scheduleImmediateWebseedRequestUpdate(reason) + // Too many reasons here: Can't predictably determine when we need to rerun updates. + //me.peer.cl.scheduleImmediateWebseedRequestUpdate(reason) } func (me *webseedPeer) expectingChunks() bool { @@ -215,7 +216,7 @@ func (ws *webseedPeer) runRequest(webseedRequest *webseedRequest) { // Delete this entry after waiting above on an error, to prevent more requests. ws.deleteActiveRequest(webseedRequest) cl := ws.peer.cl - if err == nil && cl.numWebSeedRequests[ws.hostKey] <= webseedHostRequestConcurrency/2 { + if err == nil && cl.numWebSeedRequests[ws.hostKey] == webseedHostRequestConcurrency/2 { cl.updateWebseedRequestsWithReason("webseedPeer request completed") } locker.Unlock() diff --git a/webseed-requesting.go b/webseed-requesting.go index b746850b..a28244b7 100644 --- a/webseed-requesting.go +++ b/webseed-requesting.go @@ -45,13 +45,6 @@ type ( - Initiate missing requests that fit into the available limits. */ func (cl *Client) updateWebseedRequests() { - if webseed.PrintDebug { - started := time.Now() - defer func() { - now := time.Now() - fmt.Printf("%v: updateWebseedRequests took %v\n", time.Now(), now.Sub(started)) - }() - } type aprioriMapValue struct { startIndex RequestIndex webseedRequestOrderValue @@ -454,8 +447,15 @@ func (cl *Client) updateWebseedRequestsAndResetTimer() { pprof.Do(context.Background(), pprof.Labels( "reason", string(cl.webseedUpdateReason), ), func(_ context.Context) { - cl.updateWebseedRequests() + started := time.Now() + reason := cl.webseedUpdateReason cl.webseedUpdateReason = "" + cl.updateWebseedRequests() + panicif.NotZero(cl.webseedUpdateReason) + if webseed.PrintDebug { + now := time.Now() + fmt.Printf("%v: updateWebseedRequests took %v (reason: %v)\n", now, now.Sub(started), reason) + } }) // Timer should always be stopped before the last call. TODO: Don't reset timer if there's // nothing to do (no possible requests in update). diff --git a/webseed/client.go b/webseed/client.go index e04e8268..2076e2c5 100644 --- a/webseed/client.go +++ b/webseed/client.go @@ -220,6 +220,11 @@ func (me *Client) recvPartResult(ctx context.Context, w io.Writer, part requestP return ErrBadResponse{"resp status ok but requested range", resp} } if discard != 0 { + if PrintDebug { + fmt.Printf("resp status ok but requested range [url=%q, range=%q]", + part.req.URL, + part.req.Header.Get("Range")) + } log.Printf("resp status ok but requested range [url=%q, range=%q]", part.req.URL, part.req.Header.Get("Range")) -- 2.51.0