Liferay Performance Optimizations: Michael C. Han
Liferay Performance Optimizations: Michael C. Han
Optimizations
Michael C. Han
Director of Operations
• Runtime Tuning
• L2 - “system memory”
– Constrained by heap size
• L3 – “swap space”
– Equivalent to virtual
memory swap space
Liferay L1 Caching
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
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
• 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
return groupPersistence.findByPrimaryKey(groupId);
}
Blocking vs Non-blocking Cache
• 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)