I have a web application calling a mysql database through vpn.
Sometimes (when a lot of customers are using the system) the cpu from the remote mysql host reaches 100% and everything goes so slow (I even get error 500).
I turned on slow queries log and nothing goes in there.
I saw the processlist and there are some queries (around 30 which is normal since I use a lot of ajax) that they are sorting data.
The query that does that is (with numbers filled in):
SELECT cs.id_client as id_client, TIMESTAMPDIFF(SECOND,cs.call_start,cs.call_end) AS realduration, cs.*, cs.call_start + INTERVAL 0 HOUR as call_start_corrected, cs.call_end + INTERVAL 0 HOUR as call_end_corrected,`c`.`cost` AS `cscost` ,`c`.`call_rate` AS `ccall_rate`
FROM `callscallshop` AS `cs` LEFT JOIN
`calls` AS `c`
ON `c`.`call_start` = `cs`.`call_start`
WHERE `c`.`caller_id` = `cs`.`caller_id` AND
`cs`.`id_client` IN (9301) AND
year(cs.call_start) = year(now()) AND
month(cs.call_start) = month(now()) AND
week(cs.call_start) = week(now()) AND
`cs`.`invoice_id` = '-1'
ORDER BY cs.call_start DESC
I run the above on a local copy of the database and I get 0.0027 as time to execute.
I remove the time difference and the ordering and the difference time execution is so small..
On google chrome I see that the ajax response goes over 30s sometimes.
The task manager of the db server shows that the main load is mysql.exe
Does any of you have a clue to help me solve this?
Do you think is the query or something with the servers?
UPDATE
Ajax calls wait up to 30s every day in the afteroon!! It seems to be cpu usage that reaches 100%.
They do not allow to apply indexing on the server.
I will be grateful for any idea.