Net autotuner

If you wish to dynamically adjust the TCP stack, the congestion control algorithm, buffers, and queues based on real-time network metrics such as latency, packet loss, jitter, throughput, kernel drops, and out-of-order segments, this system is designed to optimize FreeBSD networking performance under diverse and changing conditions. Try FBSD-Net-Autotuner
 
New release - v1.5 — 2026-01-09

- Automatic selection of `TARGET_HOST` from public resolvers based on lowest RTT.
- Robust NIC speed detection with fallback to 1000 Mbps.
- Mbuf cluster and UDP buffer tuning based on NIC speed (1G, 10G, 40G).
- ISR tuning via `/boot/loader.conf` with comments and reboot requirement.
- Automatic comments with timestamp in `/etc/sysctl.conf` and `/boot/loader.conf` for traceability.

Try FBSD-Net-Autotuner
 
Thanks, but i don't need automatic. I need output :
- Put this is sysctl.conf
- Put this in rc.conf
- Put this in resolv.conf
- Etc ...
 
New release - v1.6 — 2026-01-11

- 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.
- Extended log output to include `finwait1_conns`, `finwait2_conns`, and `est_conns`.

Try FBSD-Net-Autotuner
 
New release - v1.7 — 2026-01-14

- Introduced adaptive congestion control (CC) 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.

Try FBSD-Net-Autotuner
 
New release - v1.8 — 2026-01-16

- Unified latency and jitter measurement:
— Now extracts avg RTT, stddev jitter, peak jitter (max−min), and packet loss in a single call to ping.
— Liminates redundant double ping calls, reducing system load and ensuring consistent metrics from the same sample set.
- Dual jitter metrics:
— Added stddev jitter (statistical variability).
— Added peak jitter (max RTT − min RTT) for visibility into extreme spikes.
— Both values are logged for richer diagnostics.
- Extended logging:
— Log entries now include jitter and jitter_peak alongside RTT, loss, throughput, and other metrics.
— Provides clearer insight into both average variability and worst‑case latency fluctuations.
- Adaptive tuning logic updated to use stddev jitter as the primary jitter metric for decisions.
- Code efficiency: reduced duplicate calls to ping, improving performance and accuracy.
- Corrected parsing of ping output to reliably capture min/avg/max/stddev values.
- Fixed issue where RTT and jitter previously reported identical values due to incorrect field extraction.
- Improved resilience against empty or malformed ping output lines.

Try FBSD-Net-Autotuner
 
network classification: fast RTT >= 30 ms && throughput < 200M veryfast RTT<30ms && throughput >= 1G

What if network has RTT >= 30ms && 200M < throughput < 1G? Where is it classified?

Even if I don't use it, I think its a good "README" on when/how to choose different algorithms.
One thing I think is dynamically switching affects only new TCP connections (I think this is true for stacks, not sure about the CC algorithms)
 
network classification: fast RTT >= 30 ms && throughput < 200M veryfast RTT<30ms && throughput >= 1G

What if network has RTT >= 30ms && 200M < throughput < 1G? Where is it classified?

Even if I don't use it, I think its a good "README" on when/how to choose different algorithms.
One thing I think is dynamically switching affects only new TCP connections (I think this is true for stacks, not sure about the CC algorithms)
If you want to dig into the details based on your network setup, just install it and give it a try. Even if it’s only for hands-on learning, you’ll pick up useful insights. Have fun experimenting!
 
  • Like
Reactions: mer
I just tried your software and tested performances with https://www.speedtest.net/.

VM FreeBSD 15.0-RELEASE non-tweaked:
Download: 629 Mbps
Upload: 449 Mbps
pings: 14, 404, 25 (idle, download and upload latencies).

VM FreeBSD 15.0-RELEASE tweaked with FBSD-Net-Autotuner:
Download: 571 Mbps
Upload: 522 Mbps
pings: 13, 116, 29

For reference:

VM Slackware:
Download: 929 Mbps
Upload: 437 Mbps
pings: 13, 249, 17

Windows 11 (not a VM):
Download: 944 Mbps
Upload: 786 Mbps
pings: 13, 26, 17

Freebsd 15.0-RELEASE (server):
Download: 720 Mbps
Upload: 538 Mbps
pings: 13, 38, 14

I saw a little decrease in download speed, but improvements in upload speed and download ping.
The interface that brings internet on the network is 1 Gbps, so it limits the speed anyway.

What puzzle me are the lines I discovered in /etc/sysctl.conf:
Code:
# Added by fbsd-net-autotuner on 2026-04-25 13:17:23
net.inet.tcp.functions_default=Added persistent net.inet.tcp.rexmit_min=100 to /etc/sysctl.conf
Added persistent net.inet.tcp.rexmit_slop=400 to /etc/sysctl.conf
Added persistent net.inet.tcp.rexmit_initial=2000 to /etc/sysctl.conf
freebsd
# Added by fbsd-net-autotuner on 2026-04-25 13:17:23
net.inet.tcp.recvspace=131072

What is this?
Code:
net.inet.tcp.functions_default=Added persistent net.inet.tcp.rexmit_min=100 to /etc/sysctl.conf
Added persistent net.inet.tcp.rexmit_slop=400 to /etc/sysctl.conf
Added persistent net.inet.tcp.rexmit_initial=2000 to /etc/sysctl.conf
freebsd
 
Other test on a 15.0-RELEASE bare metal machine:

Non-tweaked:
Download: 927 Mbps
Upload: 677 Mbps
pings: 13, 29, 15

Code:
# /root/bin/fbsd-net-autotuner

Starting network autotuner (host=1.1.1.1, iface=bridgeLOCAL, interval=60s)
Configured net.isr.defaultqlimit=2048 (requires reboot)
Configured net.isr.maxqlimit=16384 (requires reboot)
Configured net.isr.maxthreads=4 (requires reboot)
Configured net.isr.bindthreads=1 (requires reboot)
Applied net.isr.dispatch=direct
kern.ipc.nmbclusters: 1013118
sysctl: kern.ipc.nmbclusters=262144: Invalid argument
Applied kern.ipc.nmbclusters=262144
kern.ipc.nmbjumbop: 506559
sysctl: kern.ipc.nmbjumbop=262144: Invalid argument
Applied kern.ipc.nmbjumbop=262144
kern.ipc.nmbjumbo9: 150091
sysctl: kern.ipc.nmbjumbo9=65536: Invalid argument
Applied kern.ipc.nmbjumbo9=65536
kern.ipc.nmbjumbo16: 84426
sysctl: kern.ipc.nmbjumbo16=32768: Invalid argument
Applied kern.ipc.nmbjumbo16=32768
net.inet.udp.recvspace: 42080 -> 65536
Applied net.inet.udp.recvspace=65536
So there are some problems.

Added in /boot/loader.conf:
Code:
# Added by fbsd-net-autotuner (requires reboot) on 2026-04-25 17:20:22
net.isr.defaultqlimit=2048
# Added by fbsd-net-autotuner (requires reboot) on 2026-04-25 17:20:22
net.isr.maxqlimit=16384
# Added by fbsd-net-autotuner (requires reboot) on 2026-04-25 17:20:22
net.isr.maxthreads=4
# Added by fbsd-net-autotuner (requires reboot) on 2026-04-25 17:20:22
net.isr.bindthreads=1

Added in /etc/sysctl.conf (there is no comment specifying the source):
Code:
net.isr.dispatch=direct
kern.ipc.nmbclusters=262144
kern.ipc.nmbjumbop=262144
kern.ipc.nmbjumbo9=65536
kern.ipc.nmbjumbo16=32768
net.inet.udp.recvspace=65536

Reboot. Test anew.
Tweaked:
Download: 932 Mbps
Upload: 668 Mbps
pings: 13, 31, 15

Conclusion: no change.
 
I just tried your software and tested performances with https://www.speedtest.net/.

VM FreeBSD 15.0-RELEASE non-tweaked:
Download: 629 Mbps
Upload: 449 Mbps
pings: 14, 404, 25 (idle, download and upload latencies).

VM FreeBSD 15.0-RELEASE tweaked with FBSD-Net-Autotuner:
Download: 571 Mbps
Upload: 522 Mbps
pings: 13, 116, 29

For reference:

VM Slackware:
Download: 929 Mbps
Upload: 437 Mbps
pings: 13, 249, 17

Windows 11 (not a VM):
Download: 944 Mbps
Upload: 786 Mbps
pings: 13, 26, 17

Freebsd 15.0-RELEASE (server):
Download: 720 Mbps
Upload: 538 Mbps
pings: 13, 38, 14

I saw a little decrease in download speed, but improvements in upload speed and download ping.
The interface that brings internet on the network is 1 Gbps, so it limits the speed anyway.

What puzzle me are the lines I discovered in /etc/sysctl.conf:
Code:
# Added by fbsd-net-autotuner on 2026-04-25 13:17:23
net.inet.tcp.functions_default=Added persistent net.inet.tcp.rexmit_min=100 to /etc/sysctl.conf
Added persistent net.inet.tcp.rexmit_slop=400 to /etc/sysctl.conf
Added persistent net.inet.tcp.rexmit_initial=2000 to /etc/sysctl.conf
freebsd
# Added by fbsd-net-autotuner on 2026-04-25 13:17:23
net.inet.tcp.recvspace=131072

What is this?
Code:
net.inet.tcp.functions_default=Added persistent net.inet.tcp.rexmit_min=100 to /etc/sysctl.conf
Added persistent net.inet.tcp.rexmit_slop=400 to /etc/sysctl.conf
Added persistent net.inet.tcp.rexmit_initial=2000 to /etc/sysctl.conf
freebsd
I believe tests should be conducted under the strictest possible equality of conditions: first comparing all OS in VM, and then comparing all OS on bare metal both without extra network loads and after with additional network loads (such as multiple downloads and uploads using various protocols like HTTP, FTP, P2P, etc.). The differences in performance on fast networks during simple downloads are not particularly significant.

The entries written in /etc/sysctl.conf should have looked like this:

