Caching is one of the most important technique to improve
performance of any solution. By default Liferay portal implements caching using
EHCache framework. When we implement clustered deployment of Liferay portal
solution, we need to make sure we synchronize caches across all the nodes.
Cache synchronization is a very common issue to deal with any scalable
solution. Essentially there are two types of options to solve the issue.
1.
Using Cache
Replication
2.
Using Distributed
Cache
EHCache provides different way of implementing
cache replication. Also Liferay supports cache replication using Cluster Link.
But if we need highly scalable solution where in we are planning to keep lot of
data in cache then distributed cache is better option. In distributed cache individual
node keeps only required data in cache. Centralized cache server keeps
consolidated cache of all the nodes. Terracotta provides EHCache based
distributed cache. In this blog I will provide how to configure Liferay to use
Terracotta based distributed cache instead of EHCache based replicated cache.
Here are the steps to
configure Liferay 6.1 CE server to use terracotta as caching engine.
Step
1 Download
terracotta from http://terracotta.org/downloads/open-source/catalog URL
and install the same in a a directory. We will refer this directory
as TERRACOTTA_HOME in rest of the article.
Step
2 Download and
install Liferay Portal CE GA2 in a directory. We will refer this directory as
LIFERAY_HOME. You can download Liferay from this http://downloads.sourceforge.net/project/lportal/Liferay%20Portal/6.1.1%20GA2/liferay-portal-tomcat-6.1.1-ce-ga2-20120731132656558.zip URL.
Step
3 Now locate
LIFERAY_HOME\liferay-portal-6.1.1-ce-ga2\
tomcat-7.0.27\webapps\ROOT\WEB-INF\lib directory and delete following files.
·
ehcache*.jar
·
slf4j*.jar
Step
4 Locate the
TERRACOTTA_HOME\ehcache\lib\ directory and copy the following JAR files to
LIFERAY_HOME\liferay-portal-6.1.1-ce-ga2\
tomcat-7.0.27\webapps\ROOT\WEB-INF\lib directory.
·
ehcache*.jar
·
slf4j*.jar
Step
5 Locate the
TERRACOTTA_HOME\common directory and copy the following JAR file
to LIFERAY_HOME\liferay-portal-6.1.1-ce-ga2\
tomcat-7.0.27\webapps\ROOT\WEB-INF\lib directory.
·
terracotta-toolkit*.jar
Step
6 Create the terracotta-cache directory in the
LIFERAY_HOME\liferay-portal-6.1.1-ce-ga2\
tomcat-7.0.27\webapps\ROOT\WEB-INF\classes\ directory and create the hibernate-terracotta.xml file
with following content:
<ehcache
dynamicConfig="false"
name="hibernate-terracotta"
updateCheck="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
>
<defaultCache
eternal="false"
maxElementsInMemory="100000"
overflowToDisk="false"
timeToIdleSeconds="600"
>
<terracotta />
</defaultCache>
<cache
eternal="false"
maxElementsInMemory="100000"
name="com.liferay.portal.model.impl.UserImpl"
overflowToDisk="false"
timeToIdleSeconds="600"
>
<terracotta />
</cache>
<terracottaConfig url="localhost:9510" />
</ehcache>
|
Step 7 Create liferay-multi-vm-terracotta.xml file in LIFERAY_HOME\liferay-portal-6.1.1-ce-ga2\ tomcat-7.0.27\webapps\ROOT\WEB-INF\classes\terracotta-cache directory and add following content in it:
<ehcache
dynamicConfig="false"
name="liferay-multi-vm-terracotta"
updateCheck="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd">
<defaultCache
eternal="false"
maxElementsInMemory="10000"
overflowToDisk="false"
timeToIdleSeconds="600">
<terracotta />
</defaultCache>
<cache
eternal="false"
maxElementsInMemory="10000"
name="com.liferay.portlet.journalcontent.util.JournalContent"
overflowToDisk="false"
timeToIdleSeconds="600">
<terracotta />
</cache>
<terracottaConfig url="localhost:9510" />
</ehcache>
|
Step 8 Add the following properties in portal-ext.properties file located in LIFERAY_HOME\liferay-portal-6.1.1-ce-ga2\ directory.
1
2
3
|
net.sf.ehcache.configurationResourceName=/terracotta-cache/hibernate-terracotta.xml
ehcache.multi.vm.config.location=/terracotta-cache/liferay-multivm-terracotta.xml
hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
|
Step
9 Now start
teracotta server first and then Liferay portal server. If you are using
clustered environment then you need to repeat step 2 to 8 for each node.
No comments:
Post a Comment