Webpages load slowly...
Now, website is working, but pages are loading slow, sometimes very fast, and other times it takes 20+ seconds to open a page, and sometimes a blank page is open.
I run free -m when page is loading slow and get something like this:
total used free shared buffers cached
Mem: 1001 919 82 21 42 553
-/+ buffers/cache: 323 678
Swap: 1023 31 992
if I understand right, this means I have 678 mb free. Then what is the problem why are pages loading so slow most of the times ?
Some of the settings I have:
keep alive - OFF
MinSpareServers 2
MaxSpareServers 5
MaxRequestWorkers 10
MaxRequestsPerChild 0
in my.cnf
key_buffer = 64M
maxallowedpacket = 1M
thread_stack = 64K
threadcachesize = 8
myisam-recover = BACKUP
table_cache = 8
querycachelimit = 1M
querycachesize = 16M
in error.log i have errors like
Maximum execution time of 30 seconds exceeded in…. and sometimes pages open blank, nothing there…
and also
server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting, but I tried that and it did not worked.
Any help would be appreciated!
8 Replies
Have you tried changing the settings for apache and mysql to match the recommended settings in the Linode "Hosting a Website" guide [1]? They are optimized for a 1GB Linode.
Apache
–------
KeepAlive Off
MinSpareServers 6
MaxSpareServers 12
MaxClients 80
MaxRequestsPerChild 3000
MySQL
max_connections = 75
key_buffer = 32M
maxallowedpacket = 1M
thread_stack = 128K
table_cache = 32
Best,
Lev
[1]
@AndrijaM:
yes, and still the same, page loads for 30 seconds most of the time…
First, check on your cache plugin to see if it is working…I think most of them put an HTML comment in at the bottom of every page load so you can see what it's doing (check when NOT logged in to WP site).
You have a PHP script that is timing out, I don't think this is a memory issue. Try disabling all non-essential plugins and seeing what happens.
APC speeds up the PHP end of things, which is good for Wordpress.
A Wordpress cache plugin is good because it makes Wordpress serve an html page rather than running all of the PHP.
APC + Wordpress cache plugin together are better still.
Usually a Wordpress cache plugin will serve up cached results to visitors who are not logged in, and serve up fresh content to logged in visitors. I'm not sure of the lifespan of the cached entries, but it makes a big difference if your content isn't continually changing.
Keep in mind we don't know which distro you're running so APC may not be the right answer depending on your version of PHP.
@AndrijaM:
I disabled all plugins, but nothing changed, do not use cache plugin at all (not like wordpress cache plugin, but I did install php-apc) , you thing that might help me ?
I think a working WordPress cache plugin will help you, yes, because it's much less processing to serve pages (usually). It's hard to say anything for sure without seeing your site. It's weird that you're exceeding script execution times even without plugins. My next guess without knowing any more information is that your wordpress installation could be compromised.
KeepAlive ON
MaxKeepAliveRequests 200
KeepAliveTimeout 2
StartServers 7
MinSpareServers 7
MaxSpareServers 14
MaxRequestWorkers 90
MaxConnectionsPerChild 0
You could also try switching to mpm_event with php5-fpm which works well for high traffic on some of my other servers.
In addition to that, you might want to add the following code to your default.vcl and restart varnish.
In "sub vcl_recv" look for the section with req.request != "GET" and immediately underneath it add the code below - I've included the code your'e looking for for reference (don't duplicate it).
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$"
|| req.url ~ "\.(css|js)\?[a-z]*=[0-9]*$") {
unset req.http.cookie;
}
This will strip cookies from images and css - you really don't need cookies and it stops varnish from caching the static files.
Then in "sub vcl_fetch" add this right at the very beginning:
if(req.url ~"\.(png|gif|jpg|swf|css|js)$" ||
req.url ~"\.(css|js)\?[a-z]*=[0-9]*$") {
unset beresp.http.set-cookie;
set beresp.ttl = 180s;
set beresp.http.X-Cache = "HIT";
return (deliver);
}
This will remove the cookie from the response to the user's browser, set a TTL of 180s (so all your images / css / js only get loaded into memory every 2 minutes), and set an extra cache header so you can check that its working.
Hopefully that helps.
J.