Deploying a Space

In Part I you have learned about GigaSpaces's capabilities as a data store. In this part of the tutorial we will show you how you can deploy an In Memory Data Grid (IMDGClosed In-Memory Data Grid. A set of Space instances, typically running within their respective processing unit instances. The space instances are connected to each other to form a space cluster. The relations between the spaces define the data grid topology. Also known as Enterprise Data Grid - EDG) that provides scalability and failover. GigaSpaces can be used as a scalable application platform on which you can host your C# application. However, the data grid can also be embedded within another C# application which is not hosted within the GigaSpaces platform. In this part of the tutorial we will show you how to start a data grid and how you can interact with it.

Getting Started

To start an GigaSpaces data grid, launch gs-agent.exe from the product's bin folder. This will start all the infrastructure required to run the data grid. The following components are started:

For more information, see the Service Grid page.

When you execute the gs-agent command above without any arguments, 1 GSA, 1 GSM, 1 LUS and 2 GSC's will be started. The gs-agent command takes several different parameters as arguments.

For more information, see the Scripts page.

Connecting to a Data Grid

In order to create a data grid, you need to first deploy it onto the GigaSpaces infrastructure. It's easy to write some code that connects to an existing data grid, or deploy a new one if the data grid does not exist. In the GigaSpace lingo, a data grid is called a SpaceClosed Where GigaSpaces data is stored. It is the logical cache that holds data objects in memory and might also hold them in layered in tiering. Data is hosted from multiple SoRs, consolidated as a unified data model., and a data grid node is called a Space Instance. The space is hosted within a Processing Unit (PUClosed This is the unit of packaging and deployment in the GigaSpaces Data Grid, and is essentially the main GigaSpaces service. The Processing Unit (PU) itself is typically deployed onto the Service Grid. When a Processing Unit is deployed, a Processing Unit instance is the actual runtime entity.), which is the GigaSpaces unit of deployment.

There are several ways you can deploy a new Data Grid; by command line, with C# code embedded in your application and the admin UI. The following snippets shows how to deploy a data grid.

We want to deploy a data grid that has two primary partitions and one backup for each primary partition. Here is the gs command that you would execute to achieve this:

C:\GigaSpaces\XAP.NET-<version>\NET v4.0\Bin\Gs.exe space deploy --partitions=2 --ha xapTutorialSpace

This command will start a space called xapTutorialSpace with two primary partitions and a backup for failover for each primary.

You can also deploy the space via C# code. Here is an example:

using System;

using GigaSpaces.Core.Admin.ServiceGrid;
using GigaSpaces.Core.Admin.ServiceGrid.Manager;
using GigaSpaces.Core.Admin.ServiceGrid.ProcessingUnit;
using GigaSpaces.Core.Admin.ServiceGrid.Space;
using GigaSpaces.Core.Exceptions;

public class IMDGService {

    String spaceName = "xapTutorialSpace";

    public void startDataGrid() {
        try {
            // create an admin instance to interact with the cluster
            IServiceGridAdmin admin = new ServiceGridAdminBuilder().CreateAdmin();

            // locate a grid service manager and deploy a partioned data grid
            // with 2 primaries and one backup for each primary
            IGridServiceManager mgr = admin.GridServiceManagers.WaitForAtLeastOne();

            IProcessingUnit pu = mgr.Deploy(new SpaceDeployment(spaceName).Partitioned(2, 1));

        } catch (Exception e) {
            // already deployed, do nothing
            Console.WriteLine(e.StackTrace);
        }
    }
}

Lets take our online payment system. We are expecting thousands or even millions of payments to be processed over time and we want to store them in the IMDG. For this scenario we would like to partition our space into multiple partitions with each having a backup partition and the primary partitions are hosted on different machines then the backup partitions.

Here is how you would configure your IMDG: Lets assume we have 4 machines available. On all machines we will start a GSA. The default gs-agent script will give us a total number of 8 GSC's. We want to deploy 4 partitions each having a backup and there should only be one instance per machine.

GS_HOME\bin\gs-cli deploy-space  -cluster schema=partitioned total_members=4,1 
       -max-instances-per-machine 1 xapTutorialSpace

When the application write Payment objects into this space, GigaSpaces will use the routingClosed The mechanism that is in charge of routing the objects into and out of the corresponding partitions. The routing is based on a designated attribute inside the objects that are written to the Space, called the Routing Index. information provided [SpaceRouting] by the Payment class to route the object to the right partition.

Interacting with the Data Grid

Now we are ready to interact with the data grid. All the examples we explored in the first part of the tutorial can be used to interact with the IMDG. Here is an example how you can connect to the grid from your application:

// Connect to the Space
ISpaceProxy spaceProxy = new SpaceProxyFactory("xapTutorialSpace").Create();

Web Management Console

You can start the Web Management Console and inspect the Data Grid components that have been started. Double-click gs-webui.exe from the product's bin folder, then open a web browser and navigate to http://localhost:8099 and the login screen for the admin application will open up. The following screen shots will demonstrate some of the UI features: (no username and password needed).

Dashboard

Deployed Applications

Hosts (GSA,GSC,GSM,LUS)

Deployed Data Grids

Classes in Space

Class attributes

Space Query

You can modify the query statement and query the space in realtime. Example : select UID,* from xap.tutorial.user.model.User where creditLimit > 100 and rowNum<5000

The Admin UI console has many more features which we will introduce you to throughout this tutorial.

For more information, see the Web Management Console page.