Delta Propagation Example

GemFire delta propagation lets you send deltas (changes) instead of full values when you propagate events from one cache to another. In distributed data management systems, most data is created once and then updated frequently. The updates are sent to other members for event propagation, redundancy management, and cache consistency in general. With delta propagation, you track only the changes in an updated object and send only the parts that have changed: the deltas. This feature brings significant performance benefits because of lower network transmission and object serialization/deserialization costs. The cost savings can be significant, especially when changes to an object instance are relatively small compared to the overall size of the instance.

Running the Example

The example shows a very simple client/server installation with one feeder client, that gets and updates data in its cache, and one receiver client, that receives data events from the server. Both are connected to a single cacheserver. The feeder client requests data from the server and then updates the data in its cache. The update to the feeder client's cache also updates the server's cache. The server automatically forwards these data events to the receiver client, so the receiver's cache is updated as well. The clients have an asynchronous listener that reports local cache activity to standard out.

The key to delta propagation is in the coding of the object stored in the region entry value. The entry value object, DeltaObj, used in this example implements GemFire's com.gemstone.gemfire.Delta, so that it sends and receives only the object deltas, rather than the full object. So, when the feeder client changes the object, the object tracks what is being changed. When the feeder client puts the object into its cache and GemFire distributes the put event to the server, the object provides only the delta for the distribution. The server receives the delta, uses the same object implementation to read the delta and update its cached copy, then forwards the delta to the receiver client, who does the same.

Note: To run this example, you must have terminal sessions configured for the QuickStart examples, as described in Setting Up Your Environment.

  1. In one session, start the GemFire cacheserver (see vFabric GemFire cacheserver for more information):

    $ cacheserver start cache-xml-file=xml/DeltaServer.xml

    The server starts in the background, sending information to the screen:

    Starting CacheServer with pid: 11283
    CacheServer pid: 11283 status: running
    $
    
  2. In the same session, start the feeder client:

    $ java quickstart.DeltaPropagationClientReceiver
  3. The feeder prompts you to press Enter. Before you do, in another session, start the receiver client:

    $ java quickstart.DeltaPropagationClientReceiver
    
  4. Go back to the feeder session and press Enter.

  5. Follow the instructions on the screens, noting the listener output from each client.

  6. Stop the receiver by pressing Enter.

  7. Stop the cacheserver:

    $ cacheserver stop
    

Example Source Files

Program and cache configuration files for the clients and the server, including the loader and listener declared in the Server.xml and Client.xml files. (The server is a GemFire cacheserver process and does not have an example source file.)

Table 1. Cache configuration files, located in $SamplesDirectory/quickstart/xml
DeltaServer.xml Initializes a cache to serve the /root/cs_region region, waiting for client communication.
DeltaClient1.xml Initializes a client of a cache server that runs on port 40404. Loads values and sends updates to the server.
DeltaClient2.xml Initializes a client of a cache server that runs on port 40450. Loads values and sends updates to the server.
Table 2. Java program files, located in $SamplesDirectory/quickstart/quickstart
DeltaObj.java A sample Object class that implements Delta.
DeltaPropagationClientFeeder.java The client that connects to the DeltaPropagationServer.java.
DeltaPropagationClientReceiver.java Sets up a new cache with a ReceiverListener.
DeltaSimpleListener.java A Delta Propagation quick start cache listener for simple uses.
DeltaReceiverListener.java A Delta Propagation quick start receiver cache listener.
Related Topics
Delta Propagation

Related Javadocs