MySQL Server CPU Usage – AWS MySQL Server Stuck at 50% or Throttled

amazon ec2MySQLmysql-5.6windows-server

I have a c4.large EC2 instance which is running Windows Server 2012 and MySQL.

When I look at the CPU usage on the machine it seems that MySQL is capping out at 50% CPU usage when the system is under load, it also looks like this is relative to some kind of throttling but I am not sure why this is happening.

The c4.large instance comes with 2 vCPUs and dedicated ECU and I can see from the screenshot below that these are both being used but maybe the combined total of this is being capped?

I am not sure if this is a MySQL issue or relative to Amazon Web Services like a potential systems issue or if it's some kind of misconfiguration on my side.

Does anyone have any idea why this is happening?

Screenshot of system performance

Best Answer

This is probably neither throttling nor a misconfiguration, nor anything related to AWS. Consider these points:

  • A c4.large instance has 2 cores.

  • Any given query running in MySQL runs entirely within a single thread, and

  • a single thread within a process can only run on 1 core at any moment in time (though presumably the Windows process scheduler can move it between the cores at will), and

  • 100% utilization of 1 core by 1 thread would show up as 50% CPU utilization.

What you appear to have here, rather than the server really being "under load," is a single CPU-bound query running.

Any user with the PROCESS privilege can run the SHOW FULL PROCESSLIST; query in MySQL and see what all the session (connection) threads in MySQL Server are doing at the moment. Run this and you should find your CPU hog. If you run another instance of the same query, you should find that the CPU utilization hits 100% with two CPU expensive queries running concurrently. (Then you'll want to fix/optimize that query.) The TIME column tells you how long the connection has been in its current state.