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 {
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)
+}
"maps"
"os"
"runtime/pprof"
- "strconv"
"strings"
"sync"
"time"
"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