From pojogas@gmail.com Tue Jul 10 02:12:13 2018 From: Sergiu Pojoga To: sr-users@lists.kamailio.org Subject: Re: [SR-Users] CPS Date: Mon, 09 Jul 2018 20:11:55 -0400 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0369270949==" --===============0369270949== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Figured it out eventually, thanks for the tip Alex. Cheers --Sergiu On Mon, Jul 9, 2018 at 4:14 PM Sergiu Pojoga wrote: > I have not until now that you recommended it, looks much simpler indeed, > thanks. > > Although, so far I can't seem to hit a pipe limit. If I watch pl.stats, no > matter what *timer_interval* I set, the counter increases to 1 upon a > call then back to 0 the next second. > > root(a)proxy:/# watch -n 1 -d kamcmd pl.stats > PIPE: id=65.39.XX.XX load=0 counter=0 > > Say I wanted 1 call per minute pipe, what would be the 'timer_interval' > and pl_check limit? > > On Mon, Jul 9, 2018 at 2:47 PM Alex Balashov > wrote: > >> Have you considered using pipelimit for this? It's as simple as: >> >> if(!pl_check("$avp(customer_id)", "TAILDROP", "$avp(cps_limit)")) { >> pl_drop(); >> exit; >> } >> >> There was a time when that wasn't possible because pipes couldn't easily >> be created dynamically for a given customer ID or whatever, and htable >> was the preferred vehicle for that. That has changed, and nowadays it's >> a lot simpler. :-) >> >> -- Alex >> >> On Mon, Jul 09, 2018 at 02:41:44PM -0400, Sergiu Pojoga wrote: >> >> > Hi folks, >> > >> > Trying to implement CPS throttling based on this >> > < >> https://lists.kamailio.org/pipermail/sr-users/2013-September/079713.html >> >article, >> > having some trouble. >> > >> > modparam("htable", "htable", "rhs=>size=32;initval=0;autoexpire=300;" >> > modparam("htable", "htable", "rhm=>size=32;initval=0;autoexpire=1800;") >> > >> > route[CPS] { >> > $var(rateHashSec) = $si+":sec:"+$timef(%Y/%m/%d_%H_%M_%S); >> > $var(rateHashMin) = $si+":min:"+$timef(%Y/%m/%d_%H_%M_00); >> > xlog("L_INFO", "var(rateHashSec)=$var(rateHashSec); >> > var(rateHashMin)=$var(rateHashMin)\n"); >> > $var(ratePerSec) = $shtinc(rhs=>$var(rateHashSec)); >> > $var(ratePerMin) = $shtinc(rhm=>$var(rateHashMin)); >> > xlog("L_INFO", "var(ratePerSec)=$var(ratePerSec); >> > var(ratePerMin)=$var(ratePerMin)\n"); >> > $var(limitPerSec) = 1; >> > $var(limitPerMin) = 1; >> > >> > if ($var(ratePerSec) > $var(limitPerSec) || $var(ratePerMin) > >> > $var(limitPerMin)) { >> > xlog("L_INFO", "CPS Limit on IP $si\n"); >> > send_reply("503", "CPS Limit on IP $si"); >> > exit; >> > } >> > >> > } >> > >> > Logs show hashes are created but *$var(ratePerSec/Min)* won't increment >> no >> > matter how many calls I place per second or minute: >> > >> > Jul 9 14:35:52 proxy /usr/local/sbin/kamailio[1484]: INFO: