I am running a LAMP system with Ubuntu 14.04. I have 4 cores and 8GB Ram on my server
The problem is that when I connect to my website after idle period( 2-3 hours or more) the it takes lot of time to load. Some times around 60-110 seconds.
The website loads slow in 2 scenarios
1) This happens when website is idle for 2-3 hours or more.In the second attempt and afterwards, after accessing the website after idle period in The website loads in 8-10 seconds.
2) I also have an RSS fees which runs every one hour. The website also takes 60-70 seconds while the RSS feed runs.
Please let me know how to solve the problem.
Adding Stuff
First image is when RSS is not running in cron and second one is when RSS is running in cron
total used free shared buffers cached
Mem: 7985 3981 4003 0 183 1943
-/+ buffers/cache: 1855 6130
Swap: 0 0 0
Best Answer
This is most probably caused by a memory issue. Swapped out memory to be precise. There must be some sort of a memory intensive task running in the idle period, and all your Apaches, phps, and others get swapped out. Once you try to connect, they get swapped in, but it takes a long time. Once they are back in memory, everything works fine. Solution:
Add more memory to your machine.
Make the crucial processes less swappable by using cgroups.
Before you do that, diagnose your memory usage, system load, the swapiness parameter to verify that this is indeed the culprit.