Skip to content

Commit 93030e9

Browse files
committed
Add WAN link speed override for Adaptive SQM (#565)
* Add WAN link speed override for Adaptive SQM Allow users to override the auto-detected WAN link speed, which is used as the shaping ceiling (with 2% HTB headroom). This is needed when the physical SFP supports a higher speed than what UniFi/ethtool reports (e.g., 2.5G SFP in a UXG-Fiber reporting as 1G). The override is nullable - when unset, behavior is identical to before (auto-detected speed from the gateway port). The detected value shows as placeholder text so the user knows what was auto-detected. * Move Speed Margin to end of Calculated SQM Parameters grid * Comment out Smart Queue download rate pre-deploy check UniFi Network never clobbers our TC config once Adaptive SQM takes over - the qdiscs get fully replaced by our scripts. The rate shown in the UniFi UI becomes irrelevant after deployment. * Clear link speed override when switching WAN interfaces * Fix link speed override not persisting on update The repository's upsert method copies properties individually for existing rows. LinkSpeedOverrideMbps was missing from the update path, so it was always written as null on save. * Base speedtest probe rate on max shaping rate instead of link speed The probe rate was 5% above max(AbsoluteMax, LinkSpeed), which could overshoot the physical line rate and cause packet loss at the NIC level where there is no AQM. Now it is 3% above MaxDownloadSpeed - the highest rate the system will ever shape to - which keeps it just above the shaper ceiling without exceeding what the wire can drain. * Restore 5 KB burst tuning for HTB classes 5 KB burst eliminates downstream drop_overmemory for bulk flows at gig speeds. Was reverted to stock 1500b pending per-connection testing but the 2.5G link speed override makes this viable again. * Restore original scaled burst function (rate * 5, clamped 1500-5000)
1 parent 6b0ec35 commit 93030e9

9 files changed

Lines changed: 2178 additions & 63 deletions

File tree

src/NetworkOptimizer.Sqm/Models/SqmConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public class SqmConfiguration
6666

6767
/// <summary>
6868
/// Rate to set on TC during the speedtest probe so the measurement runs unshaped.
69-
/// 5% above the larger of AbsoluteMax or physical link speed - safely above anything
70-
/// the connection can actually deliver, so TC never constrains the test.
69+
/// 3% above MaxDownloadSpeed (the highest rate the system will ever shape to).
70+
/// Just enough headroom that TC stays transparent without overshooting physical line rate.
7171
/// </summary>
7272
public int SpeedtestProbeRateMbps =>
73-
Math.Max(100, (int)(Math.Max(AbsoluteMaxDownloadSpeed, WanLinkSpeedMbps ?? 0) * 1.05));
73+
Math.Max(100, (int)(MaxDownloadSpeed * 1.03));
7474

7575
/// <summary>
7676
/// Overhead multiplier for speedtest results (1.05 = 5% overhead)

src/NetworkOptimizer.Sqm/ScriptGenerator.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ private string GenerateSpeedtestScript(Dictionary<string, string> baseline)
278278
sb.AppendLine(GetTcUpdateFunction());
279279
sb.AppendLine();
280280

281-
// Set probe rate slightly above line rate before speedtest so TC never engages
282-
sb.AppendLine("# Set SQM to probe rate (~5% above line rate) before speedtest for truly unshaped measurement");
281+
// Set probe rate slightly above max shaping rate before speedtest so TC never engages
282+
sb.AppendLine("# Set SQM to probe rate (3% above max shaping rate) before speedtest for unshaped measurement");
283283
sb.AppendLine("update_all_tc_classes $IFB_DEVICE $SPEEDTEST_PROBE_RATE");
284284
sb.AppendLine("# Upstream: shape rate if enabled, otherwise just tune performance params");
285285
sb.AppendLine("if [ \"$SHAPE_UPLOAD\" = \"1\" ]; then");
@@ -572,16 +572,14 @@ private string GeneratePingScript(Dictionary<string, string> baseline)
572572
/// </summary>
573573
private string GetTcUpdateFunction()
574574
{
575-
return @"# Burst size tuning history:
576-
# Config E testing showed 5KB burst eliminates downstream drop_overmemory for bulk
577-
# flows at gig speeds, but 8KB+ creates bursty HTB send patterns (dump at wire rate,
578-
# pause for token refill) that increase queue depth variance in fq_codel - shows up
579-
# as latency jitter under load even though fq_codel is working correctly.
580-
# Whether higher burst helps depends on ISP policing/shaping - some ISPs police with
581-
# token bucket and penalize bursts above stock, others are fine with 5KB.
582-
# Reverted to stock 1500b pending per-connection configurability.
575+
return @"# 5KB burst eliminates downstream drop_overmemory for bulk flows at gig speeds.
576+
# 8KB+ creates bursty HTB send patterns that increase queue depth variance in fq_codel.
583577
calc_burst() {
584-
echo ""1500""
578+
local rate_mbps=$1
579+
local burst=$((rate_mbps * 5))
580+
[ ""$burst"" -lt 1500 ] && burst=1500
581+
[ ""$burst"" -gt 5000 ] && burst=5000
582+
echo ""$burst""
585583
}
586584
587585
# Calculate fq_codel memory_limit scaled to rate (prevents drop_overmemory at high speeds)

0 commit comments

Comments
 (0)