MySql inserts high CPU load MySql inserts high CPU load nginx nginx

MySql inserts high CPU load


By "later" processing, do you possibly mean 1 hour or 1 day later?If that is the case then I would write the information to a CSV file which you rotate out once an hour or so and then when you need to do your "later"processing you can load the files into MySQL using LOAD DATA INFILE

http://dev.mysql.com/doc/refman/5.1/en/load-data.html

I have had LOAD DATA INFILE load 100s of MB of information in less than a minute, this method would be a great way to speed up your web response.


Are you running that PHP code in a loop?You can insert more than one row at a time in a single query, and this may help lower the CPU load. All you need to do is provide a comma separated list of values, something like this:

insert into rawreports(date, data, project_id) values (('$date1', '$data1', '$project_id1'),('$date2', '$data2', '$project_id2'), .....)")

also if you are running in a loop, you don't need to repeat the new mysqli() for every iteration.


no indexes,

That is not quite true.
I'd remove an index in the first place.
In a log-type table it doesn't make any sense.

By the way, you can use textual logs as well. For the later processing.

To get some detailed info you may run these commands from mysql console while your server is under it's usual load:

> SET profiling = 1;> INSERT an example query> SHOW PROFILE ALL

also try silly

SHOW PROCESSLIST;

which doubtfully will reveal something useful but at least worth trying