How to determine why a MySQL server has become slow and requests sometimes time out?
You need to tune your database. This is a complicated process with many variables and decision trees. Without specifics we can only really get you started here.
If you have a script that runs lots of SQL and slows down your DB, and your cpu and memory usage are fine while it's running, then you are probably running into I/O problems. i.e. You are hammering the disk. You need to look through the SQL used in the script and tune it. For example, it might be generating lots of full table scans or creating too many transaction logs that are slowing down the DB. To start with, check if any unneccessary full table scans are taking place, and see if you can add indexes to the relevant columns to reduce the I/O. then report back and we can go from there.
The above linked MySQLtuner script is excellent but understanding the results may be challenging for you if you are inexperienced with databases. Do read the disclaimers on the main page before you get started: https://github.com/major/MySQLTuner-perl
You must find the real source of your bottleneck.
Memory usage only at 50%? Maybe you don't give mysql enough memory. Try the MySQLTuner Skript. It might point you out what is wrong with your server.
Check whether only one core is used and you have a lot of cores - this could lead to a false impression that the cpu usage is low.
To help you diagnose your the problem, Percona has the percona-toolkit collection which can be used for free. In particular, you might want to use pt-stalk to diagnose issues faced by your server. The output generated from these tools will help you determine what to tune or how to tune your server.
They also have Percona Cloud Tools which is a hosted service providing access to query performance insights for all MySQL uses. Although this service is in beta, I would recommend you try it.