Dynamically adjusts the TCP stack, congestion control algorithm, buffers, and queues based on real-time network metrics such as latency, packet loss, jitter, throughput, queue drops, out-of-order segments, FIN-WAIT-1/FIN-WAIT-2 sockets, and NIC speed. It is designed to optimize FreeBSD networking performance in diverse and changing conditions.
sudo fbsd-net-autotuner [-d] [-l]-d→ Add date and time to the event log.-l→ Log events to the file/var/log/fbsd-net-autotuner.log.
You can override these defaults by exporting environment variables before running the script:
| Variable | Default | Description |
|---|---|---|
TARGET_HOST |
auto | Host used for ping measurements. Selected dynamically from public resolvers (1.1.1.1, 1.0.0.1, 8.8.8.8, 8.8.4.4, 9.9.9.9) based on lowest RTT. |
IFACE |
auto | Network interface to monitor. Auto-detected from default route or falls back to the first interface. |
PING_COUNT |
10 | Number of pings per round |
INTERVAL_SEC |
60 | Interval between measurements (sec) |
- Auto-selects the most responsive
TARGET_HOSTfrom a resilient list of public resolvers. - Detects NIC speed robustly (validates numeric values, defaults to 1000 Mbps).
- Classifies network conditions into tiers:
very_slow,slow,medium,fast,very_fast. - Dynamically selects TCP congestion control algorithm and stack:
- Algorithms:
cubic,chd,htcp,dctcp,cdg,vegas. - Stacks:
freebsd,bbr,rack.
- Algorithms:
- Adjusts:
- Buffer sizes (recv/send,
maxsockbuf). - ECN (Explicit Congestion Notification).
- Keepalive.
- Delayed ACK (tier-based with jitter override).
- SACK (Selective ACK).
- Initial congestion window (
initcwnd_segments). - TSO (toggle based on kernel drops).
- ABC (
net.inet.tcp.abc_l_var) → controls cwnd growth aggressiveness. - Reassembly queue (
net.inet.tcp.reass.maxqueuelen) → adapts to out-of-order segments. - Enables
net.inet.tcp.fast_finwait2_recycleonly if FIN-WAIT-2 exceeds 5% of ESTABLISHED.
- Buffer sizes (recv/send,
- Monitors:
- RTT (latency).
- Packet loss.
- Jitter.
- Throughput.
- Kernel
intr_queue_drops. - Out-of-order segments.
- FIN-WAIT-1 sockets (diagnostic only, logged).
- FIN-WAIT-2 sockets (dynamic tuning).
- Tunes mbuf clusters and jumbo buffers based on NIC speed (1G, 10G, 40G).
- Tunes UDP receive buffer size based on NIC speed.
- Applies changes immediately via
sysctland persists them in/etc/sysctl.conf. - Configures ISR tunables (
maxthreads,bindthreads,defaultqlimit,maxqlimit) via/boot/loader.conf(requires reboot). - Adds automatic comments with timestamp in
/etc/sysctl.confand/boot/loader.confto mark lines generated by the autotuner for traceability. - Flexible logging:
- Terminal only.
- Terminal + date.
- File logging.
The script evaluates RTT (latency), packet loss, throughput, and also jitter/out-of-order to classify the connection:
| Tier | Conditions (examples) | Behavior |
|---|---|---|
| very_slow | RTT ≥ 250ms or loss ≥ 5% | Conservative buffers, Vegas/CHD |
| slow | RTT ≥ 150ms or loss ≥ 2% or throughput < 2 Mbps | Larger buffers, Vegas/HTCP |
| medium | RTT ≥ 80ms or throughput < 20 Mbps | Balanced buffers, HTCP/Cubic |
| fast | RTT ≥ 30ms or throughput < 200 Mbps | Aggressive buffers, DCTCP/HTCP |
| very_fast | RTT < 30ms and throughput ≥ 1 Gbps | Maximum buffers, BBR/RACK |
- FreeBSD system with root privileges.
- Utilities:
sysctl,ping,netstat. - Reboot required for loader.conf tunables (
net.isr.*).
The net-autotuner continuously measures and logs the following metrics to guide dynamic tuning decisions:
| Metric | Source/Method | Purpose / Usage |
|---|---|---|
| RTT (latency) | ping statistics |
Classify network tier (very_slow → very_fast). |
| Packet loss | ping statistics |
Detect unstable links, adjust buffers and congestion control. |
| Jitter | Min/Max RTT difference | Override delayed ACK when jitter is high. |
| Throughput | netstat -I <iface> bytes per second |
Classify tier, estimate Bandwidth-Delay Product (BDP). |
| Intr queue drops | sysctl net.inet.ip.intr_queue_drops |
Increase intr_queue_maxlen, toggle TSO if persistent. |
| Out-of-order segs | netstat -s |
Adjust TCP reassembly queue length (reass.maxqueuelen). |
| FIN-WAIT-1 conns | `netstat -an | grep FIN_WAIT_1` |
| FIN-WAIT-2 conns | `netstat -an | grep FIN_WAIT_2` |
| ESTABLISHED conns | `netstat -an | grep ESTABLISHED` |
- The script runs in an infinite loop. Stop it with
Ctrl+C. - Ensure
/etc/sysctl.confand/boot/loader.confis writable for persistence. - Ensure that the congestion control algorithms (cubic, chd, htcp, dctcp, cdg, vegas) can load.
- Ensure that the TCP stacks (freebsd, bbr, rack) can load.
delayed_acktier setting may be overridden by jitter detection.abc_l_varandreass.maxqueuelenare tuned dynamically based on stability and out-of-order metrics.- FIN-WAIT-1: monitored only, useful for diagnostics, no sysctl tuning available.
- FIN-WAIT-2: dynamically managed;
fast_finwait2_recycleenabled only if >5% of ESTABLISHED. - All metrics are logged in extended output for traceability and performance analysis.
Run with logging to file and timestamps:
sudo fbsd-net-autotuner -d -lClone the repository and run the installer:
git clone https://github.com/geobarrod/FBSD-Net-Autotuner.git
cd FBSD-Net-Autotuner
sudo make installTo remove the fbsd-net-autotuner and service:
cd FBSD-Net-Autotuner
sudo make uninstall- Initial release of FreeBSD Network Autotuner.
- Added BDP estimation and buffer tuning.
- Added jitter measurement and override for delayed ACK.
- Added out-of-order segment measurement and dynamic tuning for ABC and reassembly queue.
- Refactored
loss_pctextraction. - Improved persistence logic in
set_sysctl_if_needed.
- Automatic selection of
TARGET_HOST. - Robust NIC speed detection.
- Mbuf cluster and UDP buffer tuning.
- ISR tuning via
/boot/loader.conf.
- Added monitoring of FIN-WAIT-1 sockets as a diagnostic metric (logged, no dynamic tuning).
- Integrated dynamic tuning for FIN-WAIT-2 sockets:
- Uses
net.inet.tcp.fast_finwait2_recycle. - Enabled only if FIN-WAIT-2 exceeds 5% of ESTABLISHED connections.
- Restores default when ratio ≤5%.
- Idempotent logging: changes are logged only when state transitions occur.
- Uses
- Extended log output to include
finwait1_conns,finwait2_conns, andest_conns.
- Introduced adaptive congestion control selection:
- Chooses CC algorithm dynamically (Vegas, HTCP, DCTCP, CDG, CHD/HD, Cubic) based on RTT, loss, jitter, and throughput.
- Introduced adaptive TCP stack selection:
- Chooses stack dynamically (BBR, RACK, FreeBSD) based on throughput, RTT, loss, and jitter.