Search in sources :

Example 6 with ServerLoad

use of org.apache.geode.cache.server.ServerLoad in project geode by apache.

the class LocatorLoadSnapshotJUnitTest method testIntersectingGroups.

/**
   * Test to make sure that we balancing three servers with interecting groups correctly.
   */
@Test
public void testIntersectingGroups() {
    LocatorLoadSnapshot sn = new LocatorLoadSnapshot();
    ServerLocation l1 = new ServerLocation("localhost", 1);
    ServerLocation l2 = new ServerLocation("localhost", 2);
    ServerLocation l3 = new ServerLocation("localhost", 3);
    sn.addServer(l1, new String[] { "a" }, new ServerLoad(0, 1, 0, 1));
    sn.addServer(l2, new String[] { "a", "b" }, new ServerLoad(0, 1, 0, 1));
    sn.addServer(l3, new String[] { "b" }, new ServerLoad(0, 1, 0, 1));
    // Test with interleaving requests for either group
    for (int i = 0; i < 60; i++) {
        ServerLocation l = sn.getServerForConnection("a", Collections.EMPTY_SET);
        assertTrue(l1.equals(l) || l2.equals(l));
        l = sn.getServerForConnection("b", Collections.EMPTY_SET);
        assertTrue(l2.equals(l) || l3.equals(l));
    }
    Map expected = new HashMap();
    ServerLoad expectedLoad = new ServerLoad(40f, 1f, 0f, 1f);
    expected.put(l1, expectedLoad);
    expected.put(l2, expectedLoad);
    expected.put(l3, expectedLoad);
    assertEquals(expected, sn.getLoadMap());
    sn.updateLoad(l1, new ServerLoad(0, 1, 0, 1));
    sn.updateLoad(l2, new ServerLoad(0, 1, 0, 1));
    sn.updateLoad(l3, new ServerLoad(0, 1, 0, 1));
    // then the second group.
    for (int i = 0; i < 60; i++) {
        ServerLocation l = sn.getServerForConnection("a", Collections.EMPTY_SET);
        assertTrue(l1.equals(l) || l2.equals(l));
    }
    expected = new HashMap();
    expected.put(l1, new ServerLoad(30f, 1f, 0f, 1f));
    expected.put(l2, new ServerLoad(30f, 1f, 0f, 1f));
    expected.put(l3, new ServerLoad(0f, 1f, 0f, 1f));
    assertEquals(expected, sn.getLoadMap());
    for (int i = 0; i < 60; i++) {
        ServerLocation l = sn.getServerForConnection("b", Collections.EMPTY_SET);
        assertTrue(l2.equals(l) || l3.equals(l));
    }
    // The load can't be completely balanced, because
    // We already had 30 connections from group a on server l2.
    // But we expect that l3 should have received most of the connections
    // for group b, because it started out with 0.
    expected = new HashMap();
    expected.put(l1, new ServerLoad(30f, 1f, 0f, 1f));
    expected.put(l2, new ServerLoad(45f, 1f, 0f, 1f));
    expected.put(l3, new ServerLoad(45f, 1f, 0f, 1f));
    assertEquals(expected, sn.getLoadMap());
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 7 with ServerLoad

use of org.apache.geode.cache.server.ServerLoad in project geode by apache.

the class LocatorLoadBalancingDUnitTest method testLoadMessaging.

/**
   * Test to make sure the bridge servers communicate their updated load to the controller when the
   * load on the bridge server changes.
   *
   * @throws Exception
   */
@Test
public void testLoadMessaging() throws Exception {
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    String hostName = NetworkUtils.getServerHostName(vm0.getHost());
    vm0.invoke("Start Locator", () -> startLocator(hostName, locatorPort, ""));
    String locators = getLocatorString(host, locatorPort);
    final int serverPort = vm1.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a", "b" }, locators));
    // We expect 0 load
    Map expected = new HashMap();
    ServerLocation expectedLocation = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort);
    ServerLoad expectedLoad = new ServerLoad(0f, 1 / 800.0f, 0f, 1f);
    expected.put(expectedLocation, expectedLoad);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    vm2.invoke("StartBridgeClient", () -> {
        PoolFactoryImpl pf = new PoolFactoryImpl(null);
        pf.addServer(NetworkUtils.getServerHostName(host), serverPort);
        pf.setMinConnections(8);
        pf.setMaxConnections(8);
        pf.setSubscriptionEnabled(true);
        startBridgeClient(pf.getPoolAttributes(), new String[] { REGION_NAME });
        return null;
    });
    // We expect 8 client to server connections. The queue requires
    // an additional client to server connection, but that shouldn't show up here.
    expectedLoad = new ServerLoad(8 / 800f, 1 / 800.0f, 1f, 1f);
    expected.put(expectedLocation, expectedLoad);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    stopBridgeMemberVM(vm2);
    // Now we expect 0 load
    expectedLoad = new ServerLoad(0f, 1 / 800.0f, 0f, 1f);
    expected.put(expectedLocation, expectedLoad);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) HashMap(java.util.HashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) HashMap(java.util.HashMap) Map(java.util.Map) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with ServerLoad

use of org.apache.geode.cache.server.ServerLoad in project geode by apache.

the class LocatorLoadBalancingDUnitTest method testDiscovery.

/**
   * Test the locator discovers a bridge server and is initialized with the correct load for that
   * bridge server.
   */
