Yesterday evening I committed a fix for the Memcached cache backend to TYPO3 4.3. If you work with current trunk version of TYPO3, you can enable this backend and enjoy speed improvements.
Types of caches in TYPO3
There are three different caches in TYPO3 4.3:
- cache_hash
This cache saves data produced by some TYPO3 functions, mainly by substituteMarkerArrayCached. This cache can be very large, it is used only if page is not cached and it does not make sense to enable Memcached for this cache. Database or file will work best. - cache_pagesection
This cache stores parsed TypoScript templates. It can be stored in Memcached but database is my personal preference for this cache. - cache_pages
This cache stores pages. This is what needs to be as fast as possible. So Memcached will be the best candidate for this cache.
How to configure caches
By default caches use database to store data. However it can be changed. For example the following code in typo3conf/localconf.php will use different cache backends for different caches:
$TYPO3_CONF_VARS['SYS']['caching']['cacheBackendAssignments'] = array(
'cache_hash' => array(
'backend' => 't3lib_cache_backend_File',
'options' => array(
)
),
'cache_pages' => array(
'backend' => 't3lib_cache_backend_Memcached',
'options' => array(
'servers' => array('localhost:11211'),
)
),
'cache_pagesection' => array(
'backend' => 't3lib_cache_backend_Db',
'options' => array(
'cacheTable' => 'cache_pagesection',
)
)
);
Bold text shows you how different caches are configured. Here cache_hash uses file backend. If you symlink typo3temp/ or typo3temp/cache/ to the RAID1 partition, this cache will be very fast and will not produce any load on MySQL.
cache_pagesection uses database. Notice how we configure table name.
cache_pages uses Memcached. Configuration says that Memcached server is located on the localhost and accessible through port 11211 (default Memcached configuration). You can set up other Memcached instances and add them to the list separating instances by commas. Make sure you have no spaces anywhere. But localhost will work best because network delays will make Memcached useless.
Install Memcached
Memcached should be installed on the server. Internet has plenty of instructions about it, so I will not repeat them.
Configure Memcached in PHP
I do not pretend to be an expert in Memcached but I created a reasonable configuration for Memcached locally. This requires modifying php.ini. After changing default values Memcached requests became faster (I confirmed it by profiling with XDebug). Here is my settings:
memcache.allow_failover | 1 |
memcache.chunk_size | 32768 |
memcache.default_port | 11211 |
memcache.hash_function | fnv |
memcache.hash_strategy | consistent |
memcache.max_failover_attempts | 20 |
And of course you need to have Memcached PHP extension installed.
I am going to use Memcached on my own servers when TYPO3 4.3 is out. It is really promising in terms of performance.
Comments
- michael
Will those new built-in caching options make extensions like \"nc_staticfilecache\" or \"staticpub\" largely (or completely) obsolete or am i missing something?
Greeting,
Wolfgang
Wolfgang, I do not know those extensions too well but I do not think they become obsolete. It depends on what they do. Anyway, Memcached may beat even them. File system access is always slower than direct memory access.
So basically the new memcache support can be used for some frontend Caches. It does not influence the backend performance in any way? Did I understand this right?
Find my miserly report at: http://www.t3node.com/blog/testing-the-forthcoming-typo3-caching-framework-with-memcached/
using memcached for caching pages is of course going to speed up READING already cached pages.
The problem I see in typo3 as not addressed yet ( unless it is hidden somewhere deep ) is caching of plugin results.
Imagine this page with the blog posts and a tag cloud next to it. The list of posts is pluin1 and the tagcloud is plugin2, plugin2 being extremely heavy performance wise. If plugin1 has pagination then the plugin2 will be ran with every new page being loaded. This does not make any sense as the tagcloud does not change.
Something tells me that memcached can be used to cache the plugin2 so that is it not called when pagination of plugin1 is being used.
There are tons of cases like this one when one needs to cache some parts of a page but not the whole page again and again with only tiny part of changes.
any clue in that direction?
I guess something is missing ...
I tried benchmarking your setup but I don't get any performance benefits. I checked if memcached was on and it held records. When I benchmark I still see huge load on mysqld. Dmitry did you had any performance gain on your setup?
Thanks for this howto
You should always check your config against:
t3lib/config_default.php
Below example works fine for me with current TYPO3 SVN-Version:
hth regards georg
<pre>
$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations'] = array (
'cache_hash' => array(
'backend' => 't3lib_cache_backend_MemcachedBackend',
'options' => array(
'servers' => array('localhost:11211'),
)
),
'cache_pages' => array(
'backend' => 't3lib_cache_backend_MemcachedBackend',
'options' => array(
'servers' => array('localhost:11211'),
)
),
'cache_pagesection' => array(
'backend' => 't3lib_cache_backend_MemcachedBackend',
'options' => array(
'servers' => array('localhost:11211'),
)
),
);
</pre>
If you have same problem, it's likely that you forgot THE parameter that I did not read in this tutorial:
$TYPO3_CONF_VARS['SYS']['useCachingFramework'] = '1';
Enjoy!
D.
Add a comment
All fields in this form are required!