Apache® Ignite™ Tip: Peer Class Loading Deployment Magic
In this article I will focus on Zero Deployment in Apache® Ignite™.
There is a very useful feature in Apache Ignite for inter-node byte-code exchange called peer class loading, also referred to as P2P class loading. Let’s take a look at this in little more detail.
Peer Class Loading
In Apache Ignite, there is a special distributed ClassLoader which, if enabled, will automatically redeploy Java or Scala code on every node in a grid each time the code changes.
Let’s review a simple Java code snippet from the Apache Ignite documentation shown in Figure 1.
IgniteCluster cluster = ignite.cluster(); // Compute instance over remote nodes. IgniteCompute compute = ignite.compute(cluster.forRemotes()); // Print hello message on all remote nodes. compute.broadcast(() -> System.out.println("Hello node: " + cluster.localNode().id()));
Figure 1. "Hello node" example
This code enables a “Hello node” message to be broadcast on all nodes in an Apache Ignite cluster. The code would run on all remote nodes without the need for a deployment step. So, if the code were changed, it would not be necessary to manually redeploy the code; the special distributed ClassLoader would manage the redeployment for us.
To configure peer class loading, we can use either an XML config file or program code. Figure 2 shows an example from the Apache Ignite documentation that uses Java code.
IgniteConfiguration cfg = new IgniteConfiguration(); // Enable or disable peer class loading. cfg.setPeerClassLoadingEnabled(true); // Start Ignite node. Ignite ignite = Ignition.start(cfg);
Figure 2. Enable Peer Class Loading
Specifically, there is a simple two-step process involved for using peer class loading, as follows:
- If a class that is called is already available locally on a node, then Apache Ignite will use this class and there is no requirement to request the class from a peer node.
- If a class is not available locally, a request is sent to the originating node. This originating node will send the byte-code so that the class can be loaded on the worker node.
Obviously, there are significant productivity gains in using peer class loading.
With peer class loading there are:
- No Ant scripts to run
- No Jar files to copy or FTP
- No nodes to restart
For developers working with Apache Ignite, peer class loading provides significant productivity gains, thus saving time and effort.