Sunteți pe pagina 1din 37

Liferay Performance

Optimizations
Michael C. Han
Director of Operations

October 13, 2010


Agenda

• Liferay Portal Application Level Tunings

• Liferay Portal’s Caching Strategies

• Runtime Tuning

• Platform level performance services


APPLICATION TUNING
Portal Tuning
• Application server • Database deployment
resources architecture

• Servlet Filters • CDN and Content


Cache
• Caching Tuning
• Search Server
Optimization
Of Threads and Connections
• Monitor application server threads
– Do not rely upon “auto-sizing”, could lead to “auto-
thrashing”
– Fast transactions imply 50-75 threads.
– No more than 200-300 threads

• Monitor JDBC connections


– Initially size for 20 connections. Adjust according to
monitored usage
Peek-a-boo
Filters are your friend…sometimes
• Servlet filter decorates each HTTP request

• Liferay ships with 36 servlet filters

• Deactivate the filters you do not need:


– AuditFilter, MonitoringFilter, CASFilter, NTLMFilter,
NTLMPostFilter, OpenSSOFilter, SharepointFilter

• Deactivate in portal.properties – good

• Comment out from web.xml - better


Filters Be Gone
Comment in web.xml Deactivate in portal-
ext.properties
<!--
<filter>
com.liferay.portal.servlet.filters.sso.ntlm.Ntl
<filter-name>SSO Ntlm Filter</filter-name> mFilter=false
<filter-
class>com.liferay.portal.servlet.filters.ss
o.ntlm.NtlmFilter</filter-class> com.liferay.portal.servlet.filters.sso.ntlm.Ntl
mPostFilter=false
</filter>
-->
com.liferay.portal.servlet.filters.sso.opensso
… .OpenSSOFilter=false
<!--
<filter-mapping>
<filter-name>SSO Ntlm Filter</filter-name>
<url-pattern>/c/portal/login</url-pattern>
</filter-mapping>
-->
Read-write Split
Benefits Implementation
• Optimize databases • Deploy two data sources,
separately for reading and one read and one write
writing. • Add META-INF/dynamic-
• Scale databases for read data-source-spring.xml to
separately from database list of spring configurations
for writes. • Enable replication between
write and read clusters.
Sharding
Benefits Implementation
• Common technique used by • Configure an appropriate
SaaS providers (e.g. Google shard selector in
Apps, Salesforce, Facebook). portal.properties
• Split data along logical • Add META-INF/dynamic-
divisions data-source-spring.xml to
• Liferay shards along portal list of spring configurations
instances • Enable replication between
write and read clusters
Searching with SOLR
• SOLR replaces Liferay’s
embedded Lucene
– Deploy solr-web
• Enables scaling of
search separately from
portal
• Built-in index
replication scheme.
Apache and CDN
• Load static JS, images, etc
outside of Portal
Application Server
– Reduces load on
application servers.

• CDNs replicate content to


servers closer to end user.
– Reduce latencies for portal
access
– Reduce load on application
servers
CACHING FOR SCALABILITY
Caching Overview

Improves application Facilitates horizontal vs


scalability vertical scaling

– Reduce database – Sun E15K > $1MM per


utilization and latency server
– Reduce overhead due to – 2 Dual CPU, Quad Core <
object-relational $10K per server
impedance
– Reduce expensive object
creation and excessive
garbage collection
Caching in Liferay

• L1 – “chip level cache”


– Request scoped cache

• L2 - “system memory”
– Constrained by heap size

• L3 – “swap space”
– Equivalent to virtual
memory swap space
Liferay L1 Caching

• Improve concurrency by caching to executing


thread.
• Prevent repeated calls to remote caches.
• Reduce object cloning within L2 caches
– Ehcache clones a cached object before providing to cache
clients.
• Able to accept a short lived “dirtiness” of data.
• Example:
– Permission cache
– Service value cache
L2 and L3 with Ehcache

Advantages Disadvantages
• Cache expiration algorithms • Cache size dictated by JVM
– LRU (least recently used)
heap capacity
– Timeout
• Each JVM maintains a copy of
the cached data.
• Cache coherence resolved • Difficult to control cache size
via replication algorithms (out of memory error)
– Asynchronous vs. – Requires careful tuning of
Synchronous Replication cache element count
– Key vs. full object replication • Increased file IO due to
swapping.
• Can be paired with disk • Potential degradation with
overflow/swapping for growth of swap file sizes.
larger caches
Caching Configurations

• Configure cache sizes and time to live


<cache
name="com.liferay.portal.model.impl.UserImpl"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="600"
overflowToDisk="false"
/>

• Configure disk overflows


<cache
name="com.liferay.portal.model.impl.UserImpl"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="600"
overflowToDisk=“true“
maxElementsOnDisk=“10000000”
diskPersistent=“false”
diskExpirationThreadIntervalSeconds=“120”
/>
Monitoring Cache Statistics
Configurable Replication Techniques

Default Ehcache Replication Liferay Portal EE Replication


