Page 11 of 13 FirstFirst ... 910111213 LastLast
Results 101 to 110 of 122

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

  1. #101
    Join Date
    Apr 2007
    Beans
    19

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

    Is there any way to run it on mac osx? I know that cpulimit works fine on osx

  2. #102
    Join Date
    Mar 2007
    Beans
    627

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

    @gagginaspinnata, I don't know, I don't have a mac, but osx is a unix like system, so it may work. You will need to test it to see how it is working - most probably the start-up scripts will not work, but cpulimit deamon could.

  3. #103
    Join Date
    Jan 2013
    Beans
    1

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

    Hi,

    I have two processes on my server with the same name and using your scripts it only traps one of them.

    So for example is you ran this commend twice to generate fake load.
    dd if=/dev/zero of=/dev/null &
    And then in the blacklist you set the variable equal to dd
    it would only trap the first instance of the process name. Can you let me know how I can trap all processes with this name on the server rather than just the first one.

    P.S. abcuser - u provided an awesome script.

  4. #104
    Join Date
    Jul 2011
    Beans
    12

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

    Don't limit root processes. When I tried to limit Xorg process via
    gnome-terminal, system hanged(ubuntu 12.04).
    Please add "root" to white list as below
    WHITE_PROCESSES_LIST="root"

  5. #105
    Join Date
    Aug 2005
    Location
    .nl
    Beans
    189
    Distro
    Xubuntu 13.10 Saucy Salamander

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

    I realise this thread is a few years old already, but I found it only today and I can confirm the script is still very useful. It works and it is very clever. Thank you, Abcuser, if you are still reading this.

    There is one small change I had to make, which was to insert
    Code:
    export LANG=C
    as the second line (after #!/bin/bash of course). Since the script uses the output of top and other commands, this line makes sure this output conforms to the default locale.

    For instance, the CPU usage column in top is shown with a comma as the decimal seperator in LANG=nl_NL.UTF-8, which is my system locale, but the script expects a decimal point.

    It makes sense to always use LANG=C in every script you write. Or at least, if you are going to publish them on an international web forum...

  6. #106
    Join Date
    Mar 2007
    Beans
    627

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

    @Olav, thanks for your info. I can't edit first post in this thread anymore. I can't do it for years... some forum policy that old post can't be changed.

    There was also another decision that tutorials are moved to some wiki or something... don't know in my humble opinion bad decision, because in forum you can always get feedback as author of tutorial and end-users can report bugs, ideas etc. So double way communication, collaboration etc.

  7. #107
    Join Date
    May 2013
    Beans
    4

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

    Hi.

    I have an issue with this daemon.
    I'm using it on Debian GNU/Linux 7.3 .

    The problem is that it keeps crashing the MySQL server.
    If I stop the daemon, MySQL works normally.

    To debug this, I tried running "/usr/bin/cpulimit_daemon.sh" in console.
    And this is what I get:

    Code:
    root@hsh:~# /usr/bin/cpulimit_daemon.sh
    /usr/bin/cpulimit_daemon.sh: line 9: tar|zip: command not found
    while the script is still waiting.
    After a short period of time, I get this:

    Code:
    Process 20913 detected
    Process 20913 dead!
    And this is the moment I get MySQL crashed. The MySQL crash is confirmed by /var/log/syslog also:

    Code:
    Jan 13 10:12:07 hsh mysqld_safe: Number of processes running now: 1
    Jan 13 10:12:07 hsh mysqld_safe: mysqld process hanging, pid 20913 - killed
    Jan 13 10:12:07 hsh mysqld_safe: mysqld restarted
    If I let the script running, it keeps crashing MySQL on and on.

    In /usr/bin/cpulimit_daemon.sh at line 9, i have the following code:

    Code:
    BLACK_PROCESSES_LIST= "tar|zip"   # Limit only processes defined in this variable. If variable is empty (default) all violating processes are limited.
    tar and zip are the proccesses I'm watching for not to override my limit.
    No matter if I write any process in the black list or not, I keep getting MySQL crashed.

    Does anyone have any clue about this?
    Thanks.
    Last edited by likudio; January 13th, 2014 at 11:06 AM.

  8. #108
    Join Date
    Mar 2007
    Beans
    627

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

    It looks to me that NEW_PIDS_COMMAND also gets into MySQL process. Maybe NEW_PIDS_COMMAND variable is not correctly assined by deamon.

    In terminal can you please execute command:
    Code:
    top -b -n1 -c | grep -E 'tar|zip'
    Please look at the last column of above output. Is there any of MySQL process involved? Please post the output to this forum.

    Grep command above looks for regular expression pattern!!! For example if process name (from top command) returns e.g. mysqltar (notice tar in the name of the process) then this process is going to be assigned to NEW_PIDS_COMMAND. It looks to me that at least one of MySQL process has 'tar' or 'zip' in its name.

    So for example if above command returns the: "mysqltar" and you would like to limit only "tar" you can use a regular expression to properly filter out only "tar". So try this out or one of its variations (with or without ^ OR with or without $)
    Code:
    BLACK_PROCESSES_LIST= "^tar$|^zip$"
    Note: ^ - is a special character that tells grep that string has to be the FIRST character in the line.
    Note: $ - the same as above but LAST.

    Hope this helps. If not then please reply to this forum the output of first command above.
    Last edited by abcuser; January 13th, 2014 at 01:27 PM.

  9. #109
    Join Date
    May 2013
    Beans
    4

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

    Nope, that doesn't seem to be the issue.
    Here's the only output of your command:

    Code:
    root@hsh:~# top -b -n1 -c | grep -E 'tar|zip'
    24753 root      20   0  7780  880  768 S    0  0.0   0:00.00 grep -E tar|zip
    No MySQL process involved in the grep pattern.
    I even tried to delete all the string from the blacklist line and still crashes MySQL, even without having any text in the pattern string.
    Line 9 looks like this now:
    Code:
    BLACK_PROCESSES_LIST= ""   # Limit only processes defined in this variable. If variable is empty (default) all violating processes are limited.
    ...and the result:

    Code:
    root@hsh:~# /usr/bin/cpulimit_daemon.sh
    /usr/bin/cpulimit_daemon.sh: line 9: : command not found
    Process 23990 detected
    Process 23990 dead!
    ^C
    Confirmed by /var/log/syslog:

    Code:
    Jan 13 14:42:00 hsh mysqld_safe: Number of processes running now: 1
    Jan 13 14:42:00 hsh mysqld_safe: mysqld process hanging, pid 23990 - killed
    Jan 13 14:42:00 hsh mysqld_safe: mysqld restarted
    So the issue still remains.
    But, as a side question... if the purpose of the daemon is to limit the CPU usage, why does it crash?
    It has to do with mysql_safe which thinks that the proccess is hanging and tries to restart it, right?

    Anyway, this was just a side question.
    Still can't figure it out why does it try to limit the MySQL process (and crashes it also)...

  10. #110
    Join Date
    May 2013
    Beans
    4

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

    As a (PHP) developer, I started to debug the code.

    I have put the following echos in the if lines to see which block gets execute.
    It's pretty hard for me as I don't know exactly the bash syntax... but I hope I'll figure it out. (any help is appreciated).

    So:

    Code:
    # Check if one of the variables BLACK_PROCESSES_LIST or WHITE_PROCESSES_LIST is defined.
    if [[ -n "$BLACK_PROCESSES_LIST" &&  -n "$WHITE_PROCESSES_LIST" ]] ; then    # If both variables are defined then error is produced.
       echo "At least one or both of the variables BLACK_PROCESSES_LIST or WHITE_PROCESSES_LIST must be empty."
            echo 10;
       exit 1
    elif [[ -n "$BLACK_PROCESSES_LIST" ]] ; then                                 # If this variable is non-empty then set NEW_PIDS_COMMAND variable to bellow command
       NEW_PIDS_COMMAND="top -b -n1 -c | grep -E '$BLACK_PROCESSES_LIST' | gawk '\$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
            echo 20;
    elif [[ -n "$WHITE_PROCESSES_LIST" ]] ; then                                 # If this variable is non-empty then set NEW_PIDS_COMMAND variable to bellow command
       NEW_PIDS_COMMAND="top -b -n1 -c | gawk 'NR>6' | grep -E -v '$WHITE_PROCESSES_LIST' | gawk '\$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
            echo 30;
    else
       NEW_PIDS_COMMAND="top -b -n1 -c | gawk 'NR>6 && \$9>CPU_LIMIT {print \$1}' CPU_LIMIT=$CPU_LIMIT"
            echo 40;
    fi
    And I get 40 all the time, no matter what I put in variables.
    So... the last if block gets executed and that's the reason why I get MySQL crashed.

    1. I'll let you know as soon as I get any more information... I don't know why the first if blocks don't get executed.
    2. Anyway... the script purpose it's to limit the cpu usage, but MySQL crashes. How to avoid that? I still think that mysqld_safe thinks that the server is hanging and it restarts it... I have to find a way to avoid that.
    Last edited by likudio; January 13th, 2014 at 09:20 PM.

Page 11 of 13 FirstFirst ... 910111213 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
  •