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

Attachment: pgps3MBr9VkuE.pgp
Description: Firma digital OpenPGP

__________________________________________________________
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!

Reply via email to