DEV Community

Discussion on: What happens to MySQL when hitting 100% CPU usage?

Collapse
 
mrbenosborne profile image
Ben Osborne

Each query inserts around 250000 rows or updates them, about 20 columns.

I saw the process list and the server was running fine, what I’m asking is why when the CPU was at 100% was it able to still serve requests ?

Collapse
 
rhymes profile image
rhymes

what I’m asking is why when the CPU was at 100% was it able to still serve requests ?

A combination of OS multi tasking, multi core and MySQL multi threading.

I'm not sure what sort of machines MySQL RDS runs on but is probably running on a Linux distribution which supports multiple threads running on a multi core CPU. This means that you effectively have N CPUs used by various threads. I'm not familiar with MySQL's architecture but I guess each connection is assigned a thread in a pool.

Even if you have a single CPU core each connection is handled by a separate unit of work (the thread), scheduled with a time slice by the kernel scheduler.

100% doesn't mean that your CPU is effectively disabled, it means that the computations inside that process are using 100% of the CPU allotted in a single scheduling period.

Most requests are I/O bound, so they don't bother the CPU much.

There are ways to overwhelm a database but if it can't handle 4 simultaneous inserts, then it's a toy DB :D