Community discussions

MUM Europe 2020
 
headshoter
just joined
Topic Author
Posts: 18
Joined: Mon Jul 30, 2012 3:21 am

CPU 100% during a for loop

Tue Mar 04, 2014 10:23 am

Hello ,
i wrote this script to add target address of simple queues that have total bytes greater than 50000 to a firewall address list,
but during performing the script my cpu usage stands at 100% for about 3 minutes !!!
p.s : im using rb750G as my router .

does anyone have better idea to get handle this ?

ros code

/queue simple
     :for i from=1 to=254 do={
       :if ([get [find target-addresses="192.168.7.$i/32"] total-bytes] > 50000) do={
      / ip firewall address-list add address="192.168.7.$i" list=No_internet
       }
      }
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2950
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: CPU 100% during a for loop

Tue Mar 04, 2014 11:43 am

Fixed logical problem.

Your version have target-addresses instead of target!!!

ROS 6.7:

ros code

/queue simple
:for i from=1 to=254 do={
  :if ([get [find where target=[:toip ("192.168.7.".$i)] ] total-bytes] > 50000) do={
   /ip firewall address-list add address=("192.168.7.".$i) list=No_internet 
  }
}
I'm Italian, not English. Sorry for my imperfect grammar.
 
headshoter
just joined
Topic Author
Posts: 18
Joined: Mon Jul 30, 2012 3:21 am

Re: CPU 100% during a for loop

Tue Mar 04, 2014 1:00 pm

Fixed logical problem.

Your version have target-addresses instead of target!!!

ROS 6.7:

ros code

/queue simple
:for i from=1 to=254 do={
  :if ([get [find where target=[:toip ("192.168.7.".$i)] ] total-bytes] > 50000) do={
   /ip firewall address-list add address=("192.168.7.".$i) list=No_internet 
  }
}
upgraded my ROS to 6.10 just now ...
its getting an error that says : no such item
i think its because the target must be specified with the subnet (here for example 192.168.7.2/32) and ":toip" wont translate ip in that structure.
any solutions ?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2950
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: CPU 100% during a for loop

Tue Mar 04, 2014 1:28 pm

Ok, I rewrite from 0 with more logical order:

ros code

:foreach queueTest in=[ /queue simple find where total-bytes > 50000 ] do={
 :if ( [/queue simple get $queueTest target] in 192.168.7.0/24) do={
   /ip firewall address-list add address=[/queue simple get $queueTest target] list=No_internet;
 }
};
I'm Italian, not English. Sorry for my imperfect grammar.
 
headshoter
just joined
Topic Author
Posts: 18
Joined: Mon Jul 30, 2012 3:21 am

Re: CPU 100% during a for loop

Tue Mar 04, 2014 4:32 pm

Ok, I rewrite from 0 with more logical order:

ros code

:foreach queueTest in=[ /queue simple find where total-bytes > 50000 ] do={
 :if ( [/queue simple get $queueTest target] in 192.168.7.0/24) do={
   /ip firewall address-list add address=[/queue simple get $queueTest target] list=No_internet;
 }
};
the if statement still cannot be used because it returns false for every single ip so i removed it from script and now it works greate ;)
but would you please explain me why there is this much difference in performance between the first script i used and this one ?
Thanks,
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2950
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: CPU 100% during a for loop

Tue Mar 04, 2014 7:12 pm

The problem is $i inside " " in: "192.168.7.$i/32"
The correct method to join to obtain a string is: "192.168.7.".$i."/32"
and must be used ":toip" to convert a string to ip variable.
I'm Italian, not English. Sorry for my imperfect grammar.

Who is online

Users browsing this forum: No registered users and 20 guests