第 9 章 Avoiding listen queue lock contention
Queue lock contention can cause packet drops and higher CPU usage and, consequently, a higher latency. You can avoid queue lock contention on the receive (RX) and transmit (TX) queue by tuning your application and using transmit packet steering.
Improving the performance of multi-threaded network server applications on multi-core systems can be done by opening the port with the SO_REUSEPORT or SO_REUSEPORT_BPF socket option. Without these, all threads must share a single socket to receive incoming traffic.
Using a single socket causes:
- Significant contention on the receive buffer, which can cause packet drops and higher CPU usage.
- A significant increase of CPU usage
- Possibly packet drops
With the SO_REUSEPORT or SO_REUSEPORT_BPF socket option, multiple sockets on one host can bind to the same port:
For further details, see the socket(7) man page and the /usr/src/debug/kernel-<version>/linux-<version>/tools/testing/selftests/net/reuseport_bpf_cpu.c file on your system.
Red Hat Enterprise Linux provides a code example of how to use the SO_REUSEPORT socket options in the kernel sources. To access the code example:
Enable the
rhel-9-for-x86_64-baseos-debug-rpmsrepository:# subscription-manager repos --enable rhel-10-for-x86_64-baseos-debug-rpmsInstall the
kernel-debuginfo-common-x86_64package:# dnf install kernel-debuginfo-common-x86_64-
The code example is now available in the
/usr/src/debug/kernel-<version>/linux-<version>/tools/testing/selftests/net/reuseport_bpf_cpu.cfile.