cat << 'EOF' > /etc/sysctl.d/99-latency.conf # --- Queueing & TCP Congestion --- # Pair CAKE/FQ with BBR for minimal bufferbloat and fast recovery net.core.default_qdisc = cake net.ipv4.tcp_congestion_control = bbr # --- Reduce Bufferbloat & Latency Spikes --- # Shrink max backlog queues to drop/process stale packets faster net.core.netdev_max_backlog = 1000 net.ipv4.tcp_max_syn_backlog = 1024 net.ipv4.tcp_max_tw_buckets = 10000 # --- Fast Packet Processing & TCP Timers --- # Enable Fast Open to eliminate SYN-ACK round trips net.ipv4.tcp_fastopen = 3 # Disable slow start after idle so connection bursts don't ramp up latency net.ipv4.tcp_slow_start_after_idle = 0 # Enable selective ACKs and explicit congestion notification net.ipv4.tcp_sack = 1 net.ipv4.tcp_dsack = 1 net.ipv4.tcp_ecn = 1 # Reduce orphan retries for faster socket cleanup net.ipv4.tcp_orphan_retries = 1 # --- Memory & Socket Buffers (Optimized for Small Packets / Low Delay) --- # Keep socket buffers modest to prevent deep queuing at the socket layer net.core.rmem_default = 262144 net.core.wmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_max = 4194304 net.ipv4.tcp_rmem = 4096 87380 4194304 net.ipv4.tcp_wmem = 4096 65536 4194304 # --- Neighbor / ARP Table Latency Fixes --- # Keep ARP entries warm and prevent stale neighbor lookup delays net.ipv4.neigh.default.gc_stale_time = 120 net.ipv4.neigh.default.base_reachable_time_ms = 30000 EOF