Terracotta's latest release has a loads of new feature. This blog is to describe Ehcache sync write feature
Sync Write Lock, Old Behavior
The previous version had the following behavior on using sync write locks:
For a sync write lock, on unlock it waits until it gets an acknowledgment from the server that the transaction has been processed and applied on all the other L1s having changes from that transaction.
Basically a call like this:
This call will wait until all the transactions associated with this lock have been acknowledged by the server i.e. applied on all the L1s and the ack has been received back from all the concerned clients (to which the broadcast was made).
Sync Write Lock, New Behavior
The new release has focused on making the performance of sync write lock better.
In the new implementation server acks the client immediately when it receives a transaction batch from a client. To achieve this server now has a acknowledgment which will ensure that the client knows that the server has received the transaction batch.
So when this ack is received for this transaction, a client simply releases the lock locally (only possible when the lock is greedy). This ensures that this client can make use of the lock but will make all the other clients wait for it (since the lock will only be recalled once all the transactions for this lock will be flushed).
The numbers are only for 1 client and 1 thread and are only to demonstrate that there is not much degradation in the performance
Number of Elements: 1m
synchronousWrite false : TPS = 19873
synchronousWrite true : TPS = 19094
How to turn it on/off
To enable or disable this we need to add synchronousWrites=true|false in the terracotta element in the ehcache.xml
Below is a sample of the ehcache.xml which has this set as true
<?xml version="1.0" encoding="UTF-8"?>
<cache name="testCache" maxElementsInMemory="1000000" eternal="false"
timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" synchronousWrites="false" >
<terracottaConfig url="eng03:9510" />
Here is the Source code for my test