Earlier quoted context omitted.
I can't really see how your code or queries could cause mysql or apache to gradually slow down and then speed up when you kill the processes. It sounds more like virtual memory of some process is growing too high causing thrashing, or apache has too many children, or you're running out of some resource, or something is leaking memory. Regarding apache/mysql: are you using stock distributions, or did you build them yo…
>I can't really see how your code or queries could cause mysql or apache to gradually slow down and then speed up... Actually, we've ascertained that it is not the code or queries that cause this per se, but it is the traffic patterns - human visitors + SE crawlers... at times, there are (natural) traffic bursts and that's when the server starts choking. apache/mysql - stock distros, with some config tweaks, mainly i…
- Limit the max apache child processes/threads to what your server can easily handle. That way during busy periods people will get an occasional error connecting to your server (or wait a while), but at least mysql won't be thrashing your server so it might improve overall performance during the busy times.
- Figure out which queries are using the most cpu time and optimize those.
- Have a look at your most frequently accessed pages and see if you can optimize database access in those pages.
However if your users are still sometimes getting error messages accessing your site you have to ask yourself whether that is going to hurt your business.