Search in sources :

Example 16 with ServerLoad

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

the class ServerLocator method logServers.

private void logServers() {
    if (productUseLog != null) {
        Map<ServerLocation, ServerLoad> loadMap = getLoadMap();
        if (loadMap.size() == 0) {
            return;
        }
        long now = System.currentTimeMillis();
        long lastLogTime = this.lastLogTime;
        if (now < lastLogTime + SERVER_LOAD_LOG_INTERVAL) {
            return;
        }
        this.lastLogTime = now;
        int queues = 0;
        int connections = 0;
        for (ServerLoad l : loadMap.values()) {
            queues += l.getSubscriptionConnectionLoad();
            connections = (int) Math.ceil(l.getConnectionLoad() / l.getLoadPerConnection());
        }
        Set<DistributedMember> servers;
        synchronized (ownerMap) {
            servers = new HashSet<>(ownerMap.values());
        }
        StringBuilder sb = new StringBuilder(1000);
        sb.append("server count: ").append(servers.size()).append(" connected client count: ").append(connections).append(" client subscription queue count: ").append(queues).append(System.lineSeparator()).append("current servers : ");
        String[] ids = new String[servers.size()];
        int i = 0;
        for (DistributedMember id : servers) {
            ids[i++] = id.toString();
        }
        Arrays.sort(ids);
        for (i = 0; i < ids.length; i++) {
            sb.append(ids[i]).append(' ');
        }
        productUseLog.log(sb.toString());
    }
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) DistributedMember(org.apache.geode.distributed.DistributedMember)

Example 17 with ServerLoad

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

the class LocatorLoadSnapshotJUnitTest method testUpdateLoad.

/**
   * Test the updateLoad method. The snapshot should use the new load when choosing a server.
   */
@Test
public void testUpdateLoad() {
    LocatorLoadSnapshot sn = new LocatorLoadSnapshot();
    ServerLocation l1 = new ServerLocation("localhost", 1);
    ServerLocation l2 = new ServerLocation("localhost", 2);
    sn.addServer(l1, new String[0], new ServerLoad(1, 1, 1, 1));
    sn.addServer(l2, new String[0], new ServerLoad(100, .2f, 1, .2f));
    assertEquals(l1, sn.getServerForConnection(null, Collections.EMPTY_SET));
    assertEquals(l1, sn.getServerForConnection(null, Collections.EMPTY_SET));
    sn.updateLoad(l1, new ServerLoad(200, 1, 1, 1));
    assertEquals(l2, sn.getServerForConnection(null, Collections.EMPTY_SET));
    assertEquals(l2, sn.getServerForConnection(null, Collections.EMPTY_SET));
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 18 with ServerLoad

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

the class LocatorLoadSnapshotJUnitTest method testAreBalanced.

@Test
public void testAreBalanced() {
    final LocatorLoadSnapshot sn = new LocatorLoadSnapshot();
    assertTrue(sn.hasBalancedConnections(null));
    assertTrue(sn.hasBalancedConnections("a"));
    final ServerLocation l1 = new ServerLocation("localhost", 1);
    final ServerLocation l2 = new ServerLocation("localhost", 2);
    final 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));
    assertTrue(sn.hasBalancedConnections(null));
    assertTrue(sn.hasBalancedConnections("a"));
    assertTrue(sn.hasBalancedConnections("b"));
    sn.updateLoad(l1, new ServerLoad(1, 1, 0, 1));
    assertTrue(sn.hasBalancedConnections(null));
    assertTrue(sn.hasBalancedConnections("a"));
    assertTrue(sn.hasBalancedConnections("b"));
    sn.updateLoad(l2, new ServerLoad(2, 1, 0, 1));
    assertFalse(sn.hasBalancedConnections(null));
    assertTrue(sn.hasBalancedConnections("a"));
    assertFalse(sn.hasBalancedConnections("b"));
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 19 with ServerLoad

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

the class CacheServerBridge method fetchLoadProbe.

/** Get the load probe for this cache server **/
public ServerLoadData fetchLoadProbe() {
    ServerLoadProbe probe = cacheServer.getLoadProbe();
    ServerLoad load = probe.getLoad(new ServerMetricsImpl(cacheServer.getMaxConnections()));
    ServerLoadData data = new ServerLoadData(load.getConnectionLoad(), load.getSubscriptionConnectionLoad(), load.getLoadPerConnection(), load.getLoadPerSubscriptionConnection());
    return data;
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) ServerLoadData(org.apache.geode.management.ServerLoadData) ServerLoadProbe(org.apache.geode.cache.server.ServerLoadProbe) ServerMetricsImpl(org.apache.geode.cache.server.internal.ServerMetricsImpl)

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