]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add TORRENT_MAX_ACTIVE_PIECE_HASHERS
authorMatt Joiner <anacrolix@gmail.com>
Tue, 5 Aug 2025 09:54:51 +0000 (19:54 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 5 Aug 2025 09:54:51 +0000 (19:54 +1000)
client.go
env.go
webseed-requesting.go

index 4c3c6dc276f2a5bb152709f57408a4fb7a19f7b2..f67f2a89f6fc279ed1ba39fdc2f16a4a4ed0e1ca 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1962,8 +1962,10 @@ func (cl *Client) checkConfig() error {
        return nil
 }
 
+var maxActivePieceHashers = initIntFromEnv("TORRENT_MAX_ACTIVE_PIECE_HASHERS", runtime.NumCPU(), 0)
+
 func (cl *Client) maxActivePieceHashers() int {
-       return runtime.NumCPU()
+       return maxActivePieceHashers
 }
 
 func (cl *Client) belowMaxActivePieceHashers() bool {
diff --git a/env.go b/env.go
index 10cbafc73d7b9237c864a6f3c625bf9c74366b21..c8759d6eabd837b29a856d1255065b70491ef97b 100644 (file)
--- a/env.go
+++ b/env.go
@@ -1 +1,19 @@
 package torrent
+
+import (
+       "os"
+       "strconv"
+
+       "github.com/anacrolix/missinggo/v2/panicif"
+       "golang.org/x/exp/constraints"
+)
+
+func initIntFromEnv[T constraints.Integer](key string, defaultValue T, bitSize int) T {
+       s := os.Getenv(key)
+       if s == "" {
+               return defaultValue
+       }
+       i64, err := strconv.ParseInt(s, 10, bitSize)
+       panicif.Err(err)
+       return T(i64)
+}
index a4cc17d5d4ef8701190399b6fd06e689859924e1..698eea7912de401ac6c368a9e03932847880618e 100644 (file)
@@ -9,7 +9,6 @@ import (
        "maps"
        "os"
        "runtime/pprof"
-       "strconv"
        "strings"
        "sync"
        "time"
@@ -24,13 +23,7 @@ import (
        "github.com/anacrolix/torrent/webseed"
 )
 
-var webseedHostRequestConcurrency int
-
-func init() {
-       i64, err := strconv.ParseInt(cmp.Or(os.Getenv("TORRENT_WEBSEED_HOST_REQUEST_CONCURRENCY"), "10"), 10, 0)
-       panicif.Err(err)
-       webseedHostRequestConcurrency = int(i64)
-}
+var webseedHostRequestConcurrency = initIntFromEnv("TORRENT_WEBSEED_HOST_REQUEST_CONCURRENCY", 10, 0)
 
 type (
        webseedHostKey       string