Performance Considerations
Managing Contention
If two transactions attempt to perform a cache operation on the same element, the following rules apply:
The first transaction gets access
The following transactions block on the cache operation until either the first transaction completes or the transaction timeout occurs.
Note: | When an element is involved in a transaction, it is replaced with a new element with a marker that is locked, along with the transaction ID. |
What Granularity of Locking is Used?
Ehcache uses soft locks stored in the Element itself and is on a key basis.
Performance Comparisons
Any transactional cache adds an overhead, which is significant for writes and nearly negligible for reads. Compared to transactionalMode="off", the time it takes to perform writes will be noticeably slower with either "xa" or "local" specified, and "xa_strict" will be the slowest.
Within the modes the relative time take to perform writes, where off = 1, is as follows:
off - no overhead
xa_strict - 20 times slower
xa - 3 times slower
local - 3 times slower The relative read performance is:
off - no overhead
xa_strict - 20 times slower
xa - 30% slower
local - 30% slower
Use "xa_strict" only when full guarantees are required, otherwise use one of the other modes.