Configuring Load Balancing for a Multi-site (WAN) System

Keep your multi-site communication optimized by balancing system communication load between multiple hubs.

Load balancing in a multi-site system spreads event queue processing between hubs.

Before you start, you should have your multi-site system configured with multiple hubs defined for each system. See Configuring a Multi-site (WAN) System.
  1. Set the startup-policy for each hub. Each hub should have one member where the startup-policy is primary. Only primaries send events to remote sites. Examples:
    • XML:
      <cache>
      	<gateway-hub id="Site1a" port="22222" startup-policy="secondary">
      		...
      	</gateway-hub> 
      	<gateway-hub id="Site1b" port="22223" startup-policy="primary">
      		...
      	</gateway-hub> 
    • Java:
      // Create or obtain the GemFire cache
      Cache cache = ... ;
      
      // Create the first Gateway Hub
      GatewayHub site1aHub = cache.setGatewayHub("Site1a", 22222);
      site1aHub.setStartupPolicy("STARTUP_POLICY_SECONDARY");
      
      // Create the second Gateway Hub
      GatewayHub site1bHub = cache.setGatewayHub("Site1b", 22223);
      site1bHub.setStartupPolicy("STARTUP_POLICY_PRIMARY");
      
      // Define gateways and endpoints for the gateway hubs ...
  2. On all remote sites, define the gateways to the multi-hub gateway by pointing to every hub instance that you defined. The region hub specifications are only for outgoing events. For incoming events, hubs process every event received regardless of their destination regions. A remote site will send each event to only one endpoint. Example:
    <cache>
    	<gateway-hub id="Some remote gateway hub ...
    		<gateway id="Site1a" ...
    			<gateway-endpoint id="Site1aLucy" host="lucy" port="22222"/>
    			<gateway-endpoint id="Site1aRicky" host="ricky" port="22222"/>
    			<gateway-endpoint id="Site1bLucy" host="lucy" port="22223"/>
    			<gateway-endpoint id="Site1bRicky" host="ricky" port="22223"/>
    		</gateway>
    	</gateway-hub> 
  3. Split region traffic between the primary hubs you have defined. For example, if you have two hubs and three regions, with one region having the bulk of the events, you would use one hub for that region and one hub for the other two regions. In your configuration, enable regions to communicate updates to the gateways as usual, adding the appropriate hub-id specification to each.
    Note: When you use multiple hubs, you must point each gateway-enabled region at one of the hubs. If you do not specify a hub for a region, region events are delivered to every hub and then sent to remote sites by each hub’s primary instance. The region configuration must be consistent across the distributed system, even in caches where there are no hubs running.
    Examples:
    • XML:
      <region name="A">
      	<region-attributes ... enable-gateway="true" hub-id="Site1a"/>
      	...
      </region>
      <region name="B">
      	<region-attributes ... enable-gateway="true" hub-id="Site1b"/>
      	...
      </region>
    • Java:
      // Region A 
      AttributesFactory factory = new AttributesFactory();
      factory.setEnableGateway(new Boolean(true));
      factory.setGatewayHubId("Site1a"); 
      Region multiSiteRegionA = cache.createRegion("A", factory.create());
      
      // Region B 
      AttributesFactory factory = new AttributesFactory();
      factory.setEnableGateway(new Boolean(true));
      factory.setGatewayHubId("Site1b"); 
      Region multiSiteRegionB = cache.createRegion("B", factory.create());
  4. Start all host members in the distributed system at the same time. This lets the primaries assume their roles before secondaries default to primary.