I faced the issue that my integration tests get 3x performance boost on Ubuntu 20.04 with Kernel 5.4 but on Ubuntu 22.04+ and all Linux kernels after 5.10.135 there is not such boost. Integration tests is PyTest testing Python 3.12 application using MongoDB(PyMongo and Motor) and Redis. Tests, application itself, Mongo and Redis services are running only locally in Docker Compose so there is no network communication to other hosts through real physical network. I bisected Linux Kernel and found the commit which produce performance boost: https://www.kernel.org/pub/linux/kernel/v5.x/ChangeLog-5.1 commit 4a41f453bedfd5e9cd040bad509d9da49feb3e2c Author: Wei Wang <weiwan@google.com> Date: Fri Jan 25 10:53:20 2019 -0800 tcp: change pingpong threshold to 3 but in 5.10.135 the commit was reverted by: https://www.kernel.org/pub/linux/kernel/v5.x/ChangeLog-5.10.135 commit 77ac046a9ad3b9ee94d02f999d30db3ac106c98c Author: Wei Wang <weiwan@google.com> Date: Thu Jul 21 20:44:04 2022 +0000 Revert "tcp: change pingpong threshold to 3" commit 4d8f24eeedc58d5f87b650ddda73c16e8ba56559 upstream. This reverts commit 4a41f453bedfd5e9cd040bad509d9da49feb3e2c. and in 2023 introduced net.ipv4.tcp_pingpong_thresh setting which default is 1: https://www.kernel.org/pub/linux/kernel/v6.x/ChangeLog-6.7 commit 562b1fdf061bff9394ccd884456ed1173c224fdc Author: Haiyang Zhang <haiyangz@microsoft.com> Date: Wed Oct 11 13:30:44 2023 -0700 tcp: Set pingpong threshold via sysctl The problem is changing net.ipv4.tcp_pingpong_thresh to 3 does not have the same performance effect like it was before 5.10.135. I found that the reason is exactly in 562b1fdf061bff9394ccd884456ed1173c224fdc, if revert 77ac046a9ad3b9ee94d02f999d30db3ac106c98c right before 562b1fdf061bff9394ccd884456ed1173c224fdc there is a desired 3x performance. So I made a small patch which returns the desired performance: From: Oleg Neumyvakin <oneumyvakin@gmail.com> Date: Sun, 27 Jul 2025 20:40:47 +0700 Subject: [PATCH] Fix tcp pingpong threshold --- net/ipv4/tcp_ipv4.c | 2 +- net/ipv4/tcp_output.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index f603ad9307af..fe5b1545c499 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -3288,7 +3288,7 @@ static int __net_init tcp_sk_init(struct net *net) net->ipv4.sysctl_tcp_syn_linear_timeouts = 4; net->ipv4.sysctl_tcp_shrink_window = 0; - net->ipv4.sysctl_tcp_pingpong_thresh = 1; + net->ipv4.sysctl_tcp_pingpong_thresh = 3; return 0; } diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 8e6ebf35ed58..912080d8d80a 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -167,13 +167,16 @@ static void tcp_event_data_sent(struct tcp_sock *tp, if (tcp_packets_in_flight(tp) == 0) tcp_ca_event(sk, CA_EVENT_TX_START); - tp->lsndtime = now; - - /* If it is a reply for ato after last received - * packet, increase pingpong count. + /* If this is the first data packet sent in response to the + * previous received data, + * and it is a reply for ato after last received packet, + * increase pingpong count. */ - if ((u32)(now - icsk->icsk_ack.lrcvtime) < icsk->icsk_ack.ato) + if (before(tp->lsndtime, icsk->icsk_ack.lrcvtime) && + (u32)(now - icsk->icsk_ack.lrcvtime) < icsk->icsk_ack.ato) inet_csk_inc_pingpong_cnt(sk); + + tp->lsndtime = now; } /* Account for an ACK we sent. */ -- 2.43.0 I'd created a syntetic test with Mongo and Redis using Python or YCSB but can't see performance difference. So my question, does anybody experiencing a performance issue with Python, Mongo, Redis and pingpong threshold? Continue reading...