Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing TX-Queuelength to enhance Bandwidth #100

Open
CodeFetch opened this issue Jan 6, 2021 · 20 comments
Open

Changing TX-Queuelength to enhance Bandwidth #100

CodeFetch opened this issue Jan 6, 2021 · 20 comments

Comments

@CodeFetch
Copy link
Contributor

Momentarily we use Debian's default values for e.g. the txqueuelen. These values are not optimized for routing. Increasing the buffer sizes and queue lengths will likely reduce the number of context switches. When setting them too high we might starve the userspace. Therefore we need to find reasonable values depending on the interface type (e.g. userspace VPN like fastd vs. kernel land WireGuard).

@CodeFetch
Copy link
Contributor Author

Buffer sizes should be symmetric for servers:
ethtool -G eth0 rx 4096 tx 4096

@CodeFetch
Copy link
Contributor Author

Increase input queue lengths:
echo 16384 > /proc/sys/net/core/netdev_max_backlog
ip link set eth0 txqueuelen 16384

@1977er
Copy link
Member

1977er commented Jan 10, 2021

I guess, this goes into the ffh.supernode role.

@lemoer
Copy link
Contributor

lemoer commented Jan 10, 2021

Please make sure, that this does not introduce additional buffer bloat.

@CodeFetch
Copy link
Contributor Author

@lemoer I did, but I didn't measure any improvement. So it seems it is not our bottleneck. A queue length of 16384 is enough for flattening spikes on a 2 Gbit/s link for about 5 ms. So this is nothing critical for bufferbloat, but just what we need for a 2 GBit/s link to not excessively start dropping on a high load. About the ring buffer sizes... They should be symmetric on a server that has symmetric up and down rates. Debian's defaults are for "client devices" which download more than they upload.

@1977er
Copy link
Member

1977er commented Jan 25, 2021

@CodeFetch If you did not measure any improvement, can this issue be closed?

@CodeFetch
Copy link
Contributor Author

We will sooner or later run into these issues when we have higher bandwidth demands e.g. with WireGuard, because the default configuration of Debian is not for routers or better say machines that symmetrically receive/transmit packets.

@1977er
Copy link
Member

1977er commented Jan 25, 2021

So, what did you mean by "but I didn't measure any improvement"?

@CodeFetch
Copy link
Contributor Author

@1977er That it's not the bottleneck at the moment. But I think it becomes relevant with more than 1 gbit/s traffic forwarding from different connections.

@1977er
Copy link
Member

1977er commented Jan 26, 2021

This will never happen with our current hardware and our resources.

@AiyionPrime
Copy link
Member

@CodeFetch @1977er So this is stalled/blocked, at least until we rolled out WireGuard for the broad mass?

@1977er
Copy link
Member

1977er commented Feb 20, 2021

If these settings do not harm, we can introduce them for future use.

@AiyionPrime
Copy link
Member

AiyionPrime commented Feb 20, 2021

@CodeFetch if they don't, do you want to implement this?

@lemoer lemoer changed the title Improve network interface performance Changing TX-Queuelength to enhance Bandwidth Feb 20, 2021
@lemoer
Copy link
Contributor

lemoer commented Feb 20, 2021

@1977er Settings like TXQueuelength can drastically reduce network perfomace due to bufferbloat. Therefore they can cause harm.

@1977er
Copy link
Member

1977er commented Feb 20, 2021

I guess then it's settled. As long as its not needed, don't change it.

@CodeFetch if you disagree, please re-open again.

@1977er 1977er closed this as completed Feb 20, 2021
@CodeFetch
Copy link
Contributor Author

That's not how codel etc. work as these algorithms look at the latency for deciding to drop packets. Therefore we should give it a try as the current buffer sizes are not optimized for routing and this could partially explain our current problems.

@CodeFetch CodeFetch reopened this Aug 18, 2022
@1977er
Copy link
Member

1977er commented Aug 19, 2022

Tested the setting of 16k again on a supernode with quite decent wg usage (already having the problem of dropping packets due to overusage). Looking at the % of neighbours with TQ < 95% chart I can see no effect after introducing the setting.

Bildschirmfoto 2022-08-19 um 09 53 29

(injected at 9:38)

I suggest to close this issue until we know, that we need this.

@AiyionPrime
Copy link
Member

Maybe we can re-test this once we have WG roled out, just to settle this once and for all then.

@CodeFetch
Copy link
Contributor Author

@1977er @AiyionPrime We should at least set this setting symmetric as we are using the servers as routers and not desktop machines. The current/asymmetric values are definitely wrong.

@CodeFetch
Copy link
Contributor Author

CodeFetch commented Nov 14, 2022

ip link set eth0 txqueuelen 16384

Tuning txqueuelen on pfifo_fast

The default txqueuelen was set to 1000 in Linux, in 2006. This is arguably wrong, even for gigE. Most network simulations at 100Mbit and below use 100, or even 50 as their default. Setting it below 50 is generally wrong, too, at any speed, except on wireless.

Source: https://www.bufferbloat.net/projects/codel/wiki/Best_practices_for_benchmarking_Codel_and_FQ_Codel/

Whatever that means...

Edit: "Time Squeeze" constantly increases so we might want to try tuning NAPI budgets
https://levelup.gitconnected.com/linux-kernel-tuning-for-high-performance-networking-receive-backlog-5b3f54fb82a7

Edit2: txqueuelen and netdev_max_backlog need to be set high enough for avoiding packet drops. At the same time NAPI weight and budget need to be set high enough for the softirq to handle all packets in time. Our issue is indeed softirq backpressure, but it seems that the reason for it is that the CPU cores are actually saturated. Maybe it makes sense to dedicate cores to softirq handling as recommended here (to reduce rescheduling and thereby increase cache warmth?), but that needs to be tested:
https://www.linkedin.com/pulse/navigating-linux-kernel-network-stack-receive-path-mark-price

Edit3: I like this guide more than the previous ones as it is more compact still covering all tips I've read about so far:
https://access.redhat.com/sites/default/files/attachments/20150325_network_performance_tuning.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants