]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Expose TORRENT_WEBSEED_REQUEST_CHUNK_SIZE
authorMatt Joiner <anacrolix@gmail.com>
Tue, 5 Aug 2025 12:40:18 +0000 (22:40 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 5 Aug 2025 12:40:18 +0000 (22:40 +1000)
env.go
webseed-requesting.go

diff --git a/env.go b/env.go
index c8759d6eabd837b29a856d1255065b70491ef97b..996e1a8fde750fe3bf2f05d5bdccce821e694e08 100644 (file)
--- a/env.go
+++ b/env.go
@@ -8,12 +8,20 @@ import (
        "golang.org/x/exp/constraints"
 )
 
-func initIntFromEnv[T constraints.Integer](key string, defaultValue T, bitSize int) T {
+func initIntFromEnv[T constraints.Signed](key string, defaultValue T, bitSize int) T {
+       return strconvFromEnv(key, defaultValue, bitSize, strconv.ParseInt)
+}
+
+func initUIntFromEnv[T constraints.Unsigned](key string, defaultValue T, bitSize int) T {
+       return strconvFromEnv(key, defaultValue, bitSize, strconv.ParseUint)
+}
+
+func strconvFromEnv[T, U constraints.Integer](key string, defaultValue T, bitSize int, conv func(s string, base, bitSize int) (U, error)) T {
        s := os.Getenv(key)
        if s == "" {
                return defaultValue
        }
-       i64, err := strconv.ParseInt(s, 10, bitSize)
+       i64, err := conv(s, 10, bitSize)
        panicif.Err(err)
        return T(i64)
 }
index d41d909c9ec3ed2c9737e90dca34995086f47407..d290d5253c82ca471647b4a2ca89e712b30065b8 100644 (file)
@@ -233,8 +233,9 @@ func (t *Torrent) getWebseedRequestEnd(begin RequestIndex, debugLogger *slog.Log
        return end
 }
 
-// Cloudflare caches up to 512 MB responses by default. This is also an alignment.
-var webseedRequestChunkSize uint64 = 256 << 20
+// Cloudflare caches up to 512 MB responses by default. This is also an alignment. Making this
+// smaller will allow requests to complete a smaller set of files faster.
+var webseedRequestChunkSize = initUIntFromEnv[uint64]("TORRENT_WEBSEED_REQUEST_CHUNK_SIZE", 64<<20, 64)
 
 func (t *Torrent) endRequestForAlignedWebseedResponse(start RequestIndex) RequestIndex {
        end := min(t.maxEndRequest(), nextMultiple(start, t.chunksPerAlignedWebseedResponse()))