# Added by fbsd-net-autotuner on 2026-04-24 11:10:15
net.inet.tcp.rexmit_min=100
# Added by fbsd-net-autotuner on 2026-04-24 11:10:15
net.inet.tcp.rexmit_slop=400
# Added by fbsd-net-autotuner on 2026-04-24 11:10:15
net.inet.tcp.rexmit_initial=2000
# Added by fbsd-net-autotuner on 2026-04-24 17:28:48
net.inet.tcp.rack.tlp.reorder_thresh=4
# Added by fbsd-net-autotuner on 2026-04-24 17:28:48
net.inet.tcp.rack.tlp.reorder_fade=30000000
# Added by fbsd-net-autotuner on 2026-04-24 17:28:48
net.inet.tcp.rack.tlp.pktdelay=3000
# Added by fbsd-net-autotuner on 2026-04-24 17:28:48
net.inet.tcp.rack.tlp.rtt_tlp_thresh=2
# Added by fbsd-net-autotuner on 2026-04-24 17:28:48
net.inet.tcp.rack.tlp.limit=3
 
Other test on a 15.0-RELEASE bare metal machine:

Non-tweaked:
Download: 927 Mbps
Upload: 677 Mbps
pings: 13, 29, 15

Code:
# /root/bin/fbsd-net-autotuner

Starting network autotuner (host=1.1.1.1, iface=bridgeLOCAL, interval=60s)
Configured net.isr.defaultqlimit=2048 (requires reboot)
Configured net.isr.maxqlimit=16384 (requires reboot)
Configured net.isr.maxthreads=4 (requires reboot)
Configured net.isr.bindthreads=1 (requires reboot)
Applied net.isr.dispatch=direct
kern.ipc.nmbclusters: 1013118
sysctl: kern.ipc.nmbclusters=262144: Invalid argument
Applied kern.ipc.nmbclusters=262144
kern.ipc.nmbjumbop: 506559
sysctl: kern.ipc.nmbjumbop=262144: Invalid argument
Applied kern.ipc.nmbjumbop=262144
kern.ipc.nmbjumbo9: 150091
sysctl: kern.ipc.nmbjumbo9=65536: Invalid argument
Applied kern.ipc.nmbjumbo9=65536
kern.ipc.nmbjumbo16: 84426
sysctl: kern.ipc.nmbjumbo16=32768: Invalid argument
Applied kern.ipc.nmbjumbo16=32768
net.inet.udp.recvspace: 42080 -> 65536
Applied net.inet.udp.recvspace=65536
So there are some problems.

Added in /boot/loader.conf:
Code:
# Added by fbsd-net-autotuner (requires reboot) on 2026-04-25 17:20:22
net.isr.defaultqlimit=2048
# Added by fbsd-net-autotuner (requires reboot) on 2026-04-25 17:20:22
net.isr.maxqlimit=16384
# Added by fbsd-net-autotuner (requires reboot) on 2026-04-25 17:20:22
net.isr.maxthreads=4
# Added by fbsd-net-autotuner (requires reboot) on 2026-04-25 17:20:22
net.isr.bindthreads=1

Added in /etc/sysctl.conf (there is no comment specifying the source):
Code:
net.isr.dispatch=direct
kern.ipc.nmbclusters=262144
kern.ipc.nmbjumbop=262144
kern.ipc.nmbjumbo9=65536
kern.ipc.nmbjumbo16=32768
net.inet.udp.recvspace=65536

Reboot. Test anew.
Tweaked:
Download: 932 Mbps
Upload: 668 Mbps
pings: 13, 31, 15

Conclusion: no change.
I don't know why these error messages are appearing:

sysctl: kern.ipc...: Invalid argument

I see there are some kernel variables without comments. I need to fix that. Thanks for testing it and sharing the results.
 
Well, you have some bugs. Correct them and I will test again.
Your script is sometimes writing garbage in essential config file. Don't take that as a little problem.

I compared OS in a VM and OS in a bare metal machine, I'm not mixing them.
It's only before and after running your software.

This kind of test is using all the chain between the OS and the internet servers, so it's somewhat complete.
 
Quick look at the code it seems as if the "log" is winding up in sysctl.conf (line 194) instead of the "echo" at line 192 based on what Emrion has posted.
These lines write in /etc/sysctl.conf
192 echo "# Added by fbsd-net-autotuner on $(date '+%F %T')" >> /etc/sysctl.conf
193 echo "${key}=${val}" >> /etc/sysctl.conf

the next line is for write in the log
194 log "Added persistent $key=$val to /etc/sysctl.conf"
 
New release - v2.0 — 2026-04-25

- Automatic backup creation for "/etc/sysctl.conf" and "/boot/loader.conf" for safe rollback.
- Resolved problem with un‑commented variables in "/etc/sysctl.conf" and "/boot/loader.conf".

Try FBSD-Net-Autotuner
 
Well, you have some bugs. Correct them and I will test again.
Your script is sometimes writing garbage in essential config file. Don't take that as a little problem.

I compared OS in a VM and OS in a bare metReady for testal machine, I'm not mixing them.
It's only before and after running your software.

This kind of test is using all the chain between the OS and the internet servers, so it's somewhat complete.

Ready for test
 
Back
Top