Speed up apache webserver with mod_pagespeed and memcached on Debian 7 (Wheezy)

Want to support HowtoForge? Become a subscriber!
 
Submitted by till (Contact Author) (Forums) on Wed, 2014-04-16 11:59. :: Debian | Apache

Speed up Apache webserver with mod_pagespeed and memcached on Debian 7 (Wheezy)

 

Version 1.0 
Author: Till Brehm<t [dot] brehm [at] howtoforge [dot] com> 
 Follow howtoforge on Twitter
Last edited 2014-04-16

 

The page load time gets more and more important for websites to provide a better user experience and it is important for the search engine ranking as well. Google has developed the apache module "mod_pagespeed" to optimize and streamline the content delivery of the apache webserver which reduces the load times of pages, especially when they use many assets like css files, javascript includes and images. The pagespeed module uses a filesystem based cache by default, in this tutorial I will configure pagespeed to use memcached to store the cached items in memory which is faster then the default cache method. This Tutorial can be used on any apache Installation. It is compatible with the ISPConfig 3 Perfect Server tutorials.

 

Installation of mod_pagespeed

Google provides Debian packages for mod_pagespeed for 32 and 64 bit installations.

Debian 64 bit (this should be the right for most current servers)

cd /tmp
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb 
dpkg -i mod-pagespeed-stable_current_amd64.deb

Debian 32 bit (this should be the right for most current servers)

cd /tmp
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.deb 
dpkg -i mod-pagespeed-stable_current_i386.deb

finally restart apache to activate the pagespeed module

service apache2 restart

 

Installation of memcached

The memcached package is available in the Debian repositories, so we can install it with apt directly

apt-get install memcached

Now check with the command "netstat -tap | grep memcached" if memcached is running

netstat -tap | grep memcached

The result shall look similar to this:

root@server1:/tmp# netstat -tap | grep memcached
tcp 0 0 localhost.localdo:11211 *:* LISTEN 27420/memcached

In the output we see the port were memcached is listening on: 11211, we need that port for the next step.

Configure mod_pagespeed to use memcached

vi /etc/apache2/mods-available/pagespeed.conf

find the line

[....]
# ModPagespeedMemcachedServers localhost:11211
[....]

and remove the #, so that it looks like this:

[....]
ModPagespeedMemcachedServers localhost:11211
[....]

If you have plenty of memory in your server, then you can get a further speedup by removing the # in front of this line:

[....]
ModPagespeedCreateSharedMemoryMetadataCache "/var/cache/mod_pagespeed/" 51200
[....]

Finally restart apache to apply the changes:

service apache2 restart

Now mod_pagespeed will use memcached as storage backend. You can get usage statistics from memcached with the following command:

echo stats | nc 127.0.0.1 11211

root@server1:/tmp# echo stats | nc 127.0.0.1 11211
STAT pid 27420
STAT uptime 422
STAT time 1397644927
STAT version 1.4.13
STAT libevent 2.0.19-stable
STAT pointer_size 64
STAT rusage_user 0.012000
STAT rusage_system 0.000000
STAT curr_connections 5
STAT total_connections 6
STAT connection_structures 6
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 6
STAT bytes_written 0
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0
END

Press [ctrl] + c to get back to the command prompt.

Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by pinky (registered user) on Fri, 2014-06-27 20:34.
It should maybe be noted that the nc command is supplied by the netcat package.