adamretter
adamretter

Reputation: 3517

Tuning Infinispan for local MVCC HashMap

I am new to Infinispan and basically stumbled over it whilst looking for an isolated MVCC HashMap for Java.

I am concerned that Infinispan may be somewhat heavy for what I need or that there may be a more performant way to achieve what I need with Infinispan. I don't need clustering or distribution, I just need the embedded Infinispan inside a single JVM.

At the moment I need a Map implementation which has transactions and Repeatable Read semantics, I currently have the following initialization code:

final ConfigurationBuilder builder = new ConfigurationBuilder();
builder.jmxStatistics().available(false);
builder.invocationBatching().enable();
builder.versioning().scheme(VersioningScheme.SIMPLE);
builder.versioning().enable();
builder.locking().concurrencyLevel(Runtime.getRuntime().availableProcessors() * 2);
builder.locking().writeSkewCheck(true);
builder.transaction().locking().isolationLevel(IsolationLevel.REPEATABLE_READ);
builder.transaction().lockingMode(LockingMode.OPTIMISTIC);
builder.transaction().transactionMode(TransactionMode.TRANSACTIONAL);

final DefaultCacheManager cacheManager = new DefaultCacheManager(builder.build());
final Cache<String, String> cache = cacheManager.getCache();
final TransactionManager transactionManager = cache.getAdvancedCache().getTransactionManager();

I then use the cache from various threads like so:

transactionManager.begin();
cache.put(KEY, VALUE);
...
transactionManager.commit();

Is this the most effective/performant way I could achieve this, or should I consider a different class or are there some tuning options that I am not aware of?

Upvotes: 0

Views: 183

Answers (1)

Radim Vansa
Radim Vansa

Reputation: 5888

Infinispan development is more focused on the clustered setup; local caches are rather a special case, and therefore their implementation may seem somewhat heavier.

You've missed builder.transaction().notifications(false) - that could slice another percent, and disables the ability to use transaction listeners. Also, you can experiment with budiler.transaction().useSynchronization(true), though with the dummy TM (which is used for invocation batching) it probably doesn't matter too much.

There's a cache mode optimized for local operations - simple cache but that does not support transactions. So, I'd say that this is pretty much all.

Upvotes: 2

Related Questions