|
Summary: A load-balancing group defines load-balancing between spaces in the cluster.
OverviewLoad-balancing is essential in any truly scalable architecture, as it enables scaling beyond the physical resources of a single-server machine. In GigaSpaces, load-balancing is the mechanism used by the clustered proxy to distribute space operations among spaces of a group. Each of these spaces can run on a different physical machine. If a space belongs to a load-balancing group, the clustered proxy originating from this space contains logical references to all space members in the load-balancing group. The references are "logical", in the sense that no active connection to a space member is opened until it is needed. This is illustrated in the following diagram:
Types of Load-BalancingHash-Based Load-Balancing | Weighted-Round-Robin Load-Balancing | Weighted-Hash Based Load-Balancing | Policy Parameters
GigaSpaces Platform ships with a number of built-in load-balancing policies. These range from relatively static policies, where each proxy "attaches" to a specific server and directs all operations to it, to extremely dynamic policies where the target of an operation takes into account the operation data and the relative strength of the machine. In each load balancing group, a load-balancing policy is specified per basic space operation: write, read, take and notify. This allows you to direct different kinds of operations to different spaces, ensuring correct semantics for the application. The following table describes the built-in load balancing types.
If you wish, you can implement your own load-balancing policies. Hash-Based Load-BalancingWhen using hash-based load-balancing the client proxy splits new written Entries into relevant cluster space nodes. The relevant space to rout the operation is determined using Entry first indexed field value hashcode. Hash-based load-balancing partition the data based on Entry/template first index field value hash code and the number of partitions to calculate the target space for the operation. hashcode % (# of partitions) The indexed attribute must implement the hashCode method to return a number used when your application writes the Entries to the space, and when it reads/takes Entries from the space.
ExampleA cluster is defined with 3 primary spaces: sp1, sp2, and sp3. Each primary space is associated with a backup space: sp1Backup, sp2Backup, and sp3Backup respectively.
Starting Replication group1:
Starting Replication group2:
Starting Replication group3:
The primary spaces are defined as part of a load-balancing group that uses a hash-based policy. The application writes the Account Entry class objects into the space. The m_accountID attribute as part of the Account class is defined as an indexed attribute using the __getSpaceIndexedFields() method. public static String[] __getSpaceIndexedFields() { String[] indexedFields = { "m_accountID" }; return indexedFields; } The Account class implementation: package com.j_spaces.examples.cluster.lbhashbackup; public class Account implements net.jini.core.entry.Entry { public Integer m_accountID; public String m_accountName; public Account() {} public Account(int id) { m_accountID = new Integer(id); m_accountName = "Account" + id; } public static String[] __getSpaceIndexedFields() { String[] indexedFields = { "m_accountID" }; return indexedFields; } public String toString() { return m_accountName; } } The m_accountID value is used by the space client proxy together with the number of the primary cluster available spaces (3) in the following manner to determine the target space for the write, read, or take operations: Target Space number = (m_accountID hashCode value) modulo (Number of available spaces)
If we will write 30 Entries with different Account.m_accountID values into a cluster, the Entries will be routed into the 3 partitions in the following manner:
If the relevant target space or its backup space is not active and the cluster does not have a fail-over policy defined, an error message will display. Weighted-Round-Robin Load-BalancingThe weighted-round-robin will distribute the operations using the defined weights – i.e. will skip to the next space in the list based on its weight. For example: lets assume we have 3 spaces: SpaceA , SpaceB and SpaceC (Lets assume that these are order of the spaces in the group). SpaceA weight is 6, SpaceB weight is 3 and SpaceC weight is 1. The client will perform its first 6 operation with space A, the next 3 operations will be done with space B and the next operation will be done with spaceC.
Weighted-Hash Based Load-BalancingThe weighted-hash based load-balancing allows you to define "regions" per space that are used to direct the Entry/operation to the relevant space. In this way, you direct to each space different amounts of operation/data. The space with high weight will accommodate a large amount of data. Routing to the target space is done based on the Entry's hash code (not the first index field value hash code), and the space weight. This load-balancing policy allows you to direct operations to spaces with a large amount of memory, and a strong or large amount of CPUs. For example: lets assume we have 3 spaces: SpaceA , SpaceB and SpaceC. We want SpaceA to accommodate 60% of the data, SpaceB to accommodate 30% of the data, and SpaceC to accommodate the remaining 10%. The cluster-members cluster configuration should look like the following: <cluster-members> <member> <member-name>container_SpaceA:SpaceA</member-name> <member-url> jini://*/container_SpaceA/SpaceA </member-url> <param> <param-name>weight</param-name> <param-value>6</param-value> </param> </member> <member> <member-name>container_SpaceB:SpaceB</member-name> <member-url> jini://*/container_SpaceB/SpaceB </member-url> <param> <param-name>weight</param-name> <param-value>3</param-value> </param> </member> <member-name>container_SpaceC:SpaceC</member-name> <member-url> jini://*/container_SpaceC/SpaceC </member-url> <param> <param-name>weight</param-name> <param-value>1</param-value> </param> </member> </cluster-members> Weights can be defined using the Cluster Wizard:
Policy ParametersThe interface that abstracts the load-balancing policy is com.j_spaces.core.cluster.ILoadBalance. The class that implements this interface must be set in the load-balancing group definition. The GigaSpaces class that implements this interface is com.j_spaces.core.cluster.LoadBalanceImpl. Since the load-balancing policy is designed to be open for many implementations, its parameters are structured in a highly open fashion: <group> ... <group-members>...</group-members> <load-bal-policy> <load-bal-impl-class> com.gigaspaces.cluster.loadbalance.LoadBalanceImpl </load-bal-impl-class> <write> <policy-type>select-by-priority</policy-type> <param> <param-name>A:a</param-name> <param-value>5</param-value> </param> <param> <param-name>B:b</param-name> <param-value>4</param-value> </param> </write> <default> <policy-type>round-robin</policy-type> </default> </load-bal-policy> </group> For each basic operation on the space (write, take, read and notify), a policy type should be defined, except when a policy type is set to the operation. In this case, the default policy is applied for all space operations. Each policy type can take parameters. Each parameter is enclosed by a tag. Each parameter has a name and a value, both of which are interpreted by the load-balancing implementation.
During runtime, the clustered proxy works with the load-balancing implementation to fulfill the policy. The hash-based policies take into account the hash code of Entries or templates involved in the operation. Thus, the administrator can influence the load-balancing by overriding the hashCode method in his or her Entries classes. The weight-based policies take into account the weight set for each space member in the cluster. A member with a higher weight will receive more requests. The weight for a member should be set in the cluster-members section of the cluster configuration file: <cluster-members> <member> <member-name>container-name:sp1</member-name> <member-url> rmi://localhost/container-name/sp1 </member-url> <param> <param-name>weight</param-name> <param-value>3</param-value> </param> </member> <member> <member-name>container-name:sp2</member-name> <member-url> rmi://localhost/container-name/sp2 </member-url> <param> <param-name>weight</param-name> <param-value>5</param-value> </param> </member> </cluster-members> You can configure the weight of a space member according to the strength of its physical resources – CPU speed, memory capacity, etc. Load-balancing with Replication/FailoverLoad-balancing can be combined with replication. Depending on the application needs and the load-balancing policy used, this may or may not be necessary. For example, if users tend to perform read operations, and the policy used is round-robin, replication will be necessary to ensure the requested Entry exists on the target space. If, by contrast, the policy used is distribute-by-class, it may not be necessary to replicate, because the class requested should have been written to the same space. Load-balancing can also be combined with failover, to achieve both scalability and fault tolerance. </cluster-config> <group> <group-name>partitioned_hashbased_group</group-name> <group-members> <xsl:copy-of select="cluster-config/cluster-members/member"/> </group-members> <load-bal-policy> <load-bal-impl-class>com.gigaspaces.cluster.loadbalance.LoadBalanceImpl </load-bal-impl-class> <default> <policy-type>hash-based</policy-type> </default> <proxy-broadcast-threadpool-min-size>4</proxy-broadcast-threadpool-min-size> <proxy-broadcast-threadpool-max-size>64</proxy-broadcast-threadpool-max-size> </load-bal-policy> </group> </groups> </cluster-config> Parallel Operations - BroadcastThere are three Broadcast options:
Controlling Broadcast ModeYou can control the Broadcast mode for a load-balancing group per space operation. This can be done via the cluster schema configuration file and via the SetLoadBalanceBroadcastCondition API. The SetLoadBalanceBroadcastCondition returns a LoadBalanceBroadcastInfo object. LoadBalanceBroadcastInfo contains the full information regarding the broadcast of the operation type, including grouping of the cluster members. Get and set functions to handle the LoadBalanceBroadcastInfo exists within the ILoadBalance interface. Broadcast is controlled and integrated with the load-balancer including failover to an alternative member in the same replication group if the broadcast to a source has failed. LoadBalanceBroadcastInfo indicates how broadcast information for gathering APIs (read, readMultiple,takeMultiple, take etc.) should be distributed between the cluster members by the clustered proxy when the template is a "null" template and taking into account the replication pattern. IJSpace space = SpaceFinder.find(spaceURL); JSpaceClusteredProxy clusteredProxy = (JSpaceClusteredProxy) space; LoadBalanceBroadcastInfo lbbi = clusteredProxy.setLoadBalanceBroadcastCondition (LoadBalancingPolicy.BroadcastCondition.BROADCAST_IF_NULL_VALUES , LoadBalancingPolicy.OPERATION_READ); setLoadBalanceBroadcastCondition enables to change the condition for broadcast for a load-balancing type of operation (take, read, notify or write) This api is usually used to set a per-proxy broadcast policy broadcastCondition : a value from LoadBalancingPolicy.BroadcastCondition operationType - load balancing operation type : LoadBalancingPolicy.OPERATION_READ , LoadBalancingPolicy.OPERATION_TAKE, LoadBalancingPolicy.OPERATION_WRITE or LoadBalancingPolicy.OPERATION_NOTIFY return the resulted LoadBalanceBroadcastInfo object public LoadBalanceBroadcastInfo setLoadBalanceBroadcastCondition(LoadBalancingPolicy.BroadcastCondition broadcastCondition,int operationType ) getLoadBalanceBroadcastCondition gets the current condition for broadcast for a load-balancing type of operation (take, read, notify or write) operationType - load balancing operation type : LoadBalancingPolicy.OPERATION_READ , LoadBalancingPolicy.OPERATION_TAKE, LoadBalancingPolicy.OPERATION_WRITE or LoadBalancingPolicy.OPERATION_NOTIFY broadcastCondition : a value from LoadBalancingPolicy.BroadcastCondition for this policy public LoadBalancingPolicy.BroadcastCondition getLoadBalanceBroadcastCondition(int operationType ) Batch Operation Execution ModeThe following table specifies when the different batch operations executed in parallel manner and when in serial manner when the space running in partitioned mode:
Parallel Operation Thread PoolThe client performs parallel operations using a dedicated thread pool managed at the proxy. You may tune this pool size via the following settings at the cluster config: <proxy-broadcast-threadpool-min-size>4</proxy-broadcast-threadpool-min-size> <proxy-broadcast-threadpool-max-size>64</proxy-broadcast-threadpool-max-size> Limitations
Load-Balancing Schema Options
|
(works on Firefox 2 and Internet Explorer 7)

For limitations and considerations when working with a partitioned space; and details regarding multi-space operations, refer to the 
