]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Include webseed update reason and some extra debug stuff
authorMatt Joiner <anacrolix@gmail.com>
Mon, 4 Aug 2025 12:15:41 +0000 (22:15 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 4 Aug 2025 12:15:41 +0000 (22:15 +1000)
webseed-peer.go
webseed-requesting.go
webseed/client.go

index 3a407d5fdb07c6ea6098099007c4d0a1d59d3d6c..230df90a6c27e750d5be25b881013587dc53dd6b 100644 (file)
@@ -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()
index b746850ba0a73de90e70c24068ed9b1b99fe7836..a28244b71029795340d96dc6f63d80759da4903d 100644 (file)
@@ -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).
index e04e82685c506ec8f91f3b4552f19c55afc65a93..2076e2c5f838d92cc4b6f85299c445f754533bb9 100644 (file)
@@ -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"))