Re: High volume ratelimit CPS

"Jon Bonilla (Manwe) via sr-users" <[email protected]>
Newsgroups gmane.comp.voip.ser
Message-ID <[email protected]>
El Mon, 8 Dec 2025 22:38:48 +0100
"Jon Bonilla (Manwe) via sr-users" <[email protected]> escribió:

> El Mon, 8 Dec 2025 19:49:58 +0000
> Ben Kaufman <[email protected]> escribió:
> 
> > I don't see how it could fail to be "fast enough", since $shtinc() is
> > atomic. In other words if you were running 600 children (theoretically,
> > please don't actually set children to 600), the operation $var(cps) =  
> > $shtinc(caps=>$var(cps)) will only happen one at a time, all other
> > processes will wait until it is free before they can change it.
> >  
 
> I really don't know. I remember adding a log because the destination was
> complaining and the cps being sent was higher than the limit before the
> rejections hit. 
> 
> I need to set a new box for another destination. I'll try to implement the
> same solution and reproduce it. 
> 


Hi again

I'm testing this setup using htable and seems promising. 


I'm using 60 children (not 600 xD). I have around 15 gateways with a max of 54
CAPS each. I'm setting a counter for each destination and second. If I'm above
threshold for that destination I select next destination in dispatcher (limit4).

modparam("htable",
"htable","caps=>size=11;initval=0;autoexpire=5;updateexpire=0;") 
modparam("htable","timer_interval", 5) 
modparam("htable", "timer_procs", 4)

route[RATELIMIT]
{
$var(cps_allow) = 0;
while($var(cps_allow) == 0) {
  $var(cps) = $rd + ":" + $timef(%S);
  $var(cps) = $shtinc(caps=>$var(cps));
  if ($var(cps) > CAPSLIMIT) {
    $var(cps_allow)=0;
    if (!ds_next_domain()) {
      send_reply("500","No destinations available"); 
      exit;
    }
  } else {
     $var(cps_allow)=1;
  }
}

And in failover route I also call route ratelimit:

if (t_check_status("408|500|501|502|503")) {
xlog("L_NOTICE", "Failover route for status $T_reply_code\n");
if (!ds_next_domain()) {
  xlog("L_NOTICE", "No more destinations available\n");
  send_reply("500", "No destinations available");
  exit; 
}
route(RATELIMIT);
t_set_fr(180000, OUTBOUNDTIMEOUT);
t_on_failure("FAILURE_OUTBOUND_MAIN");
route(RELAY);



I see in the logs everything working fin except that some counters seem to be
offset when I'm dealing with failover. For example:

12:53:15.7774 New call - M=INVITE

12:53:15.7776 Destination A cps is 39 below limit 54. ACCEPT

12:53:15.8658 Failover route for status 503 

12:53:15.8659 Destination B cps is 43 below limit 54. ACCEPT 

12:53:16.0191 Failover route for status 503 

12:53:16.0193 Destination C cps is 54 below limit 54. ACCEPT 

12:53:16.1500 Failover route for status 503 

12:53:16.1501 Destination D cps is 49 below limit 54. ACCEPT 

12:53:16.4523 Failover route for status 503 

12:53:16.4524 No more destinations available


The problem there is that when failover to destination C and D seems like it's
taking the counter of the previous second but the second already changed from
15 to 16. Seems like $timef(%S) is not updating each time I execute
route(RATELIMIT)
With this scenario I can go above 54 cps. 

Any ideas?


cheers,

Jon





-- 
PekePBX, the multitenant PBX solution
https://pekepbx.com

__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the sender!
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEeCM0ZbH8r7OFHtBdv/8mNWfCIT8FAmlAUwUACgkQv/8mNWfC
IT9rLA/+M7V6l4v40z4EW7XOBa5Ya7Emc5PdB+qCPojRrnrXYMrsH0T74lLD3FpK
Y+VEFD65D/Jp2JGkKuXF7cE7ujRuG+HfH72fbckoI/xnhq2NzZcUMnBZut1+jW6s
m7euke7vRe5Rdcu22eAp9pC+x1JkBXVOafezfS/Las1fSn81KPl9xszx1yz6WLgf
4+Zb8s4VVt+eGcKJ/QobQO0oGJQ//VROaEltVKv6dASI5vhjLuit9gM1doizyYRC
I88LJJ3o+WGuRpyzqprcvcHh0NxcqZOxo2UPMcNK76rVbaxEdu/aUov9JadzzxpU
Tix2QbDcLlExHzMn0kxuTD1MG3Slvz0WVTs67rpgw4guogWlPzcd/rXMOMmLVZQq
lcXm6UxEkK/mV+pTyDYc1dLOBPxpPH9cr/XqM/z+v4D+8ORf1XLg9nqO8P8k/3XT
gxmAFpfMywRvRrrdGcMi0kakJuxrgZNBr6pGrtPxKIBL7TU7q3odvEKcGgcfRSjf
7abBMgQ72wNKcmLpfOP0vSeS9M0mSyADq9WNlppik0462O/jy5yNaTgrcksAYhPt
KpZU2S0y7xgHETDtD9ngpZx5VWXJGx9d/vac3wPbsUJnmKHsslltfcXEIVrNalv8
UF7TDWrjasx8jVbAbiowrmXXN4ocfZCFyCO92WjE4cCAWFe3CPU=
=4Bdh
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.