Page 3 of 13 FirstFirst 12345 ... LastLast
Results 21 to 30 of 122

Thread: HOWTO: Set maximum CPU consumption in percentage by any process

  1. #21
    Join Date
    Mar 2007
    Beans
    630

    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
    Last edited by abcuser; May 3rd, 2009 at 09:50 AM.

  2. #22
    Join Date
    Apr 2009
    Beans
    5

    Re: HOWTO: Set maximum CPU consumption in percentage by any process

    Quote Originally Posted by abcuser View Post
    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 )

    okay cheers u modified it while i was writing. i'll go with it then cheers.
    Last edited by Elus1ve; April 29th, 2009 at 02:18 PM.

  3. #23
    Join Date
    Mar 2007
    Beans
    630

    Re: HOWTO: Set maximum CPU consumption in percentage by any process

    Quote Originally Posted by Elus1ve View Post
    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 View Post
    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 )
    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 View Post
    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.
    Last edited by abcuser; April 29th, 2009 at 05:28 PM.

  4. #24
    Join Date
    Apr 2009
    Beans
    5

    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

  5. #25
    Join Date
    Mar 2007
    Beans
    630

    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
    Last edited by abcuser; April 30th, 2009 at 09:21 AM.

  6. #26
    Join Date
    Apr 2009
    Beans
    5

    Re: HOWTO: Set maximum CPU consumption in percentage by any process

    Quote Originally Posted by abcuser View Post
    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

  7. #27
    Join Date
    Mar 2007
    Beans
    630

    Re: HOWTO: Set maximum CPU consumption in percentage by any process

    Quote Originally Posted by Elus1ve View Post
    the black list line is empty else i would get an error
    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.

  8. #28
    Join Date
    Mar 2007
    Beans
    630

    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.
    Last edited by abcuser; May 4th, 2009 at 01:43 PM.

  9. #29
    Join Date
    Apr 2009
    Beans
    5

    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


  10. #30
    Join Date
    Mar 2007
    Beans
    630

    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
    Last edited by abcuser; May 4th, 2009 at 02:10 PM.

Page 3 of 13 FirstFirst 12345 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •