<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gj |</title>
	<atom:link href="https://blog.gaiterjones.com/category/magento/magento-optimisation/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/category/magento/magento-optimisation/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Tue, 23 Jun 2015 09:32:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Magento REDIS : system, session and full page cache management solution</title>
		<link>https://blog.gaiterjones.com/magento-redis-system-session-and-full-page-cache-management-solution/</link>
					<comments>https://blog.gaiterjones.com/magento-redis-system-session-and-full-page-cache-management-solution/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Fri, 19 Jun 2015 10:44:22 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Magento Cache Management]]></category>
		<category><![CDATA[Magento Optimisation]]></category>
		<category><![CDATA[redis]]></category>
		<category><![CDATA[cache]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1308</guid>

					<description><![CDATA[In computing, active data is often cached to shorten data access times, reduce latency and improve input/output (I/O). Because almost all application workload is dependent upon I/O operations, caching is...<a class="more-link" href="https://blog.gaiterjones.com/magento-redis-system-session-and-full-page-cache-management-solution/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>In computing, active data is often cached to shorten data access times, reduce latency and improve input/output (I/O). Because almost all application workload is dependent upon I/O operations, caching is used to improve application performance.</p>
<p>Magento is a very data and database intensive application. By enabling the Magento system cache you will instantly see an improvement in response times as Magento starts to cache database queries and system data. The default cache storage code uses the file system, i.e. Magento saves cache data to disk. Whilst this will certainly improve Magento responsiveness there are other cache storage options available that are much faster and there are additional types of data we can also cache to improve the overall responsiveness and speed of a Magento CE application.</p>
<h1>memcache and redis</h1>
<p>For most computer systems the fastest data storage medium is the physical memory, using memory as cache storage results in very quick data access times and Magento can get it&#8217;s data much quicker. For CE users with a small to medium sized shop there are two free popular open source memory caching systems, <a href="http://memcached.org/" target="_blank">Memcache </a>and <a href="http://redis.io/" target="_blank">Redis</a>. I have <a href="https://blog.gaiterjones.com/live-data-logging-with-memcache/" target="_blank">used Memcache in many different applications</a> for fast access to relatively non volatile (i.e. cached) data objects.</p>
<p>In a PHP environment memcache is easy to install and easy to use. It also works out of the box with Magento simply by configuring memcache as a storage option within the cache settings of the magento local.xml file. Redis was relatively new to me and is a slightly more advanced key-value cache and object store, it can be thought of as a simple memory resident database.</p>
<p>There are a lot of discussions as to the pros and cons of <a href="http://www.infoworld.com/article/2825890/application-development/why-redis-beats-memcached-for-caching.html" target="_blank">memcache vs redis</a> and for a complete Magento CE cache solution I would recommend using redis as it provides the best caching solution for Magento CE system, session and full page caches.</p>
<h1>what to cache</h1>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-1309" src="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen.jpg" alt="magento-cache-storage-management-screen" width="800" height="315" srcset="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen.jpg 800w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen-440x173.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen-620x244.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen-760x299.jpg 760w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen-550x217.jpg 550w" sizes="(max-width: 800px) 100vw, 800px" /></p>
<p>When you go to the Magento -&gt; System -&gt; Cache Management screen as shown above you will see the available cache storage management options for your Magento installation. Magento has a default built in cache management system that when enabled caches <strong>system</strong> data such as configuration, layouts, blocks, translations etc.</p>
<p>We can also use redis to create a fast Magento CE caching system for <strong>session</strong> and full page (<strong>fpc</strong>) data too.</p>
<figure id="attachment_1310" aria-describedby="caption-attachment-1310" style="width: 575px" class="wp-caption aligncenter"><img decoding="async" class="wp-image-1310" src="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-management-solution-redis.jpg" alt="Magento cache management solution with redis" width="575" height="534" /><figcaption id="caption-attachment-1310" class="wp-caption-text">Magento cache management solution with redis</figcaption></figure>
<p>This blog will look at how to install and configure a system, session and full page cache management solution for Magento CE v1.7.0.0 or greater using redis on Ubuntu 14.04 LTS.</p>
<h1>Install redis for Magento CE on Ubuntu 14.04</h1>
<p>Installing redis on Ubuntu is dead easy, simply use the following two apt commands to install the server and php5 code. At the time of writing this will install redis v2.8.4.</p>
<pre class="brush: plain; title: ; notranslate">
apt-get install redis-server
apt-get install php5-redis
</pre>
<p>The redis server will install and start an instance with it&#8217;s default configuration listening on TCP port <em>6379</em>. Check the server is running by typing <em>redis-cli ping</em> at the command prompt, you should get a satisfying <em>PONG</em> back.</p>
<p>We want to enable three Magento cache types : <strong>system</strong>, <strong>session</strong> and <strong>fpc</strong> (full page cache), whilst all three cache types could use one redis storage instance there are some issues where it is<a href="http://colin.mollenhour.com/2013/08/14/re-using-redis-as-a-cache-backend-in-magento/" target="_blank"> safer to give each cache type it&#8217;s own redis storage instance</a>. This also allows us to specifically <a href="http://fbrnc.net/blog/2013/02/redis-optimization">configure redis options for each cache type</a>, for example we can configure volatile session data to be redis persistent.</p>
<p>Ideally we want to configure three redis instances per Magento CE installation or shop :</p>
<ol>
<li><strong>system</strong> &#8211; redis port 6379</li>
<li><strong>session</strong> &#8211; redis port 6380</li>
<li><strong>fpc</strong> &#8211; redis port 6381</li>
</ol>
<h1>Configure multiple redis instances for Magento on Ubuntu 14.04</h1>
<p>To configure multiple redis instances that will start at system startup we need to replace the default redis-server init script in /etc/init.d with the script below courtesy of <a href="http://www.robofirm.com/2014/04/setting-up-multiple-redis-instances-on-a-single-magento-server/" target="_blank">robofirm</a>.</p>
<span class="collapseomatic collapse" id="id65fc30657a577"  tabindex="0" title="Show redis-server multiple instance init script"    >Show redis-server multiple instance init script</span><div id="target-id65fc30657a577" class="collapseomatic_content ">
[bash]
#!/bin/bash<br />
### BEGIN INIT INFO<br />
# Provides:             redis-server<br />
# Required-Start:       $syslog $remote_fs<br />
# Required-Stop:        $syslog $remote_fs<br />
# Should-Start:         $local_fs<br />
# Should-Stop:          $local_fs<br />
# Default-Start:        2 3 4 5<br />
# Default-Stop:         0 1 6<br />
# Short-Description:    redis-server &#8211; Persistent key-value db<br />
# Description:          redis-server &#8211; Persistent key-value db<br />
### END INIT INFO</p>
<p>if [ -n &quot;$2&quot; ]
then<br />
NAME=$2</p>
<p>PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin<br />
DAEMON=/usr/bin/redis-server<br />
DAEMON_ARGS=/etc/redis/servers/$NAME.conf<br />
DESC=redis-server</p>
<p>RUNDIR=/var/run/redis<br />
PIDFILE=$RUNDIR/$NAME.pid</p>
<p>test -x $DAEMON || exit 0</p>
<p>set -e</p>
<p>case &quot;$1&quot; in<br />
  start)<br />
        echo -n &quot;Starting $DESC: &quot;<br />
        mkdir -p $RUNDIR<br />
        touch $PIDFILE<br />
        chown redis:redis $RUNDIR $PIDFILE<br />
        chmod 755 $RUNDIR<br />
        if start-stop-daemon &#8211;start &#8211;quiet &#8211;umask 007 &#8211;pidfile $PIDFILE &#8211;chuid redis:redis &#8211;exec $DAEMON &#8212; $DAEMON_ARGS<br />
        then<br />
                echo &quot;$NAME.&quot;<br />
        else<br />
                echo &quot;failed&quot;<br />
        fi<br />
        ;;<br />
  stop)<br />
        echo -n &quot;Stopping $DESC: &quot;<br />
        if start-stop-daemon &#8211;stop &#8211;retry forever/QUIT/1 &#8211;quiet &#8211;oknodo &#8211;pidfile $PIDFILE &#8211;exec $DAEMON<br />
        then<br />
                echo &quot;$NAME.&quot;<br />
        else<br />
                echo &quot;failed&quot;<br />
        fi<br />
        rm -f $PIDFILE<br />
        ;;</p>
<p>  restart|force-reload)<br />
        ${0} stop $2<br />
        ${0} start $2<br />
        ;;</p>
<p>  status)<br />
        echo -n &quot;$DESC is &quot;<br />
        if start-stop-daemon &#8211;stop &#8211;quiet &#8211;signal 0 &#8211;name ${NAME} &#8211;pidfile ${PIDFILE}<br />
        then<br />
                echo &quot;running&quot;<br />
        else<br />
                echo &quot;not running&quot;<br />
                exit 1<br />
        fi<br />
        ;;</p>
<p>  *)<br />
        echo &quot;Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}&quot; &gt;&amp;2<br />
        exit 1<br />
        ;;<br />