@Test
public void testDiscovery() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    String hostName = NetworkUtils.getServerHostName(vm0.getHost());
    vm0.invoke("Start Locator", () -> startLocator(hostName, locatorPort, ""));
    String locators = getLocatorString(host, locatorPort);
    int serverPort = vm1.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a", "b" }, locators));
    ServerLoad expectedLoad = new ServerLoad(0f, 1 / 800.0f, 0f, 1f);
    ServerLocation expectedLocation = new ServerLocation(NetworkUtils.getServerHostName(vm0.getHost()), serverPort);
    Map expected = new HashMap();
    expected.put(expectedLocation, expectedLoad);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    int serverPort2 = vm2.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a", "b" }, locators));
    ServerLocation expectedLocation2 = new ServerLocation(NetworkUtils.getServerHostName(vm0.getHost()), serverPort2);
    expected.put(expectedLocation2, expectedLoad);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) HashMap(java.util.HashMap) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) HashMap(java.util.HashMap) Map(java.util.Map) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 9 with ServerLoad

use of org.apache.geode.cache.server.ServerLoad in project geode by apache.

the class LocatorLoadBalancingDUnitTest method testCustomLoadProbe.

@Test
public void testCustomLoadProbe() throws Exception {
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    // VM vm3 = host.getVM(3);
    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    String hostName = NetworkUtils.getServerHostName(vm0.getHost());
    vm0.invoke("Start Locator", () -> startLocator(hostName, locatorPort, ""));
    String locators = getLocatorString(host, locatorPort);
    final ServerLoad load1 = new ServerLoad(.3f, .01f, .44f, 4564f);
    final ServerLoad load2 = new ServerLoad(23.2f, 1.1f, 22.3f, .3f);
    int serverPort1 = vm1.invoke("Start BridgeServer", () -> startBridgeServer(null, locators, new String[] { REGION_NAME }, new MyLoadProbe(load1), false));
    int serverPort2 = vm2.invoke("Start BridgeServer", () -> startBridgeServer(null, locators, new String[] { REGION_NAME }, new MyLoadProbe(load2), false));
    HashMap expected = new HashMap();
    ServerLocation l1 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort1);
    ServerLocation l2 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort2);
    expected.put(l1, load1);
    expected.put(l2, load2);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    load1.setConnectionLoad(25f);
    vm1.invoke("changeLoad", () -> changeLoad(load1));
    load2.setSubscriptionConnectionLoad(3.5f);
    vm2.invoke("changeLoad", () -> changeLoad(load2));
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    final ServerLoad load1Updated = new ServerLoad(1f, .1f, 0f, 1f);
    final ServerLoad load2Updated = new ServerLoad(2f, 5f, 0f, 2f);
    expected.put(l1, load1Updated);
    expected.put(l2, load2Updated);
    vm1.invoke("changeLoad", () -> changeLoad(load1Updated));
    vm2.invoke("changeLoad", () -> changeLoad(load2Updated));
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    PoolFactoryImpl pf = new PoolFactoryImpl(null);
    pf.addLocator(NetworkUtils.getServerHostName(host), locatorPort);
    pf.setMinConnections(20);
    pf.setSubscriptionEnabled(true);
    pf.setIdleTimeout(-1);
    startBridgeClient(pf.getPoolAttributes(), new String[] { REGION_NAME });
    waitForPrefilledConnections(20);
    // The first 10 connection should to go vm1, then 1 to vm2, then another 9 to vm1
    // because have unequal values for loadPerConnection
    vm1.invoke("Check Connection Count", () -> checkConnectionCount(19));
    vm2.invoke("Check Connection Count", () -> checkConnectionCount(1));
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) HashMap(java.util.HashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 10 with ServerLoad

use of org.apache.geode.cache.server.ServerLoad in project geode by apache.

the class LocatorLoadSnapshot method getLoadMap.

/**
   * Test hook to get the current load for all servers Returns a map of ServerLocation->Load for
   * each server.
   */
public synchronized Map getLoadMap() {
    Map connectionMap = (Map) connectionLoadMap.get(null);
    Map queueMap = (Map) queueLoadMap.get(null);
    Map result = new HashMap();
    for (Iterator itr = connectionMap.entrySet().iterator(); itr.hasNext(); ) {
        Map.Entry next = (Entry) itr.next();
        ServerLocation location = (ServerLocation) next.getKey();
        LoadHolder connectionLoad = (LoadHolder) next.getValue();
        LoadHolder queueLoad = (LoadHolder) queueMap.get(location);
        // was asynchronously removed
        if (queueLoad == null) {
            continue;
        }
        result.put(location, new ServerLoad(connectionLoad.getLoad(), connectionLoad.getLoadPerConnection(), queueLoad.getLoad(), queueLoad.getLoadPerConnection()));
    }
    return result;
}
Also used : Entry(java.util.Map.Entry) ServerLoad(org.apache.geode.cache.server.ServerLoad) Entry(java.util.Map.Entry) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Iterator(java.util.Iterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

ServerLoad (org.apache.geode.cache.server.ServerLoad)19 Test (org.junit.Test)15 HashMap (java.util.HashMap)8 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 Map (java.util.Map)6 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)5 Host (org.apache.geode.test.dunit.Host)4 VM (org.apache.geode.test.dunit.VM)4 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Iterator (java.util.Iterator)2 PoolFactoryImpl (org.apache.geode.internal.cache.PoolFactoryImpl)2 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ClientConnectionRequest (org.apache.geode.cache.client.internal.locator.ClientConnectionRequest)1