NIC Optimization for Low Latency
To make your NIC optimization settings permanent across reboots, you can create a systemd service that applies the necessary ethtool
and tc qdisc
configurations at startup.
Steps:
- Create the Script with
ethtool
andtc
Commands - Create a systemd Service File
- Enable and Validate the Service
Step 1: Create the Script
First, create a script that includes ethtool
and tc
settings for low latency.
sudo nano /usr/local/bin/nic-optimization.sh
Add the following commands to the script:
#!/bin/bash
# Disable Interrupt Coalescing
ethtool -C eth0 rx-usecs 0 rx-frames 0
ethtool -C eth0 tx-usecs 0 tx-frames 0
# Disable TCP Offloading
ethtool -K eth0 tso off gso off gro off
# Reduce NIC Ring Buffers
ethtool -G eth0 rx 256
ethtool -G eth0 tx 256
# Disable Flow Control
ethtool -A eth0 rx off tx off
# Set TC (Traffic Control) qdisc to pfifo_fast
tc qdisc replace dev eth0 root pfifo_fast
Make the script executable:
sudo chmod +x /usr/local/bin/nic-optimization.sh
Step 2: Create a systemd Service File
Now, create a systemd service to run the script at startup.
sudo nano /etc/systemd/system/nic-optimization.service
Add the following content:
[Unit]
Description=NIC Optimization for Low Latency
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/nic-optimization.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Explanation:
Type=oneshot
: This means the service will run and then exit. It’s not a long-running service.RemainAfterExit=yes
: Keeps the service in an active state after it finishes running.ExecStart
: Specifies the script that will be executed (/usr/local/bin/nic-optimization.sh
).
Step 3: Enable and Start the Service
Now, enable the service to run at boot, start it, and verify that it works.
Check the status to verify it ran successfully:
sudo systemctl status nic-optimization.service
Start the service immediately:
sudo systemctl start nic-optimization.service
Enable the service so it runs at every boot:
sudo systemctl enable nic-optimization.service
Reload systemd to recognize the new service:
sudo systemctl daemon-reload
You should see output similar to:
● nic-optimization.service - NIC Optimization for Low Latency
Loaded: loaded (/etc/systemd/system/nic-optimization.service; enabled; vendor preset: enabled)
Active: active (exited) since Mon 2024-10-21 10:00:00 UTC; 2s ago
Process: 1234 ExecStart=/usr/local/bin/nic-optimization.sh (code=exited, status=0/SUCCESS)
Main PID: 1234 (code=exited, status=0/SUCCESS)
This confirms that the service ran successfully, applying your NIC optimizations.
Step 4: Validation
To ensure that your settings were applied correctly, you can manually validate the optimizations after the service runs.
Validate ethtool
Settings:
Check Flow Control:
ethtool -a eth0
Ensure that RX
and TX
flow control are set to off
.
Check NIC Ring Buffers:
ethtool -g eth0
You should see the RX
and TX
ring buffers set to 256
.
Check TCP Offloading:
ethtool -k eth0
Ensure that tso
, gso
, and gro
are set to off
.
Check Interrupt Coalescing:
ethtool -c eth0
You should see values for rx-usecs
and tx-usecs
as 0
, and rx-frames
and tx-frames
as 0
.
Validate tc qdisc
:
Check the Active qdisc:
tc qdisc show dev eth0
You should see:
qdisc pfifo_fast 0: root refcnt 2 bands 3 priomap 1 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2
This confirms that the pfifo_fast
queuing discipline is active.
Summary of Commands:
- Validate the settings:
Check traffic control qdisc:
tc qdisc show dev eth0
Check ethtool
settings:
ethtool -c eth0
ethtool -k eth0
ethtool -g eth0
ethtool -a eth0
Check the service status:
sudo systemctl status nic-optimization.service
Enable and start the service:
sudo systemctl enable nic-optimization.service
sudo systemctl start nic-optimization.service
Reload systemd:
sudo systemctl daemon-reload
Create the service file:
sudo nano /etc/systemd/system/nic-optimization.service
Make the script executable:
sudo chmod +x /usr/local/bin/nic-optimization.sh
Create the script:
sudo nano /usr/local/bin/nic-optimization.sh
By following these steps, your NIC optimizations will be applied automatically on boot, ensuring low latency and low jitter persistently. Let me know if you need further assistance!