esac</p>
<p>else</p>
<p>FILES=/etc/redis/servers/*<br />
for f in $FILES<br />
do<br />
SERVERNAME=$(sed &#8216;s|/etc/redis/servers/||g&#8217; &lt;&lt;&lt; $f)<br />
SERVERNAME=$(sed &#8216;s|.conf||g&#8217; &lt;&lt;&lt; $SERVERNAME)<br />
/etc/init.d/redis-server &quot;$1&quot; &quot;$SERVERNAME&quot;<br />
done</p>
<p>fi</p>
<p>exit 0<br />
[/bash]
</div>
<p>Stop the redis server, change into the /etc/init.d folder and make a backup copy of the redis-server init script, then empty the original script, edit it and paste in the multi instance script from above.</p>
<pre class="brush: plain; title: ; notranslate">
service redis-server stop
cd /etc/init.d
cp redis-server redis-server.old
&gt; redis-server
nano redis-server
</pre>
<p>The redis config files are saved in /etc/redis. We want to create a config file for each redis server cache storage instance in a new folder called servers.</p>
<pre class="brush: plain; title: ; notranslate">
cd /etc/redis
mkdir servers
cp redis.conf ./servers/server1.conf
cp redis.conf ./servers/server2.conf
cp redis.conf ./servers/server3.conf
</pre>
<p>Now we have three configuration files for our three caches :</p>
<ol>
<li>server1.conf &#8211; system (redis port 6379)</li>
<li>server2.conf &#8211; session (redis port 6380)</li>
<li>server3.conf &#8211; fpc (redis port 6381)</li>
</ol>
<p>We need to edit each configuration file and configure the redis settings for each cache. There is a lot of configuration information in the default redis.conf file most of it relating to options that are commented out and not required. The most important settings are the TCP port numbers used for each instance, the process id, log file name and persistence data.</p>
<p>Redis can be configured to automatically save (or persist) cached data to disk, this is really useful for volatile cache data, i.e. data you do not want to lose. Essentially redis saves a dump of the cache data regularly to disk (in /var/lib/redis) so that if the redis instance crashes or the server is restarted the cached data is not lost. This is great for cached Magento session data, we want this data in fast cache storage but we do not want to lose the data unlike system and full page cache data where we don&#8217;t really care if the data is lost &#8211; it will just be cached again.</p>
<p>Below are three example config files for the three cache types, you can configure your instances with these settings, or use the info to customise the default config files created in the /servers folder. You must at least make the tcp port numbers and pids unique.</p>
<span class="collapseomatic collapse" id="id65fc30657a5cd"  tabindex="0" title="instance1 - server1.conf SYSTEM"    >instance1 - server1.conf SYSTEM</span><div id="target-id65fc30657a5cd" class="collapseomatic_content ">
[text]
# Redis configuration<br />
# SERVER 1 SHOP01<br />
# MAGENTO SHOP01 DATA</p>
<p>maxmemory 1gb<br />
maxmemory-policy volatile-lru</p>
<p>daemonize yes</p>
<p>port 6379<br />
pidfile /var/run/redis/redis-server1.pid<br />
logfile /var/log/redis/redis-server1.log<br />
dbfilename redis-server1-dump.rdb<br />
dir /var/lib/redis<br />
bind 127.0.0.1<br />
timeout 0<br />
tcp-keepalive 0</p>
<p>loglevel notice<br />
databases 16</p>
<p>################################ SNAPSHOTTING  ################################<br />
# SAVE DATA to DISK<br />
#save 900 1<br />
#save 300 10<br />
#save 60 10000</p>
<p>stop-writes-on-bgsave-error yes<br />
rdbcompression yes<br />
rdbchecksum yes</p>
<p># replication<br />
repl-disable-tcp-nodelay no<br />
slave-priority 100</p>
<p>appendonly no<br />
appendfilename &quot;appendonly.aof&quot;<br />
# appendfsync always<br />
appendfsync everysec<br />
no-appendfsync-on-rewrite no<br />
auto-aof-rewrite-percentage 100<br />
auto-aof-rewrite-min-size 64mb<br />
lua-time-limit 5000<br />
slowlog-log-slower-than 10000<br />
slowlog-max-len 128</p>
<p>notify-keyspace-events &quot;&quot;</p>
<p>############################### ADVANCED CONFIG ###############################</p>
<p># Hashes are encoded using a memory efficient data structure when they have a<br />
# small number of entries, and the biggest entry does not exceed a given<br />
# threshold. These thresholds can be configured using the following directives.<br />
hash-max-ziplist-entries 512<br />
hash-max-ziplist-value 64</p>
<p># Similarly to hashes, small lists are also encoded in a special way in order<br />
# to save a lot of space. The special representation is only used when<br />
# you are under the following limits:<br />
list-max-ziplist-entries 512<br />
list-max-ziplist-value 64</p>
<p># Sets have a special encoding in just one case: when a set is composed<br />
# of just strings that happens to be integers in radix 10 in the range<br />
# of 64 bit signed integers.<br />
# The following configuration setting sets the limit in the size of the<br />
# set in order to use this special memory saving encoding.<br />
set-max-intset-entries 512</p>
<p># Similarly to hashes and lists, sorted sets are also specially encoded in<br />
# order to save a lot of space. This encoding is only used when the length and<br />
# elements of a sorted set are below the following limits:<br />
zset-max-ziplist-entries 128<br />
zset-max-ziplist-value 64</p>
<p># Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in<br />
# order to help rehashing the main Redis hash table (the one mapping top-level<br />
# keys to values). The hash table implementation Redis uses (see dict.c)<br />
# performs a lazy rehashing: the more operation you run into a hash table<br />
# that is rehashing, the more rehashing &quot;steps&quot; are performed, so if the<br />
# server is idle the rehashing is never complete and some more memory is used<br />
# by the hash table.<br />
#<br />
# The default is to use this millisecond 10 times every second in order to<br />
# active rehashing the main dictionaries, freeing memory when possible.<br />
#<br />
# If unsure:<br />
# use &quot;activerehashing no&quot; if you have hard latency requirements and it is<br />
# not a good thing in your environment that Redis can reply form time to time<br />
# to queries with 2 milliseconds delay.<br />
#<br />
# use &quot;activerehashing yes&quot; if you don&#8217;t have such hard requirements but<br />
# want to free memory asap when possible.<br />
activerehashing yes</p>
<p># The client output buffer limits can be used to force disconnection of clients<br />
# that are not reading data from the server fast enough for some reason (a<br />
# common reason is that a Pub/Sub client can&#8217;t consume messages as fast as the<br />
# publisher can produce them).<br />
#<br />
# The limit can be set differently for the three different classes of clients:<br />
#<br />
# normal -&gt; normal clients<br />
# slave  -&gt; slave clients and MONITOR clients<br />
# pubsub -&gt; clients subscribed to at least one pubsub channel or pattern<br />
#<br />
# The syntax of every client-output-buffer-limit directive is the following:<br />
#<br />
# client-output-buffer-limit &lt;class&gt; &lt;hard limit&gt; &lt;soft limit&gt; &lt;soft seconds&gt;<br />
#<br />
# A client is immediately disconnected once the hard limit is reached, or if<br />
# the soft limit is reached and remains reached for the specified number of<br />
# seconds (continuously).<br />
# So for instance if the hard limit is 32 megabytes and the soft limit is<br />
# 16 megabytes / 10 seconds, the client will get disconnected immediately<br />
# if the size of the output buffers reach 32 megabytes, but will also get<br />
# disconnected if the client reaches 16 megabytes and continuously overcomes<br />
# the limit for 10 seconds.<br />
#<br />
# By default normal clients are not limited because they don&#8217;t receive data<br />
# without asking (in a push way), but just after a request, so only<br />
# asynchronous clients may create a scenario where data is requested faster<br />
# than it can read.<br />
#<br />
# Instead there is a default limit for pubsub and slave clients, since<br />
# subscribers and slaves receive data in a push fashion.<br />
#<br />
# Both the hard or the soft limit can be disabled by setting them to zero.<br />
client-output-buffer-limit normal 0 0 0<br />
client-output-buffer-limit slave 256mb 64mb 60<br />
client-output-buffer-limit pubsub 32mb 8mb 60</p>
<p># Redis calls an internal function to perform many background tasks, like<br />
# closing connections of clients in timeout, purging expired keys that are<br />
# never requested, and so forth.<br />
#<br />
# Not all tasks are performed with the same frequency, but Redis checks for<br />
# tasks to perform accordingly to the specified &quot;hz&quot; value.<br />
#<br />
# By default &quot;hz&quot; is set to 10. Raising the value will use more CPU when<br />
# Redis is idle, but at the same time will make Redis more responsive when<br />
# there are many keys expiring at the same time, and timeouts may be<br />
# handled with more precision.<br />
#<br />
# The range is between 1 and 500, however a value over 100 is usually not<br />
# a good idea. Most users should use the default of 10 and raise this up to<br />
# 100 only in environments where very low latency is required.<br />
hz 10</p>
<p># When a child rewrites the AOF file, if the following option is enabled<br />
# the file will be fsync-ed every 32 MB of data generated. This is useful<br />
# in order to commit the file to the disk more incrementally and avoid<br />
# big latency spikes.<br />
aof-rewrite-incremental-fsync yes<br />
[/text]
</div>
<span class="collapseomatic collapse" id="id65fc30657a5fd"  tabindex="0" title="instance2 - server2.conf SESSION"    >instance2 - server2.conf SESSION</span><div id="target-id65fc30657a5fd" class="collapseomatic_content ">
[text]
# Redis configuration<br />
# SERVER 2 SHOP01<br />
# MAGENTO SHOP01 SESSIONS</p>
<p>maxmemory 1gb<br />
maxmemory-policy volatile-lru</p>
<p>daemonize yes</p>
<p>port 6380<br />
pidfile /var/run/redis/redis-server2.pid<br />
logfile /var/log/redis/redis-server2.log<br />
dbfilename redis-server2-dump.rdb<br />
dir /var/lib/redis<br />
bind 127.0.0.1<br />
timeout 0<br />
tcp-keepalive 0</p>
<p>loglevel notice<br />
databases 16</p>
<p>################################ SNAPSHOTTING  ################################<br />
# SAVE DATA to DISK<br />
save 900 1<br />
save 300 10<br />
save 60 10000</p>
<p>stop-writes-on-bgsave-error yes<br />
rdbcompression yes<br />
rdbchecksum yes</p>
<p># replication<br />
repl-disable-tcp-nodelay no<br />
slave-priority 100</p>
<p>appendonly no<br />
appendfilename &quot;appendonly.aof&quot;<br />
# appendfsync always<br />
appendfsync everysec<br />
no-appendfsync-on-rewrite no<br />
auto-aof-rewrite-percentage 100<br />
auto-aof-rewrite-min-size 64mb<br />
lua-time-limit 5000<br />
slowlog-log-slower-than 10000<br />
slowlog-max-len 128</p>
<p>notify-keyspace-events &quot;&quot;</p>
<p>############################### ADVANCED CONFIG ###############################</p>
<p># Hashes are encoded using a memory efficient data structure when they have a<br />
# small number of entries, and the biggest entry does not exceed a given<br />
# threshold. These thresholds can be configured using the following directives.<br />
hash-max-ziplist-entries 512<br />
hash-max-ziplist-value 64</p>
<p># Similarly to hashes, small lists are also encoded in a special way in order<br />
# to save a lot of space. The special representation is only used when<br />
# you are under the following limits:<br />
list-max-ziplist-entries 512<br />
list-max-ziplist-value 64</p>
<p># Sets have a special encoding in just one case: when a set is composed<br />
# of just strings that happens to be integers in radix 10 in the range<br />
# of 64 bit signed integers.<br />
# The following configuration setting sets the limit in the size of the<br />
# set in order to use this special memory saving encoding.<br />
set-max-intset-entries 512</p>
<p># Similarly to hashes and lists, sorted sets are also specially encoded in<br />
# order to save a lot of space. This encoding is only used when the length and<br />
# elements of a sorted set are below the following limits:<br />
zset-max-ziplist-entries 128<br />
zset-max-ziplist-value 64</p>
<p># Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in<br />
# order to help rehashing the main Redis hash table (the one mapping top-level<br />
# keys to values). The hash table implementation Redis uses (see dict.c)<br />
# performs a lazy rehashing: the more operation you run into a hash table<br />
# that is rehashing, the more rehashing &quot;steps&quot; are performed, so if the<br />
# server is idle the rehashing is never complete and some more memory is used<br />
# by the hash table.<br />
#<br />
# The default is to use this millisecond 10 times every second in order to<br />
# active rehashing the main dictionaries, freeing memory when possible.<br />
#<br />
# If unsure:<br />
# use &quot;activerehashing no&quot; if you have hard latency requirements and it is<br />
# not a good thing in your environment that Redis can reply form time to time<br />
# to queries with 2 milliseconds delay.<br />
#<br />
# use &quot;activerehashing yes&quot; if you don&#8217;t have such hard requirements but<br />
# want to free memory asap when possible.<br />
activerehashing yes</p>
<p># The client output buffer limits can be used to force disconnection of clients<br />
# that are not reading data from the server fast enough for some reason (a<br />
# common reason is that a Pub/Sub client can&#8217;t consume messages as fast as the<br />
# publisher can produce them).<br />
#<br />
# The limit can be set differently for the three different classes of clients:<br />
#<br />
# normal -&gt; normal clients<br />
# slave  -&gt; slave clients and MONITOR clients<br />
# pubsub -&gt; clients subscribed to at least one pubsub channel or pattern<br />
#<br />
# The syntax of every client-output-buffer-limit directive is the following:<br />
#<br />
# client-output-buffer-limit &lt;class&gt; &lt;hard limit&gt; &lt;soft limit&gt; &lt;soft seconds&gt;<br />
#<br />
# A client is immediately disconnected once the hard limit is reached, or if<br />
# the soft limit is reached and remains reached for the specified number of<br />
# seconds (continuously).<br />
# So for instance if the hard limit is 32 megabytes and the soft limit is<br />
# 16 megabytes / 10 seconds, the client will get disconnected immediately<br />
# if the size of the output buffers reach 32 megabytes, but will also get<br />
# disconnected if the client reaches 16 megabytes and continuously overcomes<br />
# the limit for 10 seconds.<br />
#<br />
# By default normal clients are not limited because they don&#8217;t receive data<br />
# without asking (in a push way), but just after a request, so only<br />
# asynchronous clients may create a scenario where data is requested faster<br />
# than it can read.<br />
#<br />
# Instead there is a default limit for pubsub and slave clients, since<br />
# subscribers and slaves receive data in a push fashion.<br />
#<br />
# Both the hard or the soft limit can be disabled by setting them to zero.<br />
client-output-buffer-limit normal 0 0 0<br />
client-output-buffer-limit slave 256mb 64mb 60<br />
client-output-buffer-limit pubsub 32mb 8mb 60</p>
<p># Redis calls an internal function to perform many background tasks, like<br />
# closing connections of clients in timeout, purging expired keys that are<br />
# never requested, and so forth.<br />
#<br />
# Not all tasks are performed with the same frequency, but Redis checks for<br />
# tasks to perform accordingly to the specified &quot;hz&quot; value.<br />
#<br />
# By default &quot;hz&quot; is set to 10. Raising the value will use more CPU when<br />
# Redis is idle, but at the same time will make Redis more responsive when<br />
# there are many keys expiring at the same time, and timeouts may be<br />
# handled with more precision.<br />
#<br />
# The range is between 1 and 500, however a value over 100 is usually not<br />
# a good idea. Most users should use the default of 10 and raise this up to<br />
# 100 only in environments where very low latency is required.<br />
hz 10</p>
<p># When a child rewrites the AOF file, if the following option is enabled<br />
# the file will be fsync-ed every 32 MB of data generated. This is useful<br />
# in order to commit the file to the disk more incrementally and avoid<br />
# big latency spikes.<br />
aof-rewrite-incremental-fsync yes<br />
[/text]
</div>
<span class="collapseomatic collapse" id="id65fc30657a625"  tabindex="0" title="instance3 - server3.conf FPC"    >instance3 - server3.conf FPC</span><div id="target-id65fc30657a625" class="collapseomatic_content ">
[text]
# Redis configuration<br />
# SERVER 3 SHOP01<br />
# MAGENTO SHOP01 FPC</p>
<p>maxmemory 1gb<br />
maxmemory-policy volatile-lru</p>
<p>daemonize yes</p>
<p>port 6381<br />
pidfile /var/run/redis/redis-server3.pid<br />
logfile /var/log/redis/redis-server3.log<br />
dbfilename redis-server3-dump.rdb<br />
dir /var/lib/redis<br />
bind 127.0.0.1<br />
timeout 0<br />
tcp-keepalive 0</p>
<p>loglevel notice<br />
databases 16</p>
<p>################################ SNAPSHOTTING  ################################<br />
# SAVE DATA to DISK<br />
#save 900 1<br />
#save 300 10<br />
#save 60 10000</p>
<p>stop-writes-on-bgsave-error yes<br />
rdbcompression yes<br />
rdbchecksum yes</p>
<p># replication<br />
repl-disable-tcp-nodelay no<br />
slave-priority 100</p>
<p>appendonly no<br />
appendfilename &quot;appendonly.aof&quot;<br />
# appendfsync always<br />
appendfsync everysec<br />
no-appendfsync-on-rewrite no<br />
auto-aof-rewrite-percentage 100<br />
auto-aof-rewrite-min-size 64mb<br />
lua-time-limit 5000<br />
slowlog-log-slower-than 10000<br />
slowlog-max-len 128</p>
<p>notify-keyspace-events &quot;&quot;</p>
<p>############################### ADVANCED CONFIG ###############################</p>
<p># Hashes are encoded using a memory efficient data structure when they have a<br />
# small number of entries, and the biggest entry does not exceed a given<br />
# threshold. These thresholds can be configured using the following directives.<br />
hash-max-ziplist-entries 512<br />
hash-max-ziplist-value 64</p>
<p># Similarly to hashes, small lists are also encoded in a special way in order<br />
# to save a lot of space. The special representation is only used when<br />
# you are under the following limits:<br />
list-max-ziplist-entries 512<br />
list-max-ziplist-value 64</p>
<p># Sets have a special encoding in just one case: when a set is composed<br />
# of just strings that happens to be integers in radix 10 in the range<br />
# of 64 bit signed integers.<br />
# The following configuration setting sets the limit in the size of the<br />
# set in order to use this special memory saving encoding.<br />
set-max-intset-entries 512</p>
<p># Similarly to hashes and lists, sorted sets are also specially encoded in<br />
# order to save a lot of space. This encoding is only used when the length and<br />
# elements of a sorted set are below the following limits:<br />
zset-max-ziplist-entries 128<br />
zset-max-ziplist-value 64</p>
<p># Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in<br />
# order to help rehashing the main Redis hash table (the one mapping top-level<br />
# keys to values). The hash table implementation Redis uses (see dict.c)<br />
# performs a lazy rehashing: the more operation you run into a hash table<br />
# that is rehashing, the more rehashing &quot;steps&quot; are performed, so if the<br />
# server is idle the rehashing is never complete and some more memory is used<br />
# by the hash table.<br />
#<br />
# The default is to use this millisecond 10 times every second in order to<br />
# active rehashing the main dictionaries, freeing memory when possible.<br />
#<br />
# If unsure:<br />
# use &quot;activerehashing no&quot; if you have hard latency requirements and it is<br />
# not a good thing in your environment that Redis can reply form time to time<br />
# to queries with 2 milliseconds delay.<br />
#<br />
# use &quot;activerehashing yes&quot; if you don&#8217;t have such hard requirements but<br />
# want to free memory asap when possible.<br />
activerehashing yes</p>
<p># The client output buffer limits can be used to force disconnection of clients<br />
# that are not reading data from the server fast enough for some reason (a<br />
# common reason is that a Pub/Sub client can&#8217;t consume messages as fast as the<br />
# publisher can produce them).<br />
#<br />
# The limit can be set differently for the three different classes of clients:<br />
#<br />
# normal -&gt; normal clients<br />
# slave  -&gt; slave clients and MONITOR clients<br />
# pubsub -&gt; clients subscribed to at least one pubsub channel or pattern<br />
#<br />
# The syntax of every client-output-buffer-limit directive is the following:<br />
#<br />
# client-output-buffer-limit &lt;class&gt; &lt;hard limit&gt; &lt;soft limit&gt; &lt;soft seconds&gt;<br />
#<br />
# A client is immediately disconnected once the hard limit is reached, or if<br />
# the soft limit is reached and remains reached for the specified number of<br />
# seconds (continuously).<br />
# So for instance if the hard limit is 32 megabytes and the soft limit is<br />
# 16 megabytes / 10 seconds, the client will get disconnected immediately<br />
# if the size of the output buffers reach 32 megabytes, but will also get<br />
# disconnected if the client reaches 16 megabytes and continuously overcomes<br />
# the limit for 10 seconds.<br />
#<br />
# By default normal clients are not limited because they don&#8217;t receive data<br />
# without asking (in a push way), but just after a request, so only<br />
# asynchronous clients may create a scenario where data is requested faster<br />
# than it can read.<br />
#<br />
# Instead there is a default limit for pubsub and slave clients, since<br />
# subscribers and slaves receive data in a push fashion.<br />
#<br />
# Both the hard or the soft limit can be disabled by setting them to zero.<br />
client-output-buffer-limit normal 0 0 0<br />
client-output-buffer-limit slave 256mb 64mb 60<br />
client-output-buffer-limit pubsub 32mb 8mb 60</p>
<p># Redis calls an internal function to perform many background tasks, like<br />
# closing connections of clients in timeout, purging expired keys that are<br />
# never requested, and so forth.<br />
#<br />
# Not all tasks are performed with the same frequency, but Redis checks for<br />
# tasks to perform accordingly to the specified &quot;hz&quot; value.<br />
#<br />
# By default &quot;hz&quot; is set to 10. Raising the value will use more CPU when<br />
# Redis is idle, but at the same time will make Redis more responsive when<br />
# there are many keys expiring at the same time, and timeouts may be<br />
# handled with more precision.<br />
#<br />
# The range is between 1 and 500, however a value over 100 is usually not<br />
# a good idea. Most users should use the default of 10 and raise this up to<br />
# 100 only in environments where very low latency is required.<br />
hz 10</p>
<p># When a child rewrites the AOF file, if the following option is enabled<br />
# the file will be fsync-ed every 32 MB of data generated. This is useful<br />
# in order to commit the file to the disk more incrementally and avoid<br />
# big latency spikes.<br />
aof-rewrite-incremental-fsync yes<br />
[/text]
</div>
<p>Now we can start the three redis server instances with</p>
<pre class="brush: plain; title: ; notranslate">
service redis-server start
</pre>
<h1>Install and configure redis Magento backend system cache Cm_Cache_Backend_Redis</h1>
<p>Support for redis as a Magento system cache started life as a Magento community project. Meet <a href="http://colin.mollenhour.com/" target="_blank">Colin Mollenhour</a> who appears to be the main genius behind the modules developed to use redis as a Magento/Zend cache storage system (as well as the mighty <a href="https://github.com/colinmollenhour/modman" target="_blank">modman</a>). Such was the popularity of Colin&#8217;s backend system cache module it was included as part of the Magento core distribution as of Magento CE version 1.8.0.0. You will find Mage_Cache_Backend_Redis declared in lib/Mage/Cache/Backend/Redis.php which since version 1.8.0.0 extends Colin&#8217;s Cm_Cache_Backend_Redis in lib/Cm/Cache/Backend/Redis.</p>
<p>You can find the source code to the Cm_Cache_Backend_Redis backend system cache redis module as well as support information <a href="https://github.com/colinmollenhour/Cm_Cache_Backend_Redis" target="_blank">here</a>. I asked Colin what his recommendation was for updating Cm_Cache_Backend_Redis and his answer was  &#8216; <strong>I definitely recommend the latest master from github for all versions of Magento</strong>.&#8217; So you need to be running Magento CE vesion 1.7.0.0 or newer and should install the latest vesion of Cm_Cache_Backend_Redis from the <a href="https://github.com/colinmollenhour/Cm_Cache_Backend_Redis" target="_blank">github</a>.</p>
<figure id="attachment_1322" aria-describedby="caption-attachment-1322" style="width: 440px" class="wp-caption aligncenter"><img decoding="async" class="wp-image-1322 size-medium" src="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-management-solution-version-support1-440x289.jpg" alt="" width="440" height="289" srcset="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-management-solution-version-support1-440x289.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-management-solution-version-support1-620x407.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-management-solution-version-support1-760x499.jpg 760w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-management-solution-version-support1-550x361.jpg 550w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-management-solution-version-support1.jpg 800w" sizes="(max-width: 440px) 100vw, 440px" /><figcaption id="caption-attachment-1322" class="wp-caption-text">Magento cache management system redis support</figcaption></figure>
<p>&nbsp;</p>
<h2>Install Cm_Cache_Backend_Redis with modman</h2>
<p>You can install Cm_Cache_Backend_Redis by simply cloning/downloading the git source and then copying the files into your Magento root folder. However a much better way of installing this code (and all community modules for Magento) is to use <a href="https://github.com/colinmollenhour/modman">modman</a>, the module manager also created by Colin Mollenhour. I was a bit apprehensive about modman at first as I didn&#8217;t fully understand how it was working and did not want to lose control over where magento module files were installed but once you are familiar with it, it really does make module installation and management a hell of a lot easier.</p>
<h3>Install modman</h3>
<p>If you have never used modman before install it from the command line, it is a script file that will require execution permissions.</p>
<pre class="brush: plain; title: ; notranslate">
bash &lt; &lt;(curl -s -L https://raw.github.com/colinmollenhour/modman/master/modman-installer)
Done. Modman installed in /root/bin/modman
mv /root/bin/modman /home/myapps/
export PATH=/home/myapps:$PATH
</pre>
<p>Modman lets you store all your Magento module code in one location independant of your actual Magento installation. This is useful as it lets you manage and control your module code seperately from Magentos core code and folder structure, this makes installing, testing, updating and removing modules much easier. Modman works by creating symlinks within the Magento application to the real module files in a .modman folder. Before using modman make sure you enable &#8220;Allow Symlinks&#8221; (found under System &gt; Configuration &gt; Advanced &gt; Developer -&gt; Template Settings).</p>
<p>Once you have installed the modman script you need to determine where modman will be initialised and your modman folder will be installed. I recommend you initialise modman in a folder outwith your Magento installation. For example if Magento is installed in <em>/home/www/magento</em> initialise modman in <em>/home/www</em> then create a .basedir file to tell modman where the Magento application is installed relative to the .modman folder i.e. <em>magento</em></p>
<pre class="brush: plain; title: ; notranslate">
cd /home/www
modman init
Initialized Module Manager at /home/www
cd .modman
echo magento &gt; .basedir
cd ../magento
</pre>
<p>&nbsp;</p>
<p>Now you have modman installed and initialised and can install any Magento module that supports modman.</p>
<p>To install Cm_Cache_Backend_Redis make sure you are in your Magento application folder and enter</p>
<pre class="brush: plain; title: ; notranslate">
modman clone git://github.com/colinmollenhour/Cm_Cache_Backend_Redis.git
</pre>
<span class="collapseomatic collapse" id="id65fc30657a65d"  tabindex="0" title="Cloning into &#039;Cm_Cache_Backend_Redis&#039;..."    >Cloning into 'Cm_Cache_Backend_Redis'...</span><div id="target-id65fc30657a65d" class="collapseomatic_content ">
remote: Counting objects: 671, done.<br />
remote: Total 671 (delta 0), reused 0 (delta 0), pack-reused 671<br />
Receiving objects: 100% (671/671), 125.21 KiB | 0 bytes/s, done.<br />
Resolving deltas: 100% (213/213), done.<br />
Checking connectivity&#8230; done.<br />
Submodule &#8216;lib/Credis&#8217; (https://github.com/colinmollenhour/credis.git) registered for path &#8216;lib/Credis&#8217;<br />
Cloning into &#8216;lib/Credis&#8217;&#8230;<br />
remote: Counting objects: 696, done.<br />
remote: Total 696 (delta 0), reused 0 (delta 0), pack-reused 696<br />
Receiving objects: 100% (696/696), 186.95 KiB | 0 bytes/s, done.<br />
Resolving deltas: 100% (395/395), done.<br />
Checking connectivity&#8230; done.<br />
Submodule path &#8216;lib/Credis&#8217;: checked out &#8216;e8244e74b354df5a07353acf763996832b1c9928&#8217;<br />
Applied: Cm/Cache/Backend/* app/code/community/Cm/Cache/Backend/Redis.php<br />
WARNING: Removing conflicting directory: /home/www/dev/magento/lib/Credis<br />
Applied: lib/* lib/Credis<br />
Successfully create symlink new module &#8216;Cm_Cache_Backend_Redis&#8217;<br />
</div>
<p>&nbsp;</p>
<p>modman installs Cm_Cache_Backend_Redis and we can now configure the system cache in Magento.</p>
<h2>Configure Magento redis system cache</h2>
<p>To configure Magento to use the Cm_Cache_Backend_Redis module to cache system data we need to edit the Magento /app/etc/local.xml file and within the global tags add backend system cache redis configuration as shown below, note <em>Cm_Cache_Backend_Redis</em> is defined as the backend cache module. Also note the port number we are using for the backend system cache is the port number of our first redis instance <em>6379</em> and the compression method being uses is <em>gzip</em>.</p>
<pre class="brush: plain; highlight: [5,7,16]; title: ; notranslate">
&lt;cache&gt;
	&lt;backend&gt;Cm_Cache_Backend_Redis&lt;/backend&gt;
		 &lt;backend_options&gt;
			&lt;server&gt;127.0.0.1&lt;/server&gt;
			&lt;port&gt;6379&lt;/port&gt;
			&lt;persistent&gt;&lt;/persistent&gt;
			&lt;database&gt;0&lt;/database&gt;
			&lt;password&gt;&lt;/password&gt;
			&lt;force_standalone&gt;0&lt;/force_standalone&gt;
			&lt;connect_retries&gt;1&lt;/connect_retries&gt;
			&lt;read_timeout&gt;10&lt;/read_timeout&gt;
			&lt;automatic_cleaning_factor&gt;0&lt;/automatic_cleaning_factor&gt;
			&lt;compress_data&gt;1&lt;/compress_data&gt;
			&lt;compress_tags&gt;1&lt;/compress_tags&gt;
			&lt;compress_threshold&gt;20480&lt;/compress_threshold&gt;
			&lt;compression_lib&gt;gzip&lt;/compression_lib&gt;
			&lt;use_lua&gt;0&lt;/use_lua&gt;
		 &lt;/backend_options&gt;
  &lt;/cache&gt;
</pre>
<p>&nbsp;</p>
<p>You will notice in the /app/etc folder a<em> local.xml.additional</em> file here you will find other configuration examples including the redis cache config above. Now go to System -&gt; Cache Management in Magento admin and enable/refresh the cache to enable the new configuration. Magento is now using redis server instance 1 (db 0) on tcp port 6379 to cache backend Magento system data.</p>
<h2>Monitor Magento redis system cache</h2>
<p>We want to be sure that everything is working and Magento is actually using redis in the way we want it to. There are a few ways to monitor redis and confirm our configuration is working. The first is via the command line. You can monitor a specific redis instance by telnetting to the redis port on locahost and issuing the <a href="http://redis.io/commands/MONITOR" target="_blank">MONITOR </a>command :</p>
<pre class="brush: plain; title: ; notranslate">
telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
MONITOR
+OK
+1434702244.302408 &#x5B;0 127.0.0.1:50415] &quot;SELECT&quot; &quot;0&quot;
+1434702244.303202 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_CORE_CACHE_OPTIONS&quot; &quot;d&quot;
+1434702244.303360 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_CONFIG_GLOBAL_LOCK&quot; &quot;d&quot;
+1434702244.303652 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_CONFIG_GLOBAL&quot; &quot;d&quot;
+1434702244.328254 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_APP_4E4ABDD8DC00C3DACB3C1597944A3B6C&quot; &quot;d&quot;
+1434702244.328821 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_STORE_ADMIN_CONFIG_CACHE&quot; &quot;d&quot;
+1434702244.329252 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_APP_B1FB6E8F13287C01E5C05063633DDA4C&quot; &quot;d&quot;
+1434702244.329791 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_APP_E4D52B98688947405EDE639E947EE03D&quot; &quot;d&quot;
+1434702244.330144 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_STORE_DE_CONFIG_CACHE&quot; &quot;d&quot;
+1434702244.330371 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_STORE_EN_CONFIG_CACHE&quot; &quot;d&quot;
+1434702244.332765 &#x5B;0 127.0.0.1:50415] &quot;HGET&quot; &quot;zc:k:cc4_CONFIG_GLOBAL_STORES_DE&quot; &quot;d&quot;
QUIT
+OK
Connection closed by foreign host.
</pre>
<p>Here we are connecting to the system cache redis instance on port 6379 and if you browse your Magento site you should see redis cache activity as Magento saves or gets data from the cache. To monitor all redis server activity use <em>redis-cli monitor</em> from the command line. Note that the monitor command consumes a lot of redis resources so don&#8217;t leave it running!</p>
<p>There are two other graphical administration tools we can use to monitor redis activity check out how to install these later in the blog.</p>
<h1>Install and configure redis Magento session cache Cm_RedisSession</h1>
<p><a href="https://github.com/colinmollenhour/Cm_RedisSession" target="_blank">Cm_RedisSession</a> is another module from Colin Mollenhour that enables Magento to use redis as a cache storage system for Magento session data. By default Magento saves session data to the file system in the Magento var/session folder. Each session file is about 4Kb in size and over time the var/session folder can grow quite large if not managed. The second option for session storage in Magento is to use the Magento MySQL database. I have always avoided doing this as I don&#8217;t think session data belongs in the Magento database.</p>
<p>Cm_RedisSession rewrites the Magento db session save code to use redis instead of the database.</p>
<h2>Install Cm_RedisSession with modman</h2>
<p>Again, as with Cm_Cache_Backend_Redis if you are running Magento version 1.8.0.0 or greater Cm_RedisSession is already installed but you should upgrade it to the latest version.</p>
<p>In your Magento application folder install Cm_RedisSession with modman :</p>
<pre class="brush: plain; title: ; notranslate">
modman clone git://github.com/colinmollenhour/Cm_RedisSession.git
</pre>
<span class="collapseomatic collapse" id="id65fc30657a687"  tabindex="0" title="Cloning into &#039;Cm_RedisSession&#039;..."    >Cloning into 'Cm_RedisSession'...</span><div id="target-id65fc30657a687" class="collapseomatic_content ">
[text]
modman clone git://github.com/colinmollenhour/Cm_RedisSession.git<br />
Cloning into &#8216;Cm_RedisSession&#8217;&#8230;<br />
remote: Counting objects: 562, done.<br />
remote: Total 562 (delta 0), reused 0 (delta 0), pack-reused 562<br />
Receiving objects: 100% (562/562), 151.45 KiB | 0 bytes/s, done.<br />
Resolving deltas: 100% (221/221), done.<br />
Checking connectivity&#8230; done.<br />
Submodule &#8216;lib/Credis&#8217; (git://github.com/colinmollenhour/credis.git) registered for path &#8216;lib/Credis&#8217;<br />
Cloning into &#8216;lib/Credis&#8217;&#8230;<br />
remote: Counting objects: 696, done.<br />
remote: Total 696 (delta 0), reused 0 (delta 0), pack-reused 696<br />
Receiving objects: 100% (696/696), 186.95 KiB | 0 bytes/s, done.<br />
Resolving deltas: 100% (395/395), done.<br />
Checking connectivity&#8230; done.<br />
Submodule path &#8216;lib/Credis&#8217;: checked out &#8216;7bd47b61fc3dad28aa881de45c71026256ad27cc&#8217;<br />
WARNING: Removing conflicting directory: /home/www/dev/magento/app/code/community/Cm/RedisSession<br />
 Applied: code                            app/code/community/Cm/RedisSession<br />
WARNING: Removing conflicting regular file: /home/www/dev/magento/app/etc/modules/Cm_RedisSession.xml<br />
 Applied: Cm_RedisSession.xml             app/etc/modules/Cm_RedisSession.xml<br />
WARNING: Removing conflicting symbolic link: /home/www/dev/magento/lib/Credis<br />
 Applied: lib/Credis                      lib/Credis<br />
Successfully create symlink new module &#8216;Cm_RedisSession&#8217;<br />
[/text]
</div>
<p>&nbsp;</p>
<h2>Configure Magento redis session cache</h2>
<p>Again in /app/etc/local.xml.additional you will see a configuration example for the redis session cache, note that the <a href="https://github.com/colinmollenhour/Cm_RedisSession" target="_blank">configuration example from Colin</a> is more complete and that is the one I am using here. Edit your local.xml file and add the configuration below between the <em>global</em> tags. Note that we specify our second redis instance on port 6380 as the session cache, also note Colin&#8217;s module uses the session_save db value normally used to store sessions in MySQL. Cm_RedisSession rewrites this code to use redis, using the db value here also means Magento will fallback (hopefully) to using MySQL to store session data should redis fail.</p>
<pre class="brush: plain; highlight: [1,4,10]; title: ; notranslate">
        &lt;session_save&gt;db&lt;/session_save&gt;
        &lt;redis_session&gt;                       &lt;!-- All options seen here are the defaults --&gt;
            &lt;host&gt;127.0.0.1&lt;/host&gt;            &lt;!-- Specify an absolute path if using a unix socket --&gt;
            &lt;port&gt;6380&lt;/port&gt;
            &lt;password&gt;&lt;/password&gt;             &lt;!-- Specify if your Redis server requires authentication --&gt;
            &lt;timeout&gt;2.5&lt;/timeout&gt;            &lt;!-- This is the Redis connection timeout, not the locking timeout --&gt;
            &lt;persistent&gt;&lt;/persistent&gt;         &lt;!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 --&gt;
            &lt;db&gt;0&lt;/db&gt;                        &lt;!-- Redis database number; protection from accidental loss is improved by using a unique DB number for sessions --&gt;
            &lt;compression_threshold&gt;2048&lt;/compression_threshold&gt;  &lt;!-- Set to 0 to disable compression (recommended when suhosin.session.encrypt=on); known bug with strings over 64k: https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/issues/18 --&gt;
            &lt;compression_lib&gt;gzip&lt;/compression_lib&gt;              &lt;!-- gzip, lzf, lz4 or snappy --&gt;
            &lt;log_level&gt;1&lt;/log_level&gt;               &lt;!-- 0 (emergency: system is unusable), 4 (warning; additional information, recommended), 5 (notice: normal but significant condition), 6 (info: informational messages), 7 (debug: the most information for development/testing) --&gt;
            &lt;max_concurrency&gt;6&lt;/max_concurrency&gt;                 &lt;!-- maximum number of processes that can wait for a lock on one session; for large production clusters, set this to at least 10% of the number of PHP processes --&gt;
            &lt;break_after_frontend&gt;5&lt;/break_after_frontend&gt;       &lt;!-- seconds to wait for a session lock in the frontend; not as critical as admin --&gt;
            &lt;break_after_adminhtml&gt;30&lt;/break_after_adminhtml&gt;
            &lt;first_lifetime&gt;600&lt;/first_lifetime&gt;                 &lt;!-- Lifetime of session for non-bots on the first write. 0 to disable --&gt;
            &lt;bot_first_lifetime&gt;60&lt;/bot_first_lifetime&gt;          &lt;!-- Lifetime of session for bots on the first write. 0 to disable --&gt;
            &lt;bot_lifetime&gt;7200&lt;/bot_lifetime&gt;                    &lt;!-- Lifetime of session for bots on subsequent writes. 0 to disable --&gt;
            &lt;disable_locking&gt;0&lt;/disable_locking&gt;                 &lt;!-- Disable session locking entirely. --&gt;
            &lt;min_lifetime&gt;60&lt;/min_lifetime&gt;                      &lt;!-- Set the minimum session lifetime --&gt;
            &lt;max_lifetime&gt;2592000&lt;/max_lifetime&gt;                 &lt;!-- Set the maximum session lifetime --&gt;
        &lt;/redis_session&gt;
</pre>
<p>Refresh your Magento configuration to enable the Magento redis session cache.</p>
<p>Remember that when you change your session cache your existing session data will not be automatically imported. Depending on how important retaining existing session data is you may want to import your session data from the file system or database into redis. This will then maintain all existing session data, i.e. logged in customers will remain logged in, and customer session data will not be lost.</p>
<p>Colin Mollenhour has included a utility to allow you to import your session data. The following commands will put your shop into maintenance mode, to stop the creation of any new sessions, and import session data from the file system. You can find more information on this migration process <a href="https://github.com/colinmollenhour/Cm_RedisSession" target="_blank">here</a>.</p>
<pre class="brush: plain; title: ; notranslate">
touch maintenance.flag   # Enter maintenance mode
sleep 2                  # Allow any running processes to complete
# This will copy sessions into redis and clear the config cache so local.xml changes will take effect
php ../.modman/Cm_RedisSession/migrateSessions.php -y
rm maintenance.flag      # All done, exit maintenance mode
</pre>
<p>If the import script returns an error it means you have not yet configured or enabled the redis session cache in local.xml.</p>
<p>Now that you have imported existing session data you can delete the contents of your Magento var/session folder, this folder should now stay empty.</p>
<h2>Monitor Magento redis session cache</h2>
<p>Again we can confirm the redis session cache is working by monitoring the session cache instance on TCP port 6380. Browse to your Magento site in an incognito browser session to force Magento to create new session data, you will see the session data appear in the monitor window.</p>
<pre class="brush: plain; highlight: [1]; title: ; notranslate">
telnet localhost 6380
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
MONITOR
+OK
+1434705128.835230 &#x5B;0 127.0.0.1:58060] &quot;SELECT&quot; &quot;0&quot;
+1434705128.835387 &#x5B;0 127.0.0.1:58060] &quot;HINCRBY&quot; &quot;sess_8fdjpoeco2panshj38m7d6cd36&quot; &quot;lock&quot; &quot;1&quot;
+1434705128.835523 &#x5B;0 127.0.0.1:58060] &quot;HMGET&quot; &quot;sess_8fdjpoeco2panshj38m7d6cd36&quot; &quot;data&quot; &quot;writes&quot;
+1434705128.835889 &#x5B;0 127.0.0.1:58060] &quot;HMSET&quot; &quot;sess_8fdjpoeco2panshj38m7d6cd36&quot; &quot;pid&quot; &quot;vwelive|30576&quot; &quot;lock&quot; &quot;1&quot;
+1434705128.835939 &#x5B;0 127.0.0.1:58060] &quot;EXPIRE&quot; &quot;sess_8fdjpoeco2panshj38m7d6cd36&quot; &quot;1440&quot;
+1434705129.201090 &#x5B;0 127.0.0.1:58060] &quot;HGET&quot; &quot;sess_8fdjpoeco2panshj38m7d6cd36&quot; &quot;pid&quot;
+1434705129.201434 &#x5B;0 127.0.0.1:58060] &quot;SELECT&quot; &quot;0&quot;
+1434705129.201469 &#x5B;0 127.0.0.1:58060] &quot;HMSET&quot; &quot;sess_8fdjpoeco2panshj38m7d6cd36&quot; &quot;data&quot; &quot;:gz:x\x01\xedVKO\xdc0\x10\xe6\xa7D&gt;A\xc5\xe6\x9dl\xe2\bU\x88C+Q(\x12\xb4\x1c-\x93\xcc\xb2\x86$\x0ev\xb2KK\xf7\xbfw\xecd\xd5\xe5\xd0\xaa\xc7=\xec%\x89\xc7\xf3\xf0|\xdf\x8c'\xa5T\xf0\x8b\xd3\x84\xbei\x1aF\x940\rZ\x0b\xd9\xb2\x15\xafE\xc5{\xa9\x18&gt;9)8\x8d\x8dN\x10P\xa2\xa
QUIT
+OK
Connection closed by foreign host.
</pre>
<h1>Install and configure redis Magento CE full page cache Lesti_Fpc</h1>
<p>Lesti_Fpc is a Magento CE module <a href="https://gordonlesti.com/projects/lestifpc/" target="_blank">developed by Gordon Lesti</a> that enables an internal full page cache. A full page cache is included with Magento Enterprise but for CE users this is perhaps one of the best free full page cache solutions available.</p>
<p>If you are trying to optimising your Magento CE installation a full page cache will instantly improve page loading time and responsiveness. You will want to thoroughly test this module on your development servers to make sure it works with your particular Magento installation and frontend theme. You should read the <a href="https://gordonlesti.com/projects/lestifpc/" target="_blank">support information from Gordon Lesti</a> to familiarise yourself with the way the module works and can be configured.</p>
<p>I was not 100% comfortable with using the module and opted to modify it to only cache pages for users not logged in as I was mainly concerned about improving responsiveness for first time visitors and Google Search / Speed Index.</p>
<p>Like the default Magento system and session caches Lesti_Fpc will use the file system as the default cache storage system but we can also configure it to use redis. The Lesti_Fpc full page cache is one of the main reason I moved from using memcache to redis, Lesti_Fpc can use both, but only with redis can you refresh the full page cache within Magento. With memcache the only way to refresh the cache is to purge the cache storage.</p>
<h2>Install Lesti_Fpc with modman</h2>
<p>From your Magento root folder, use modman to install the Lesti_Fpc module.</p>
<pre class="brush: plain; title: ; notranslate">
modman clone https://github.com/GordonLesti/Lesti_Fpc.git
</pre>
<p>Refresh your Magento configuration and you will see a new cache type listed in the Magento cache storage management admin page.</p>
<figure id="attachment_1342" aria-describedby="caption-attachment-1342" style="width: 735px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class=" wp-image-1342" src="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-lesti-fpc-screen-620x114.jpg" alt="Enable Lesti_Fpc" width="735" height="135" srcset="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-lesti-fpc-screen-620x114.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-lesti-fpc-screen-440x81.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-lesti-fpc-screen-760x140.jpg 760w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-lesti-fpc-screen-550x101.jpg 550w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-lesti-fpc-screen.jpg 800w" sizes="(max-width: 735px) 100vw, 735px" /><figcaption id="caption-attachment-1342" class="wp-caption-text">Enable Lesti_Fpc</figcaption></figure>
<p>&nbsp;</p>
<p>To enable Lest_Fpc select the Fpc cache type and then select <em>enable</em> from actions and click submit. This will enable the full page cache which will start caching to the file system in var/cache/.</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-1309" src="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen.jpg" alt="magento-cache-storage-management-screen" width="800" height="315" srcset="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen.jpg 800w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen-440x173.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen-620x244.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen-760x299.jpg 760w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-cache-storage-management-screen-550x217.jpg 550w" sizes="(max-width: 800px) 100vw, 800px" /></p>
<h2>Configure Lesti_Fpc redis full page cache</h2>
<p>To configure Lesti_Fpc to use redis as the cache storage system locate the fpc.xml.sample symlink in app/etc/. Rename the symlink to fpc.xml and open the file for editing. You will see an example redis cache configuration commented out, uncomment the configuration and edit the port settings to match the port configured on our redis instance 3 for full page cache &#8211; 6381. Note how Lest_Fpc also uses Cm_Cache_Backend_Redis to cache data to redis. <em>Neat huh?</em></p>
<p>&nbsp;</p>
<pre class="brush: plain; highlight: [1,4]; title: ; notranslate">

            &lt;!--backend&gt;Cm_Cache_Backend_Redis&lt;/backend&gt;
            &lt;backend_options&gt;
                &lt;server&gt;127.0.0.1&lt;/server&gt;
                &lt;port&gt;6381&lt;/port&gt;
                &lt;persistent&gt;cache-fpc&lt;/persistent&gt;
                &lt;database&gt;1&lt;/database&gt;
                &lt;password&gt;&lt;/password&gt;
                &lt;force_standalone&gt;1&lt;/force_standalone&gt;
                &lt;connect_retries&gt;1&lt;/connect_retries&gt;
                	&lt;lifetimelimit&gt;86400&lt;/lifetimelimit&gt;
                &lt;read_timeout&gt;10&lt;/read_timeout&gt;
                &lt;compress_data&gt;1&lt;/compress_data&gt;
                &lt;compress_tags&gt;1&lt;/compress_tags&gt;
                &lt;compress_data&gt;gzip&lt;/compress_data&gt;
            &lt;/backend_options--&gt;

</pre>
<p>Refresh the Magento configuration cache to enable the redis cache for Lest_Fpc full page cache data.</p>
<h2>Monitor Lesti_Fpc full page cache</h2>
<p>Again we can confirm that Lest_Fpc is using redis by monitoring our redis instance on port 6381.</p>
<pre class="brush: plain; highlight: [1]; title: ; notranslate">
telnet localhost 6381
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
MONITOR
+OK
+1434708527.473899 &#x5B;0 127.0.0.1:37524] &quot;select&quot; &quot;0&quot;
+1434708528.667508 &#x5B;0 127.0.0.1:37538] &quot;select&quot; &quot;0&quot;
+1434708528.728683 &#x5B;0 127.0.0.1:37538] &quot;hget&quot; &quot;zc:k:cc4_487CA86953D34994D28E9FEA5DCAD22EF836ECD4_PAGE&quot; &quot;d&quot;
+1434708535.892402 &#x5B;0 127.0.0.1:37508] &quot;select&quot; &quot;0&quot;
+1434708542.685102 &#x5B;0 127.0.0.1:37478] &quot;select&quot; &quot;0&quot;
+1434708542.772018 &#x5B;0 127.0.0.1:37478] &quot;hget&quot; &quot;zc:k:cc4_E8F535AA519A6B32EFBB322BAFB4BA86704430AB_PAGE&quot; &quot;d&quot;
+1434708543.253530 &#x5B;0 127.0.0.1:37495] &quot;select&quot; &quot;0&quot;
+1434708546.151371 &#x5B;0 127.0.0.1:37562] &quot;select&quot; &quot;0&quot;
+1434708546.304141 &#x5B;0 127.0.0.1:37562] &quot;hget&quot; &quot;zc:k:cc4_3FA4328F459A7D31B2D5B7BD4C4374494AFF146E_PAGE&quot; &quot;d&quot;
QUIT
+OK
Connection closed by foreign host.
</pre>
<p>You can now also delete the contents of your Magento var/cache/ folder, Magento is no longer caching data to the file system, and when all the caching modules are working correctly this folder will stay empty.</p>
<p><em>Congratulations</em> you now have a fully cached Magento system using a fast input/output redis memory cache.</p>
<h1>Monitoring redis</h1>
<p>There are two admin tools well worth installing to help you monitor redis,</p>
<p>Steve Robbins has developed a <a href="https://github.com/steverobbins/Magento-Redismanager" target="_blank">Magento Redis Manager</a> module that allows you to monitor your redis confguration via a Magento admin page.</p>
<h2>Install Magento Redis Manager</h2>
<p>Install the Magento Redis Manager module from your Magento root folder with modman.</p>
<pre class="brush: plain; title: ; notranslate">
modman clone https://github.com/steverobbins/Magento-Redismanager.git
</pre>
<p>Refresh your Magento configuration cache, log out of admin and back in to view the Magento Redis Manager admin page under System -&gt; Redis Management.</p>
<figure id="attachment_1344" aria-describedby="caption-attachment-1344" style="width: 800px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-1344 size-full" src="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-redis-manager.jpg" alt="Magento Redis Manager" width="800" height="324" srcset="https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-redis-manager.jpg 800w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-redis-manager-440x178.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-redis-manager-620x251.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-redis-manager-760x308.jpg 760w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/magento-redis-manager-550x223.jpg 550w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption id="caption-attachment-1344" class="wp-caption-text">Magento Redis Manager</figcaption></figure>
<p>Here we can clearly see our three redis cache instances and how they are being used by Magento for the System (cache), Fpc and Session cache. Here you can also manually flush individual redis caches if required. You can also completely flush the cache storage from the cache management page.</p>
<p>Another redis administration graphical tool that is very useful is <a href="https://github.com/ErikDubbelboer/phpRedisAdmin" target="_blank">Erik Dubbelboers phpRedisAdmin</a>. This is a php script that lets you monitor redis via your browser.</p>
<h2>Install phpRedisAdmin</h2>
<p>You can install phpRedisAdmin with composer, see the <a href="https://github.com/ErikDubbelboer/phpRedisAdmin" target="_blank">github </a>page for more information.</p>
<figure id="attachment_1345" aria-describedby="caption-attachment-1345" style="width: 800px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" class="wp-image-1345 size-full" src="https://blog.gaiterjones.com/wp-content/uploads/2015/06/php-redis-admin.jpg" alt="PHPRedisAdmin" width="800" height="293" srcset="https://blog.gaiterjones.com/wp-content/uploads/2015/06/php-redis-admin.jpg 800w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/php-redis-admin-440x161.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/php-redis-admin-620x227.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/php-redis-admin-760x278.jpg 760w, https://blog.gaiterjones.com/wp-content/uploads/2015/06/php-redis-admin-550x201.jpg 550w" sizes="(max-width: 800px) 100vw, 800px" /><figcaption id="caption-attachment-1345" class="wp-caption-text">PHPRedisAdmin</figcaption></figure>
<p>You need to configure phpRedisAdmin with the names and port numbers of your configured redis instances, then you will see the three instances listed in phpRedisAdmin. phpRedisAdmin also lets you browse the redis data for each cache instance. Note that the last save values above show that the system and fpc caches are not being persisted, or dumped to disk by redis, the volatile session data however is persisted, and regularly saved to disk just as we configured it to.</p>
<h1>Conclusions</h1>
<p>Thanks to the developers of the Magento CE caching modules and redis cache storage system we have a pretty good method of <a href="https://blog.gaiterjones.com/5-ways-to-improve-magento-page-speed/">optimising </a>and improving Magento responsiveness with a cost effective fast caching system. Of course redis configured on a single server will have it&#8217;s limits, but for a small to medium sized ecommerce shop this solution should suffice and you should be able to implement a good caching system and experience good results from caching your Magento data.</p>
<p>You can see this cache system using the config from this blog <a href="http://dev.gaiterjones.com/magento/" target="_blank">running on my dev Magento 1.9.x store.</a></p>
<p>&nbsp;</p>
<h1>Credits</h1>
<ul>
<li>Colin Mollenhour
<ul>
<li>modman</li>
<li>backend and session modules</li>
</ul>
</li>
<li>Gordon Lesti
<ul>
<li>Lesti full page cache</li>
</ul>
</li>
<li>Steve Robbins
<ul>
<li>Magento Redis Manager</li>
</ul>
</li>
<li>Erik Dubbelboer
<ul>
<li>PHP Redis Admin</li>
</ul>
</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/magento-redis-system-session-and-full-page-cache-management-solution/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>5 Ways to Improve Magento Page Speed</title>
		<link>https://blog.gaiterjones.com/5-ways-to-improve-magento-page-speed/</link>
					<comments>https://blog.gaiterjones.com/5-ways-to-improve-magento-page-speed/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Tue, 26 May 2015 15:11:34 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Magento Optimisation]]></category>
		<category><![CDATA[google page speed insights]]></category>
		<category><![CDATA[magento optimisation]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1293</guid>

					<description><![CDATA[Googles Phantom update recently laid emphasis on having a more mobile friendly website to improve search results on mobile devices. This is great for Magento 1.9 with it&#8217;s responsive theme...<a class="more-link" href="https://blog.gaiterjones.com/5-ways-to-improve-magento-page-speed/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>Googles Phantom update recently laid emphasis on having a more mobile friendly website to improve search results on mobile devices. This is great for Magento 1.9 with it&#8217;s responsive theme design but if your Magento page load speed is slow you may well be penalised by Google.</p>
<h2>Google Page Speed Insights</h2>
<p>The <a href="https://developers.google.com/speed/pagespeed/insights/?" target="_blank">Google Page Speed insights tool</a> gives you a good idea as to how your Magento site is performing according to Google&#8217;s page speed analysis rules. It will rate your page speed for both Desktop and Mobile devices on a scale between 1 and 100, the higher the rating the better. Apart from the general response speed of your server it concentrates on some basic optimisation rules including compression and browser caching.</p>
<p>Google will provide you with some guidance to help you improve your page speed analysis results. The main speed issues all Magento stores are going to suffer from will, despite all your optimisation attempts, probably always eventually come back to your server hardware resources and configuration. The mean time to the first byte delivery for a Magento store will be very dependant on server, database and network resources that may be out of your control (or budget) especially as Magento is already a pretty data intensive beast.</p>
<p>Here are 5 ways to <strong>improve your Magento Google Page Speed insight results</strong>.</p>
<h2>1. Buy a new server / enable full page caching</h2>
<p>Ok, so a new server is probably not going to be an option, but remember if your server is not up to spec for your Magento installation no amount of optimising is going to make your server faster. Full page caching might be an option to help improve server response times.</p>
<h2>2. Enable Apache Compression</h2>
<p>Assuming you are using Apache, make sure compression and the <strong>mod_deflate</strong> module is enabled. mod_deflate is an Apache module which “provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.” (from its web). You need to make sure the module is enabled before you try to configure compression. To do this with Ubuntu for example simply enter</p>
<pre class="prettyprint"><code>a2enmod deflate
service apache2 restart</code></pre>
<p>Now take a look at the default Magento .htaccess file in the root of your Magento folder,  Make sure the section with the deflate compression rules is not commented to enable the default compression rules.</p>
<pre class="prettyprint"><code>############################################
## DEFLATE COMPRESSION
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
    AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript application/x-javascript
    #AddOutputFilterByType DEFLATE application/x-httpd-php

    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:pdf|doc)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:avi|mov|mp3|mp4|rm)$ no-gzip dont-vary
</code></pre>
<p>These are the default rules, if you google this subject you will also find suggestions to improve on / customise these rules. Some will also argue that you should move the .htaccess rules to your apache site .conf file.</p>
<h2>3. Enable Browser Cache Rules</h2>
<p>Similar to taking advantage of Apaches compression features, you need to also make sure you are telling visitors what data their browsers can and cannot cache, and for how long. Client side caching rules obviously help considerably to reduce the time required by the browser to fetch data.</p>
<p>The Apache module is called mod_expires. Enable this with</p>
<pre class="prettyprint"><code>a2enmod expires
service apache2 restart</code></pre>
<p>Again look at the default Magento .htaccess rules and make sure the <strong>mod_expires</strong> section is not commented out.</p>
<pre class="prettyprint"><code>
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

	ExpiresActive On
	ExpiresDefault "access plus 1 year"


</code></pre>
<h2>4. Optimise images</h2>
<p>The first thing you will see when Google analyses your product pages are suggestions to improve image optimisation. A good Magento store will have a lot of images, and Magento makes a good job of resizing and caching product images for various frontend views.</p>
<p>There are two really good lossless image optimisation tools available that can optimise all your images in seconds with just one command line: <strong>jpegoptim</strong> and <strong>pngcrush</strong>.</p>
<p>These are free utilities that should be available for your flavour of Unix. In ubuntu you can install them with</p>
<pre class="prettyprint"><code>apt-get install jpegoptim
apt-get install pngcrush</code></pre>
<p>First take a backup of your Magento installation, or at least your <em>/media/catalog/product</em> and <em>category</em> folders.</p>
<p>To optimise every single product image open a terminal session and change to your magento<em> media/catalog/product</em> folder. Now execute the following command line</p>
<pre class="prettyprint"><code>find . -type d -exec  sh -c "/usr/bin/jpegoptim --strip-all -t {}/*.jpg" \; | perl -e '@a=&lt;&gt;; $a=join("", @a); @b = $a =~ /%\s+\((\d+)k\)/g; foreach my $n (@b) {$sum = $sum + $n}; print "Total saved ${sum}k\n"' </code></pre>
<p>This will optimise all jpg files in the current folder and all subfolders. The original file will be overwritten and a summary of the compression savings shown at the end. Be sure to reset the permissions of all the image files after running the optimisation as they will have all been reset which can lead to them not being accessible by Apache.</p>
<p>If you have png files you want to optimise the corresponding pngcrush command is</p>
<pre class="prettyprint"><code>for png in `find $1 -iname "*.png"`; do pngcrush -ow "$png"; done</code></pre>
<p>Before you jump in and optimise all your images make sure you have a backup, and I would also do a test optimisation on your production server. Replacing thousands of broken product images is really no fun at all.</p>
<p>&nbsp;</p>
<h2>5. Minify and Optimise JS, CSS and HTML</h2>
<p>The best way to minify and optimise your javascript and style sheet files for Google page insights is to enable the Magento js and css combination feature in admin. I would also recommend installing the <a href="https://blog.gaiterjones.com/5-magento-modules-you-cannot-live-without/">Fooman Speedster Advanced</a> module. I noticed the new RWD theme in Magento 1.9 now supports SASS, this will no doubt help to improve CSS optimisation in the future, if your theme doesn&#8217;t support SCSS then have a look at manually optimising the CSS yourself using online tools. The same goes for javascript, make sure any plugins you install are using minified js files, or try to minify the source yourself using online tools.</p>
<p>I am currently testing a <a href="https://github.com/gaiterjones/magento-minifyhtml" target="_blank">module</a> that uses the well known minify code to minify Magento html output.</p>
<p>Each of these steps will help to improve the page speed insight score, html minification alone increases the rank by 1. When you add all these small improvements together your page speed rank will increase by 5 to 10 points which may well be enough to get you in to the green ranking of 85 and above.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/5-ways-to-improve-magento-page-speed/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
