Mirror Service Examples

  Search Here
Searching GigaSpaces XAP/EDG 6.5 Documentation

                                               

This page is specific to:
GigaSpaces 6.5

If you're interested in another version, click it below:
GigaSpaces 6.0


Overview

Since GigaSpaces 6.0, Mirror Service examples are part of the eternal data source examples.
In addition, specific Mirror Service usage scenarios are presented as part of this section.

Primary-Backup topology with a Custom Mirror Service Deployed as a Processing Unit

This example introduce simple OpenSpaces Mirror benchmark application.
It includes 3 components:

  • Feeder
  • Clustered space
  • Mirror Service

All application components deployed as Processing Units.
The cluster space is configured to have 1 partition with a single backup.
You can change this easily by editing the GigaSpacesXAP\examples\openspaces\cluster\src\META-INF\spring\pu.xml:

<os-sla:sla cluster-schema="partitioned-sync2backup" number-of-instances="1" number-of-backups="1"
                max-instances-per-vm="1">
    </os-sla:sla>

Simply increase the number-of-instances to have larger value.

Installing the Application

Extract the example into \GigaSpacesXAP\examples\openspaces folder.
You should have 3 folders created:
\GigaSpacesXAP\examples\openspaces\cluster\
\GigaSpacesXAP\examples\openspaces\mirror\
\GigaSpacesXAP\examples\openspaces\feeder\

Deploying the Application

To deploy the feeder , clustered space and a Mirror:
1. Run One GSM and 4 GSCs.
2. Run \GigaSpacesXAP\examples\openspaces\cluster\build deploy-local-cluster
3. Run \GigaSpacesXAP\examples\openspaces\mirror\build deploy-local-mirror
4. Run \GigaSpacesXAP\examples\openspaces\feeder\build deploy-local-feeder

The above build commands will create processing unit deployment folders at:
\GigaSpacesXAP\deploy\cluster
\GigaSpacesXAP\deploy\mirror
\GigaSpacesXAP\deploy\feeder

Once you deploy the Feeder , cluster and the Mirror processing units, the UI should display the following:


The GSC running the feeder will display its throughput:

The GSC running the Mirror Service will display its throughput:

As you can see, because the Mirror is based on a reliable asynchronous replication channel, it is receiving its operations periodically.

The Mirror Processing Unit configuration

The Mirror Processing Unit configuration declaration includes:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:os-core="http://www.openspaces.org/schema/core"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.openspaces.org/schema/core http://www.openspaces.org/schema/core/openspaces-core.xsd">
	<bean id="propertiesConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
	<bean id="myMirror" class="org.openspaces.example.mirror.MyMirror">
	</bean>
	<os-core:space id="space" url="/./mirror-service" schema="mirror" external-data-source="myMirror" />
</beans>

The org.openspaces.example.mirror.MyMirror is the actual custom Mirror implementation.

The Mirror Implementation

The org.openspaces.example.mirror.MyMirror class implements the BulkDataPersister and the ManagedDataSource interfaces.

package org.openspaces.example.mirror;

import java.util.List;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;

import com.gigaspaces.datasource.BulkDataPersister;
import com.gigaspaces.datasource.BulkItem;
import com.gigaspaces.datasource.DataIterator;
import com.gigaspaces.datasource.DataSourceException;
import com.gigaspaces.datasource.ManagedDataSource;

public class MyMirror implements BulkDataPersister, ManagedDataSource<Person> {

	public class Reminder {
		Timer timer;

		public Reminder() {
			timer = new Timer();
			timer.schedule(new RemindTask(), 1000 ,1000);
		}

		class RemindTask extends TimerTask {
			public void run() {
				int val = count.intValue();
				int done = val -lastVal ;
				lastVal = val;
				long dur = System.currentTimeMillis() - lastTime;
				lastTime = System.currentTimeMillis();
				double tp =0;
				if (done >0) {
					tp = (done) / (double) (dur) * 1000;
				}
				System.out.println("got:" + val + " operations" + " TP[oper/sec]:" + tp);
			}
		}
	}

	public AtomicInteger count = new AtomicInteger();
	long lastTime = System.currentTimeMillis();
	int lastVal = 0;
	Reminder reminder ;

	public void executeBulk(List<BulkItem> bulk) throws DataSourceException {
		count.getAndAdd(bulk.size());
	}

	public void init(Properties arg) throws DataSourceException {
		System.out.println("init" + arg);
		reminder = new Reminder();
	}

	public DataIterator<Person> initialLoad() throws DataSourceException {
		return null;
	}

	public void shutdown() throws DataSourceException {
		reminder.timer.cancel();
	}
}

Primary-Backup topology with a Mirror Service

This figure shows how two spaces, a primary and its backup, are joined by a Mirror Service space.
Client interacts with the primary which synchronously replicates to the backup and then asynchronously replicates to the Mirror Service space.
The Mirror Service implementation writes the bulk data into the external data-source.


Mirror Service over WAN

This figure shows how two clusters, each of a primary and its backup, are joined together by a Mirror Service space.
Client interacts with the primary which synchronously replicates to the backup and then asynchronously replicates to the Mirror Service space.
The Mirror Service implementation writes the bulk data into the second cluster. Note that this sort of implementation is not the default



GigaSpaces 6.5 Documentation Contents (Current Page in Bold)

    Java

    C++

    .NET

    Middleware Capabilities

    Configuration and Management

Add GigaSpaces wiki search to your browser search engines!
(works on Firefox 2 and Internet Explorer 7)

Labels