Re: HOWTO: Set maximum CPU consumption in percentage by any process
Elus1ve, I have written new version of cpulimit daemon. Replace step "2. WRITE CPULIMIT DAEMON FILE" from first post of this how-to with the file bellow. All other steps from how-to remains the same.
UPDATE: script deleted because of some bug. Please see script in new post bellow.
Daemon has two new variables: BLACK_PROCESSES_LIST and WHITE_PROCESSES_LIST.
If you would like only to limit process e.g "firefox" then set:
BLACK_PROCESSES_LIST="firefox"
If you would like to limit all processes except e.g. "firefox" set:
WHITE_PROCESSES_LIST="firefox"
If you would like to limit/exclude multiple processes just use "\|" separator (without quoting marks) between process names. Sample:
BLACK_PROCESSES_LIST="firefox|\gedit\|glchess"
WHITE_PROCESSES_LIST="firefox|\gedit\|glchess"
I haven't tested this new daemon in deep so I haven't changed first post's how-to. I would be very happy if someone out there could test this daemon and post some feed back.
Regards
Re: HOWTO: Set maximum CPU consumption in percentage by any process
Quote:
Originally Posted by
abcuser
I suggest to extent grep commands with \| which is "OR" conditional in grep.
Sample:
PIDS=$(ps -eo pid,args | grep "FahCore_a0.exe\|second_program\|third_program\|et c_program" | grep -v grep | gawk '{print $1}')
You also can use grep but using "v" switch sample:
PIDS=$(ps -eo pid,args | grep -v "mysqld" | grep -v grep | gawk '{print $1}')
thx for help.
i tried the first method inside your original loop and ended up with almost 1500 instances of cpulimit :S
does the loop need some modification?
gonna try with the invert match hopfully it doesn create that much threads
you know i have a "power hour" in the morning when all perl, logwatch, backup etc process is working and i try to use cpulimit on these processes so that the web surface is still reachable (this is the main goal :P)
okay cheers u modified it while i was writing. i'll go with it then cheers.
Re: HOWTO: Set maximum CPU consumption in percentage by any process
Quote:
Originally Posted by
Elus1ve
i tried the first method inside your original loop and ended up with almost 1500 instances of cpulimit :S
does the loop need some modification?
gonna try with the invert match hopfully it doesn create that much threads
Sorry it was probably some kind of bug in code. I didn't test it... But instead I have written new version of daemon. Please see the code in my previous post and test it on test computer. If you would like to test it directly on production computer (not recommended in first place) replace line:
cpulimit -p $i -l $CPU_LIMIT -z & # Limit new violating processes
with command:
echo $i
So instead of cpulimit processes just print PIDs on screen. You can then check if desired PIDs were displayed by using command:
ps aux | grep PID
Quote:
Originally Posted by
Elus1ve
you know i have a "power hour" in the morning when all perl, logwatch, backup etc process is working and i try to use cpulimit on these processes so that the web surface is still reachable (this is the main goal :P)
In this case write all processes you would like to omit a CPU in BLACK_PROCESSES_LIST variable separated by "\|" (without double quotes). See notes in previous post for details.
Quote:
Originally Posted by
Elus1ve
okay cheers u modified it while i was writing. i'll go with it then cheers.
Yes, sorry... I just got and idea how to extend daemon functionality.
Please try above daemon. For testing purposes you can just copy above text, create file and give execute permissions and then execute from terminal using command:
sudo ./cpulimit_daemon.sh
And pressing <ctrl>+c to stop script.
Re: HOWTO: Set maximum CPU consumption in percentage by any process
# ps aux | grep cpu
root 8341 0.0 0.0 1788 556 ? S< 14:20 0:00 cpulimit -p 11030 -l 5 -z
root 8420 0.0 0.0 1788 556 ? S< 14:20 0:00 cpulimit -p 11030 -l 5 -z
root 8498 0.0 0.0 1788 560 ? S< 14:20 0:00 cpulimit -p 11030 -l 5 -z
root 8773 0.0 0.0 1788 560 ? S< 14:21 0:00 cpulimit -p 11030 -l 5 -z
root 8981 0.0 0.0 1788 556 ? S< 14:21 0:00 cpulimit -p 11030 -l 5 -z
root 9024 0.0 0.0 1788 560 ? S< 14:21 0:00 cpulimit -p 11030 -l 5 -z
root 9123 0.0 0.0 1788 556 ? S< 14:21 0:00 cpulimit -p 11030 -l 5 -z
root 9214 0.0 0.0 1788 556 ? S< 14:21 0:00 cpulimit -p 11030 -l 5 -z
root 11070 0.0 0.0 1788 556 ? S< 14:01 0:00 cpulimit -p 11030 -l 5 -z
its running for a few hours wonder why is there so many instance on the same pid :S
# ps -p 11030
PID TTY TIME CMD
11030 ? 00:03:34 awstats.pl
Re: HOWTO: Set maximum CPU consumption in percentage by any process
Elus1ve,
it looks the same process was cpu-limited multiple times.
Can you please provide more info.
1. Did you make your own version of the program or did you use my new daemon script? This problem should not happened with my new daemon script because I haven't touched code that is preventing multiple cpu limitation of the same PID.
2. Did you kill all cpulimit processes before running new daemon - you could have some old cpulimit processes running before running a daemon. I suggest you run "killall cpulimit" and then check "ps aux | grep cpulimit" to see if all cpulimit processes are killed. Then start daemon.
3. How did you set variables BLACK_PROCESSES_LIST and WHITE_PROCESSES_LIST?
Regards
Re: HOWTO: Set maximum CPU consumption in percentage by any process
Quote:
Originally Posted by
abcuser
Elus1ve,
it looks the same process was cpu-limited multiple times.
Can you please provide more info.
1. Did you make your own version of the program or did you use my new daemon script? This problem should not happened with my new daemon script because I haven't touched code that is preventing multiple cpu limitation of the same PID.
using your new version
2. Did you kill all cpulimit processes before running new daemon - you could have some old cpulimit processes running before running a daemon. I suggest you run "killall cpulimit" and then check "ps aux | grep cpulimit" to see if all cpulimit processes are killed. Then start daemon.
yea i looked up that i have killed every cpulimit process
3. How did you set variables BLACK_PROCESSES_LIST and WHITE_PROCESSES_LIST?
Regards
WHITE_PROCESSES_LIST="mysqld\|sc_trans\|httpd"
the black list line is empty else i would get an error :P
Re: HOWTO: Set maximum CPU consumption in percentage by any process
Quote:
Originally Posted by
Elus1ve
the black list line is empty else i would get an error :P
I have omitted possibility of having BLACK and WHITE list at the same time, because it is not logical to have both at the same time.
Re: HOWTO: Set maximum CPU consumption in percentage by any process
Elus1ve,
you were correct some processes could be repeated (cpulimited) multiple times, because of bug in QUEUE_PID variable. I used command diff to check the difference between already cpulimited processes (variable LIMITED_PIDS) vs. new processes (NEW_PIDS variable). But I have forgot, that diff can return c-change, d-delete or a-add. Script just assumed that every time c is returned. So this was the reason some processes could be repeated twice or more time. I have now replaced diff command with comm which is more suitable to solve this kind of problem. I have made some other little changes in script as well, so please copy the whole script and change variables values. I have tested this new script in deep and now problem should be solved. Can you please be so kind and test this new script and just write me some feed-back.
Thanks,
Abcuser
UPDATE: script was deleted. See script on the first post of this thread.
Re: HOWTO: Set maximum CPU consumption in percentage by any process
that was it mate, with the last version you solved it:)
thank you very much for your efforts
\\:D/
Re: HOWTO: Set maximum CPU consumption in percentage by any process
Elus1ve, thanks a lot for testing. I have updated first post with this latest script.
I have also changed start-up script in chapter3 step 2. "Restart" option was simplified.
Regards