I’m really new to server-side and I’ve been administrating a dedicated server for my website.
At peak hours the website is very slow, in order to know why I’ve been monitoring it using htop.
Some really long-lasting (more than few hours) mysql processes use up to 95% of the CPU !
The thing is I don’t know what queries might be the cause of it nor how to monitor it.
I do have a cron every quarter of hour that sometimes takes a long time to run but the time of the slow down is not always matching cron’s.
I’ve heard of a solution using a cron job killing too long mysql processes but wouldn’t it cause discrepancies in the db ?
Configure MySQL server to log slow queries, then look at them. You need to understand why these queries are so slow.
Most likely, these queries can be sped up by adding proper indexes, but this is not fast and hard rule – you need to understand what is really happening.
You can kill long-running queries, but if you have MyISAM engine it can corrupt your tables. In that case, seriously consider switching to Innodb engine. With transactional engine like Innodb, currently running transactions will likely be rolled back, but data should not be corrupted.