Page 8 of 13 FirstFirst ... 678910 ... LastLast
Results 71 to 80 of 122

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

  1. #71
    Join Date
    Aug 2007
    Location
    Belgium
    Beans
    176
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    What an interesting box you have there...
    El Belgicano
    -----------------
    Laptop: 5 years old Asus M6N (ATI9600/9700 graphics, 512Mb RAM, Intel Mobile 1.66GHz, 60Gb HDD) running 10.04-Lucid Lynx pretty nicely.

  2. #72
    Join Date
    Mar 2007
    Beans
    623

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

    @El_Belgicano: If you execute mencoder randomly then daemon can be useful, but if you would like to omit only single process and doing this ones per some time, then you do not need cpu_limit daemon script. You can just execute the cpulimit command with process id for mencoder.

    @davidparks21: Thanks for bringing this issue out. Limiting processes to 3% is actually very specific problem. In this case it can easily happen that cpulimit program is caught in a 3% cpu limit by deamon. In this case I suggest to whitelist the cpulimit process.
    Last edited by abcuser; November 1st, 2011 at 01:15 PM.

  3. #73
    Join Date
    Aug 2007
    Location
    Belgium
    Beans
    176
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    Quote Originally Posted by abcuser View Post
    @El_Belgicano: If you execute mencoder randomly then daemon can be useful, but if you would like to omit only single process and doing this ones per some time, then you do not need cpu_limit daemon script. You can just execute the cpulimit command with process id for mencoder.
    Mostly i run mencoder through a script, thus if i follow your thinking, i could change my script from:
    Code:
    ...
    mencoder [...] &
    ...
    to:
    Code:
    ...
    mencoder [...] &
    cpulimit -e mencoder -l 40 & (exact parameters to be investigated...)
    ...
    and this instance (assuming there are never two mencoders running at the same time) would be limited to 40% cpu without the daemon part having to remind the process it is limited...?

    Could be good for the pc, i'm looking to trim it's idling ram at a minimum, i'm stuck at 45MB atm... i could save a few more MB's without the daemon...

    Thanks for the input...
    El Belgicano
    -----------------
    Laptop: 5 years old Asus M6N (ATI9600/9700 graphics, 512Mb RAM, Intel Mobile 1.66GHz, 60Gb HDD) running 10.04-Lucid Lynx pretty nicely.

  4. #74
    Join Date
    Mar 2007
    Beans
    623

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

    Quote Originally Posted by El_Belgicano View Post
    Mostly i run mencoder through a script, thus if i follow your thinking, i could change my script
    In you case I would create a bash file line on destkop or something and then just double click on it to run mencoder.
    The code could be something like:
    Code:
    #!/bin/bash
    mencoder... 
    PID=$(ps -eo pid | grep "mencoder..." | grep -v grep | gawk '{print $1}')
    cpulimit -p $PID -l 40 -z
    Quote Originally Posted by El_Belgicano View Post
    Could be good for the pc, i'm looking to trim it's idling ram at a minimum, i'm stuck at 45MB atm... i could save a few more MB's without the daemon...
    I am sceptical about this statement. I don't think you will preserve much of RAM, specially not mega bytes. But you can test the code and I would be happy to see the results how many RAM you have spare.
    Last edited by abcuser; November 3rd, 2011 at 05:26 PM.

  5. #75
    Join Date
    Aug 2007
    Location
    Belgium
    Beans
    176
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    Quote Originally Posted by abcuser View Post
    In you case I would create a bash file line on destkop or something and then just double click on it to run mencoder.
    The code could be something like:
    Code:
    #!/bin/bash
    mencoder... 
    PID=$(ps -eo pid | grep "mencoder..." | grep -v grep | gawk '{print $1}')
    cpulimit -p $PID -l 40 -z
    For now i modified my script to:
    Code:
    cpulimit -e mencoder -l 25 &
    mencoder [...]
    killall cpulimit &
    Now i have two questions:
    - What if i put two mencoder lines instead of one, would they both respect the speed limit?
    - Any idea on how to be more "elegant" than killall? I feel like a butcher now...

    Quote Originally Posted by abcuser View Post
    I am sceptical about this statement. I don't think you will preserve much of RAM, specially not mega bytes. But you can test the code and I would be happy to see the results how many RAM you have spare.
    Well, without the daemon running i can spare a MB or two while idle... since no unexpected process has to be limited, starting cpulimit when needed sounds lighter...
    El Belgicano
    -----------------
    Laptop: 5 years old Asus M6N (ATI9600/9700 graphics, 512Mb RAM, Intel Mobile 1.66GHz, 60Gb HDD) running 10.04-Lucid Lynx pretty nicely.

  6. #76
    Join Date
    Mar 2007
    Beans
    623

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

    Quote Originally Posted by El_Belgicano View Post
    - What if i put two mencoder lines instead of one, would they both respect the speed limit?
    In this case then I suggest to use code already discussed on post #14, but in your case use mencoder, like bellow.
    Code:
    #!/bin/bash
    PIDS=$(ps -eo pid | grep "mencoder" | grep -v grep | gawk '{print $1}')
    for i in $PIDS
    do
        cpulimit -p $i -l 40 -z &
    done
    Quote Originally Posted by El_Belgicano View Post
    - Any idea on how to be more "elegant" than killall? I feel like a butcher now...
    Killing is never elegant. I don't see any point of changing this command if it is working fine.

    Quote Originally Posted by El_Belgicano View Post
    Well, without the daemon running i can spare a MB or two while idle... since no unexpected process has to be limited, starting cpulimit when needed sounds lighter...
    Interesting findings, thanks for sharing the info. Sparing RAM is very important on netbooks. I have never thought of RAM usage because of having several GB of RAM on PC and I can spare one or two MB.

  7. #77
    Join Date
    Aug 2007
    Location
    Belgium
    Beans
    176
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    Quote Originally Posted by abcuser View Post
    In this case then I suggest to use code already discussed on post #14, but in your case use mencoder, like bellow.
    Code:
    #!/bin/bash
    PIDS=$(ps -eo pid | grep "mencoder" | grep -v grep | gawk '{print $1}')
    for i in $PIDS
    do
        cpulimit -p $i -l 40 -z &
    done
    Is there any hidden advantage to prefer "-p" over "-e"?
    Right now i'm using:
    Code:
    function encode()
    {
    	mencoder [...] (first pass)
    	mencoder [...] (second pass)
    }
    cpulimit -e mencoder -l 20 &
    encode [args1]
    encode [args2]
    killall cpulimit &
    It's looking like the 20% is being respected for all "mencoder" lines in the speed limited zone... Not done testing though, the script is running right now...

    Quote Originally Posted by abcuser View Post
    Killing is never elegant. I don't see any point of changing this command if it is working fine.
    Then i'll keep feeling like a butcher...

    Quote Originally Posted by abcuser View Post
    Interesting findings, thanks for sharing the info. Sparing RAM is very important on netbooks. I have never thought of RAM usage because of having several GB of RAM on PC and I can spare one or two MB.
    I got 512MB of RAM on that laptop, but for some time now i've been looking to make it as light as possible while idle... Where i'm now, even going from a colored root window to using an image as wallpaper means a change from 42-43 to 45-47 MB (with X, ssh, mpd -paused- and a conky)
    Last edited by El_Belgicano; November 5th, 2011 at 06:53 PM.
    El Belgicano
    -----------------
    Laptop: 5 years old Asus M6N (ATI9600/9700 graphics, 512Mb RAM, Intel Mobile 1.66GHz, 60Gb HDD) running 10.04-Lucid Lynx pretty nicely.

  8. #78
    Join Date
    Mar 2007
    Beans
    623

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

    Quote Originally Posted by El_Belgicano View Post
    Is there any hidden advantage to prefer "-p" over "-e"?
    In this case it is not. But in my script in #1 post there is easier to track which PIDs are already cpulimited and which are not by using uniq process ID.

  9. #79
    Join Date
    Oct 2011
    Beans
    13

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

    Well, I'm no longer having cpulimit its self, but when I checked on cpulimit again today (after running a few days) I see that I have cpulimit processes on 2 of the whitelist processes. I'm perplexed.

    I tried taking the base command:

    Code:
    top -b -n1 -c | gawk 'NR>6' | grep -E -v 'my|whitelist|processes'
    And it does indeed exclude the processes that I see limited.

    Before I run off and hack up the script with a ton of debug statements and painfully monitor it for the next few days I thought I'd see if this perks anyones ears.

    My configuration on the cpulimit_daemon.sh is below, everything else is out-of-the-box as is laid out in this post.


    Code:
    #!/bin/bash
    # ==============================================================
    # CPU limit daemon - set PID's max. percentage CPU consumptions
    # ==============================================================
    
    # Variables
    CPU_LIMIT=3             # Maximum percentage CPU consumption by each PID
    DAEMON_INTERVAL=2       # Daemon check interval in seconds
    BLACK_PROCESSES_LIST=   # Limit only processes defined in this variable. If variable is empty (default) all violating processes are limited.
    WHITE_PROCESSES_LIST="openvpn|squid|log_helper|url_rewrite_helper|ssh|nrpe|cpulimit|statusreader"   # Limit all processes except processes defined in this variable. If variable is empty (default) all violating processes are limited.

    ps -ef | grep cpulimit
    Code:
    root      5833 32058  0 21:06 ?        00:00:01 cpulimit -p 5774 -l 3 -z
    root     13439 32058  0 Nov03 ?        00:07:04 cpulimit -p 951 -l 3 -z
    root     14018 32058  0 Oct31 ?        00:10:18 cpulimit -p 5655 -l 3 -z
    root     15825 32058  0 Nov01 ?        00:10:07 cpulimit -p 614 -l 3 -z
    root     20063 32058  0 Nov01 ?        00:09:43 cpulimit -p 1 -l 3 -z
    root     32657 32058  0 Nov03 ?        00:06:09 cpulimit -p 501 -l 3 -z
    Those PIDs
    Code:
    1001      5774  5772  0 21:06 pts/0    00:00:01 -bash
    root       951     1  0 Oct24 ?        00:05:54 /bin/bash /opt/openvpn/bin/statusreader
    root      5655     1  0 Oct24 ?        00:11:31 /bin/bash /opt/squid/bin/log_helper
    root       614     1  0 Oct24 ?        00:05:21 /usr/sbin/vnstatd -d
    root         1     0  0 Oct24 ?        00:36:17 /sbin/init
    syslog     501     1  0 Oct24 ?        00:06:35 rsyslogd -c5

  10. #80
    Join Date
    Mar 2007
    Beans
    623

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

    This is strange problem, I never faced the problem of this kind. Did you change some WHITE_PROCESSES_LIST variable like adding "openvpn" string to the variable and forgot to restart daemon?

    === From first post of this thread ===
    Restart cpulimit service
    If you change some variables settings in /usr/bin/cpulimit_daemon.sh like CPU_LIMIT, DAEMON_INTERVAL, BLACK_PROCESSES_LIST or WHITE_PROCESSES_LIST, then after changing settings you must restart service.
    Code:
    sudo service cpulimit restart
    Last edited by abcuser; November 8th, 2011 at 05:57 PM.

Page 8 of 13 FirstFirst ... 678910 ... 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
  •