I'm sure you've noticed that for many servers, the website loading time is quite long if you're the first visitor for a couple of hours. Do you have any idea why this is the case (is it just server cache?) and how to make the site fast even for that first visitor? Let's take a normal LAMP setup in this case. Thanks for your help!
Asked
Active
Viewed 4,000 times
1
-
In the case of most database engines, per database configuration for "AUTOCLOSE" or similar feature can be a culprit. – Adam Caviness Apr 03 '12 at 13:00
1 Answers
8
There lots of potential causes. There's almost certainly not just one single reason.
A few possibilities:
- The website is running under some pooling mechanism like FastCGI, mod_php/mod_perl/mod_python, etc. If either these or Apache are not configured to keep a minimum pool of servers, they will have to restart the application when a new request arrives and there are no servers available with that application already loaded.
- The application uses a database connection pool. Same problem as above, except it's the database connection that needs to be re-established. Some relational databases can be very slow at opening a new connection (lots of overhead)
- Various caching mechanisms (for high performance sites running load balancers or caches like memcached) along the way may need to refresh their information from the site directly if the information they have is stale. Could also apply to your browser's local cache: while it can normally ignore all the additional static files on a website like css, js, images, once these expire from the cache it needs to re-fetch them.
- Sites may have maintenance activities like backups that take place when their load is low and the site is not being accessed.
- Could even be as low level as the server's OS disk caching, which may have had its cache filled with other sites on the same server, pushing out the cached version of the site that hasn't been accessed in awhile (that's exactly what the disk cache is supposed to do, cache frequently used files, not infrequently used ones). The delay this should cause would most likely be very small and not noticeable to a human.
Mitigation strategies of course depend on what the actual cause is. But a few things that should normally be done:
- Make sure Apache's MinSpareServers/MinSpareThreads and other performance settings are configured properly. Try to understand how, when and why Apache spawns more servers/threads.
- Make sure any application servers like FastCGI are also properly configured to keep a sufficient pool available.
- Correctly configure database connection pooling or keep a persistent database connection always open.
- Ensure all your included files (css, js, etc) are cacheable and have reasonable expiry times.
cecilkorik
- 445
- 1
- 4
- 13