[kamailio/kamailio] Issue bug CPS pipelimit (Issue #4985)
joseaponted created an issue (kamailio/kamailio#4985) ### Description pipelimit keeps calling `get_total_bytes_waiting()` (reading `/proc/net/udp` and `/proc/net/tcp`) from the main fast timer even with `load_fetch=0` and `timer_mode=1`. Only TAILDROP pipes are used, so network load is not needed. On a host that also runs RTPengine (tens of thousands of UDP sockets), each read of `/proc/net/udp` takes ~20 s, which blocks the main `timer` process at 100% CPU (almost all %system). As a consequence: - pipelimit counters are reset every ~20 s instead of every `timer_interval` (1 s), so TAILDROP limits effectively apply per ~20 s window. - tm timers are delayed too: `tm.stats` shows `waiting` transactions growing continuously (22k -> 31k in a few minutes) because wait timers don't fire on time. Commit 61d1fbcc8c ("pipelimit: allow to disable fetching cpu and network load") suggests `load_fetch=0` should prevent this. ### Troubleshooting #### Reproduction 1. Run Kamailio with pipelimit on a host with many UDP sockets (e.g. RTPengine on the same host handling thousands of calls). 2. Use only TAILDROP pipes, with: modparam("pipelimit", "timer_interval", 1) modparam("pipelimit", "timer_mode", 1) modparam("pipelimit", "load_fetch", 0) 3. Watch `kamcmd pl.list`: `last_counter` changes every ~20 s, not every 1 s. 4. Check the main timer process: 100% CPU, with `/proc/<pid>/net/udp` open. #### Debugging Data Main timer process (`core.ps` -> "timer") at 100% CPU, ~0% usr / ~100% sys: pidstat -t -u -p <timer_pid> 1 5 |__kamailio 0.00 %usr 100.00 %system Open file descriptor: ls -l /proc/<timer_pid>/fd | grep net 19 -> /proc/<timer_pid>/net/udp perf top -p <timer_pid>: 70.15% [kernel] [k] udp_get_next 16.11% [kernel] [k] udp_get_first 1.92% [kernel] [k] udp_seq_start perf record --call-graph dwarf -p <timer_pid>: udp_get_next udp_seq_start seq_read_iter / seq_read / proc_reg_read / vfs_read / read get_total_bytes_waiting 0x7443089c0066 0x7443089c0a5c timer_main main_loop main Address resolution via /proc/<timer_pid>/maps: 7443089b3000-7443089c8000 r-xp 00003000 ... /usr/lib/x86_64-linux-gnu/kamailio/modules/pipelimit.so offset in file: 0x10066 So the call comes from pipelimit.so, from `timer_main` (main fast timer), despite `timer_mode=1` and `load_fetch=0`. #### Log Messages No errors logged. #### SIP Traffic Not relevant; occurs under normal load (~hundreds of CPS per pipe, thousands of concurrent calls with RTPengine on the same host). ### Possible Solutions - Skip `get_total_bytes_waiting()` entirely when `load_fetch=0`. - Ideally, only fetch network load if at least one NETWORK pipe exists. - Also verify that `timer_mode=1` actually moves the routine off the main timer. Workaround used: removed pipelimit and implemented per-second CPS limiting with htable (`$shtinc` on a key built with `$Ts`). ### Additional Information * **Kamailio Version** - output of `kamailio -v` version: kamailio 6.0.8 (x86_64/linux) flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, MEM_JOIN_FREE, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED compiled with gcc 11.4.0 * **Operating System**: Ubuntu 22.04.5 LTS, kernel 6.8.0-138-generic, 32 CPUs RTPengine running on the same host -- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/4985 You are receiving this because you are subscribed to this thread. Message ID: <kamailio/kamailio/issues/4985@github.com>
miconda left a comment (kamailio/kamailio#4985) Can you double check if you really use a config with: ``` modparam("pipelimit", "timer_mode", 1) modparam("pipelimit", "load_fetch", 0) ``` The code shows that get_total_bytes_waiting() is used only with load_fetch 1 -- link to the master, but should be the same in 6.0.x: - https://github.com/kamailio/kamailio/blob/master/src/modules/pipelimit/pipel... -- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/4985#issuecomment-6053556930 You are receiving this because you are subscribed to this thread. Message ID: <kamailio/kamailio/issues/4985/6053556930@github.com>
darwvin-dev left a comment (kamailio/kamailio#4985) <!-- darwvin-triage-20261013-4985 --> Static cross-branch check: `pl_timer_refresh()` in Kamailio `6.0` and `6.1` only calls `get_total_bytes_waiting()` when `pl_load_fetch != 0`; on `master` it is gated by `pl_load_fetch & PL_LOAD_FETCH_NETWORK`. For the report's exact `load_fetch=0`, the examined source does not explain a network-load read. Before a fix PR, could we verify the *effective* deployed pipelimit configuration and build/branch SHA for the loaded `pipelimit.so`, confirm whether a dynamic override is active, and capture a fully symbolized stack pointing at the actual binary? The `timer_mode=1` path also uses `sr_wtimer_add()`, not the normal `F_TIMER_FAST` registration. This is a code-level observation only; I have not reproduced the reporter's 20-second stall. -- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/4985#issuecomment-6145343566 You are receiving this because you are subscribed to this thread. Message ID: <kamailio/kamailio/issues/4985/6145343566@github.com>
abalashov left a comment (kamailio/kamailio#4985)
3\. Static cross-branch check: `pl_timer_refresh()` in Kamailio `6.0` and `6.1` only calls `get_total_bytes_waiting()` when `pl_load_fetch != 0`; on `master` it is gated by `pl_load_fetch & PL_LOAD_FETCH_NETWORK`. For the report's exact `load_fetch=0`, the examined source does not explain a network-load read. Before a fix PR, could we verify the _effective_ deployed pipelimit configuration and build/branch SHA for the loaded `pipelimit.so`, confirm whether a dynamic override is active, and capture a fully symbolized stack pointing at the actual binary? The `timer_mode=1` path also uses `sr_wtimer_add()`, not the normal `F_TIMER_FAST` registration. This is a code-level observation only; I have not reproduced the reporter's 20-second stall.
While this is load-bearing, is it in the hot path? -- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/4985#issuecomment-6168397643 You are receiving this because you are subscribed to this thread. Message ID: <kamailio/kamailio/issues/4985/6168397643@github.com>
miconda left a comment (kamailio/kamailio#4985) Closing, if something new has to be added, ask to reopen or create a new issue, eventually providing feedback after testing with latest git master branch. -- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/4985#issuecomment-6211088689 You are receiving this because you are subscribed to this thread. Message ID: <kamailio/kamailio/issues/4985/6211088689@github.com>
Closed #4985 as completed. -- Reply to this email directly or view it on GitHub: https://github.com/kamailio/kamailio/issues/4985#event-33425173287 You are receiving this because you are subscribed to this thread. Message ID: <kamailio/kamailio/issue/4985/issue_event/33425173287@github.com>
participants (4)
-
Alex Balashov -
Daniel-Constantin Mierla -
Darwvin -
joseaponted