0

From outside MySQL, I know I can do many things to know what the CPU usage of a process is, ie. top.

But, from an internal standpoint, I would like to know if it is possible to run a query from MySQL to know what the system CPU is or the CPU consumption of the current thread is.

I'm running massive queries nightly through the Event Scheduler and my DB server gets stuck at 100% CPU for a few minutes blocking or slowing down users around the globe.

I've tried to research a way to limit CPU usage by thread or user, but it doesn't seem to be possible yet.

So, I'm trying to do something along the lines of the following in my Event:

IF (SELECT CPU_USAGE() > 0.8) THEN
    REPEAT
        SLEEP(0.01);
    UNTIL (SELECT CPU_USAGE() < 0.25)
    END REPEAT;
END IF;

Obviously CPU_USAGE() doesn't exist, but if there is something similar I can do to accomplish a similar effect, I'm all ears. Thanks.

P.S. I'm on Amazon RDS

2
  • It might be easier/better to limit the number of threads your tasks can use at a given time. Commented Mar 24, 2014 at 15:21
  • How would this be handled? Commented Mar 27, 2014 at 1:36

1 Answer 1

2

I am afraid there is no such option select option natively in MySQL.

If you are inside mysql client command line, you can call the "top" command from inside the MySQL client using this command : \! top, but I don't think this is what you need.

The best answer is probably to use a UDF from SYS functions. More info here. I have no experience using it but it seems the closest to what you need.

Sign up to request clarification or add additional context in comments.

1 Comment

This would be great in an ideal situation and maybe in the future, but I am on Amazon RDS which unfortunately doesn't allow me to import those UDF's.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.