• Easy to configure • Replication requests
• Multicast discovery with assigned to queues based
RMI Replication on priority.
• Difficulty in scaling beyond • Thread pools perform
8 cluster members. replication.
• 1 replication thread per • ClusterLink and reliable
cached object multicast for replication
– 200+ cached entities = 200+
replication threads
L2 and L3 via Data Grids

Advantages Disadvantages
• Each partition contains • Generating collision-safe
unique cached elements. keys consumes CPU
– Coherence no longer a – MD5 hash key
concern • Slower than in-memory
• Unlimited cache sizes caches
– Expand total cache by adding • Cache performance
another shard
impacted by network
• Cache fault tolerance performance.
Available Implementations

Terracotta Memcached
• Highly scalable, commercial • Popular open source solution
open source solution. used by Facebook, Google,
and other large deployments
• Supports both partitioned
and replicated modes • Max 2MB cached object size
• Use multiple languages to
• Rich set of monitoring tools
access cache
to manage cache
• “Roll your own” tools and
performance.
strategies
• Partitioned cache: 1 cache • Cache is 1 large cache, no
per entity segments per object
Pluggable Cache Factories

• Simple interface to access cache services


Object value = SingleVMPoolUtil.get(cacheName, objectKey);

Object value = MultiVMPoolUtil.get(cacheName, objectKey);

• Utilize dependency injection and factory pattern to


enable swapping of cache providers
<bean id="com.liferay.portal.kernel.cache.MultiVMPool"
class="com.liferay.portal.cache.MultiVMPoolImpl">
<property name="portalCacheManager"
ref="com.liferay.portal.kernel.cache.MultiVMPortalCacheManager" />
</bean>
<bean id="com.liferay.portal.kernel.cache.MultiVMPortalCacheManager"
class="com.liferay.portal.cache.ehcache.EhcachePortalCacheManager">
<property name="configPropertyKey" value="ehcache.multi.vm.config.location" />
<property name="MBeanServer" ref="registryAwareMBeanServer" />
</bean>
RUNTIME TUNING
Not just Max and Min
• Java VM – beyond -Xms and -Xmx
– Do not rely upon “automatic GC tuning.”
• Carefully tune your young and old generation
– Garbage collector algorithm choice critical
• Generational vs parallel vs CMS
– Perform detailed heap tuning: young generation, survivor spaces, etc
– Number of threads/CPUs dedicated to GC execution
– JVM vendor does matter!
• IBM vs JRockit vs Sun

• ‐server ‐XX:NewSize=700m ‐XX:MaxNewSize=700m ‐Xms2048m ‐Xmx2048m ‐XX:MaxPermSize=128m


‐XX:SurvivorRatio=20 –XX:TargetSurvivorRatio=90 –XX:MaxTenuringThreshold=15 –XX:ParallelGCThread=8
Common JVM Parameters
Watch Where You’re Going!
JVM and the OS
• Monitor CPU and virtual • Monitor network and
memory utilization disk IO
– vmstat shows CPU and – iostat shows disk
memory utilization utilization and IO
– mpstat shows the performance
performance of each – ifstat shows network
core/thread of a CPU interface performance
CPU Monitors
mpstat vmstat
IO Monitors
ifstat iostat
Don’t Neglect the Database
• Database - MySQL
– Buffer sizing to match size and load
• Key buffer
• Sort buffer
• Read buffer
– Caches
• Query caches
• Thread caches

• Database - Oracle
– Oracle RAC and Oracle Name Service
– Oracle Statistics Pack
– Oracle buffer sizes (transaction and rollback logs, etc)
LIFERAY PLATFORM SERVICES
Caching in the Platform
• All ServiceBuilder generated services can automatically
leverage Liferay’s L1 cache

• Automatic clearing of all Liferay L1 caches

• Cache via AOP using ThreadLocalCacheable method


annotation
@ThreadLocalCachable
public Group getGroup(long groupId)
throws PortalException, SystemException {

return groupPersistence.findByPrimaryKey(groupId);
}
Blocking vs Non-blocking Cache

• 500 users accessing the same data element creates


500 requests to database.

• Blocking cache ensures only 1 request goes to


databases, remaining 499 blocks until data retrieved
into cache.

• Reduce request load to data source

• Deactivate in portal.properties
Aspects and Annotations
• Spring AOP uses Java • @Async + AsyncAdvice
dynamic proxies – Method can be flagged
(AspectJ an option) as @Async
– Dynamic proxies = large
call stacks. • @Clusterable +
ClusterableAdvice
• ChainableMethodAdvic – Ensures flagged methods
e reduces call stack are executed cluster
sizes wide.
StringBuilder vs String.concat
• StringBuilder can be excessively wasteful
when concatenating small number of strings
– String.concat at times more efficient than
StringBuilder (e.g. 2-3 strings)

• Liferay’s StringBundler automatically


optimizes which mechanism to use.
– StringBundler bundler = new StringBundler();
bundler.append(….);
Q&A

S-ar putea să vă placă și