Infinispan, JGroups and Spring

Posted by MyTimeTable Team

Recently, we moved a part of our MyTimetable caching layer from Ehcache to Infinispan. We also started to cache more aggressively in order to optimise performance. In this post we discuss some of the challenges encoured when trying to configure Infinispan and JGroups from Spring.

There are many reasons to move from Ehcache to Infinispan, and most blog posts cite performance advantages. Our reasons to move were different. The documentation and code of Infinispan is much more accessible, Infinispan is 100% open source, and the pace of development of Infinispan seems to be much higher. Nevertheless we are still relying on Ehcache for some of our caching in the current MyTimetable version, but that should change in the upcoming version.

MyTimetable uses a Spring and properties-based configuration, and for this reason it is important for us to be able to configure the default Infinispan settings from Spring. At the same time, we want to keep the individual named caches configuration in an Infinispan XML file to keep full flexibility in cache configuration. By default, the SpringEmbeddedCacheManagerFactoryBean does not support specifying both a configuration file and overrides. This seems to be a bug, because the Javadoc states that it should be possible. For this reason we extended the factory bean. Using our extension it is possible to both specify a configuration file, and override certain properties from that configuration file.

Next up is the JGroups configuration. By default, JGroups is configured using the transportProperties property of the Infinispan factory bean. You can configure a configuration file location (configurationFile), enter a configuration string (configurationString), or paste the whole configuration XML in your config (configurationXml). We were looking for a way to specify individual properties, while retrieving the base configuration from a jgroups.xml file. For this reason, we implemented our own JGroupsChannelLookup, which provides the JGroups channel to Infinispan. Using our implementation, it is possible to load a configuration file and override or set certain properties, based on the protocol name and protocol property names. The source code of this implementation is available as a gist.

We can now configure Infinispan and JGroups from Spring, using our usual property placeholders. The full Spring configuration looks like this:

TOPICS:

LinkedIn Twitter