From 304ad7f308711c5d9c8397aa1d5d737e596a0574 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Fri, 20 Feb 2026 11:05:53 -0500 Subject: [PATCH] qbt: tweak --- configuration.nix | 25 +++++++++++++++++++++++++ services/qbittorrent.nix | 9 +++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/configuration.nix b/configuration.nix index 7ba9c5e..1a7af64 100644 --- a/configuration.nix +++ b/configuration.nix @@ -132,6 +132,31 @@ compressor = "zstd"; supportedFilesystems = [ "f2fs" ]; }; + + # BBR congestion control handles variable-latency VPN connections much + # better than CUBIC by probing bandwidth continuously rather than + # reacting to packet loss. + kernelModules = [ "tcp_bbr" ]; + + kernel.sysctl = { + # Use BBR + fair queuing for smooth throughput through the WireGuard VPN + "net.core.default_qdisc" = "fq"; + "net.ipv4.tcp_congestion_control" = "bbr"; + + # Disable slow-start after idle: prevents TCP from resetting window + # size on each burst cycle (the primary cause of the 0 -> 40 MB/s spikes) + "net.ipv4.tcp_slow_start_after_idle" = 0; + + # Larger socket buffers to accommodate the VPN bandwidth-delay product + # (22ms RTT * target throughput). Current 2.5MB max is too small. + "net.core.rmem_max" = 16777216; + "net.core.wmem_max" = 16777216; + "net.ipv4.tcp_rmem" = "4096 87380 16777216"; + "net.ipv4.tcp_wmem" = "4096 65536 16777216"; + + # Higher backlog for the large number of concurrent torrent connections + "net.core.netdev_max_backlog" = 5000; + }; }; environment.etc = { diff --git a/services/qbittorrent.nix b/services/qbittorrent.nix index 587d671..16a8d34 100644 --- a/services/qbittorrent.nix +++ b/services/qbittorrent.nix @@ -48,7 +48,7 @@ serverConfig.BitTorrent = { Session = { - MaxConnectionsPerTorrent = 100; + MaxConnectionsPerTorrent = 50; MaxUploadsPerTorrent = 10; MaxConnections = -1; MaxUploads = -1; @@ -57,7 +57,7 @@ # queueing QueueingSystemEnabled = true; - MaxActiveDownloads = 8; # num of torrents that can download at the same time + MaxActiveDownloads = 5; # keep focused: fewer torrents, each gets more bandwidth MaxActiveUploads = -1; MaxActiveTorrents = -1; IgnoreSlowTorrentsForQueueing = true; @@ -84,8 +84,9 @@ inherit (config.services.qbittorrent.serverConfig.Preferences.Downloads) TempPath; TempPathEnabled = true; - # how many connections per sec - ConnectionSpeed = 300; + # Reduced from 300: that rate floods the VPN tunnel with SYN packets, + # starving actual data transfer and causing the 0->40MB/s spike pattern. + ConnectionSpeed = 20; # Automatic Torrent Management: use category save paths for new torrents DisableAutoTMMByDefault = false;