Apache Ignite

Apache Ignite provides a very nice set of features for distributed caching (which is what we use it for with L2 caching) plus "Data grid" features.

My expectation is that most people will prefer client/server mode with use of near caches.

Client/server mode

We can use Ignite in client/server mode which means that our application uses a Ignite client to talk to a Ignite cluster (of servers).

In this mode the bean cache data is partitioned across all the Ignite servers in the cluster and not in our application. We can choose to use a near cache for some or all of our bean types and in doing so improve performance (by having local data) but increase memory footprint in our application (as it now holds some cache data).

Server mode

In server mode our application starts a Ignite server instance which is a full fledged member of the Ignite cluster. This means that it will hold data etc.

Dependency

Add a dependency to ebean-ignite. Pre-built packages are located on maven. The version of the ebean-ignite artifact you seleect should match the version of ebean that you are using. When Ebean starts, ebean-ignite is automatically registered as the L2 cache implementation.

Disable L2 cache

During development and testing it is often useful to disable the use of the l2 cache.

Properties
## disable use of L2 cache (for dev / testing etc)
ebean.disableL2Cache=true

Configuration

Apache Ignite is configured with a IgniteConfiguration class. The documentation for this class is available here. This class can be delivered in two ways: with an XML configuration file (which represents a persisted version of this bean), and programmatically by constructing this class and passing it into the Igniter.

For more information about Ignite Configuration, start here.

XML configuration

To configure the Ignite instance via XML, you need to construct an XML file that represents the IgniteConfiguration bean in a persisted state. Then you must place this file in a location that Ignite expects.

According to the documentation, when Ignite starts it looks for a configuration file in {IGNITE_HOME}/config/default-config.xml. You should be able to export the IGNITE_HOME environment variable to point to a director that contains your configuration file.

Programmatic configuration

You can programmatically configure Ignite by creating an instance of IgniteConfiguration and setting it via:

IgniteConfiguration configuration = ...;
serverConfig.setServiceObject("igniteConfiguration", configuration);

To do this automatically at startup, you can create a class that implements ServerConfigStartup and place it in the directory where you tell ebean to look for your models.

package models;

import io.ebean.config.ServerConfig;
import io.ebean.event.ServerConfigStartup;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;

import java.util.Arrays;

public class MyServerConfigStartup implements ServerConfigStartup {

    @Override
    public void onStart(ServerConfig serverConfig) {

        IgniteConfiguration igniteCfg = new IgniteConfiguration();
        igniteCfg.setClientMode(true);

        TcpDiscoveryVmIpFinder finder = new TcpDiscoveryVmIpFinder();
        finder.setAddresses(Arrays.asList("172.30.1.1"));

        TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
        discoverySpi.setIpFinder(finder);

        igniteCfg.setDiscoverySpi(discoverySpi);
        serverConfig.putServiceObject("igniteConfiguration", igniteCfg);
    }
}

If this configuration instance is passed in Ebean will use it to configure the Ignite instance. Otherwise it will use properties and avaje IgniteConfigBuilder.

Getting started

  • Annotate beans with @Cache
  • Add maven dependency ebean-ignite
  • Optionally add ebean-ignite-config.xml
  • For client/server mode you need a running Ignite server