Search in sources :

Example 11 with ServerLoad

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

the class CacheServerLoadMessage method fromData.

@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    super.fromData(in);
    load = new ServerLoad();
    InternalDataSerializer.invokeFromData(load, in);
    location = new ServerLocation();
    InternalDataSerializer.invokeFromData(location, in);
    this.clientIds = DataSerializer.readArrayList(in);
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) ServerLocation(org.apache.geode.distributed.internal.ServerLocation)

Example 12 with ServerLoad

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

the class CacheServerStatsJUnitTest method testServerStats.

@Test
public void testServerStats() throws InterruptedException {
    long startTime = System.currentTimeMillis();
    cacheServerStats.incCurrentClients();
    cacheServerStats.incConnectionThreads();
    cacheServerStats.incThreadQueueSize();
    cacheServerStats.incCurrentClientConnections();
    cacheServerStats.incFailedConnectionAttempts();
    cacheServerStats.incConnectionsTimedOut();
    cacheServerStats.incReadQueryRequestTime(startTime);
    cacheServerStats.incSentBytes(20);
    cacheServerStats.incReceivedBytes(20);
    cacheServerStats.incReadGetRequestTime(startTime);
    cacheServerStats.incProcessGetTime(startTime);
    cacheServerStats.incReadPutRequestTime(startTime);
    cacheServerStats.incProcessPutTime(startTime);
    ServerLoad load = new ServerLoad(1, 1, 1, 1);
    cacheServerStats.setLoad(load);
    sample();
    assertEquals(1, getCurrentClients());
    assertEquals(1, getConnectionThreads());
    assertEquals(1, getThreadQueueSize());
    assertEquals(1, getClientConnectionCount());
    assertEquals(1, getTotalFailedConnectionAttempts());
    assertEquals(1, getTotalConnectionsTimedOut());
    assertEquals(20, getTotalSentBytes());
    assertEquals(20, getTotalReceivedBytes());
    assertEquals(1.0, getConnectionLoad(), 0.01);
    assertEquals(1.0, getLoadPerConnection(), 0.01);
    assertEquals(1.0, getLoadPerQueue(), 0.01);
    assertEquals(1.0, getQueueLoad(), 0.01);
    assertTrue(getQueryRequestRate() > 0);
    assertTrue(getGetRequestRate() > 0);
    assertTrue(getGetRequestAvgLatency() > 0);
    assertTrue(getPutRequestRate() > 0);
    assertTrue(getPutRequestAvgLatency() > 0);
    bridge.stopMonitor();
    assertEquals(0, getCurrentClients());
    assertEquals(0, getConnectionThreads());
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with ServerLoad

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

the class GatewayReceiverStatsJUnitTest method testServerStats.

@Test
public void testServerStats() throws InterruptedException {
    long startTime = System.currentTimeMillis();
    receiverStats.incCurrentClients();
    receiverStats.incConnectionThreads();
    receiverStats.incThreadQueueSize();
    receiverStats.incCurrentClientConnections();
    receiverStats.incFailedConnectionAttempts();
    receiverStats.incConnectionsTimedOut();
    receiverStats.incReadQueryRequestTime(startTime);
    receiverStats.incSentBytes(20);
    receiverStats.incReceivedBytes(20);
    receiverStats.incReadGetRequestTime(startTime);
    receiverStats.incProcessGetTime(startTime);
    receiverStats.incReadPutRequestTime(startTime);
    receiverStats.incProcessPutTime(startTime);
    ServerLoad load = new ServerLoad(1, 1, 1, 1);
    receiverStats.setLoad(load);
    sample();
    assertEquals(1, getCurrentClients());
    assertEquals(1, getConnectionThreads());
    assertEquals(1, getThreadQueueSize());
    assertEquals(1, getClientConnectionCount());
    assertEquals(1, getTotalFailedConnectionAttempts());
    assertEquals(1, getTotalConnectionsTimedOut());
    assertEquals(20, getTotalSentBytes());
    assertEquals(20, getTotalReceivedBytes());
    assertEquals(1.0, getConnectionLoad(), 0.01);
    assertEquals(1.0, getLoadPerConnection(), 0.01);
    assertEquals(1.0, getLoadPerQueue(), 0.01);
    assertEquals(1.0, getQueueLoad(), 0.01);
    assertTrue(getGetRequestRate() > 0);
    assertTrue(getGetRequestAvgLatency() > 0);
    assertTrue(getPutRequestRate() > 0);
    assertTrue(getPutRequestAvgLatency() > 0);
    bridge.stopMonitor();
// TODO:FAIL: assertIndexDetailsEquals(0, getCurrentClients());
// TODO:FAIL: assertIndexDetailsEquals(0, getConnectionThreads());
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 14 with ServerLoad

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

the class LocatorLoadBalancingDUnitTest method testEstimation.

/**
   * Test that the locator will properly estimate the load for servers when it receives connection
   * requests.
   */
@Test
public void testEstimation() throws IOException, ClassNotFoundException {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    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(2 / 800f, 1 / 800.0f, 0f, 1f);
    ServerLocation expectedLocation = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort);
    Map expected = new HashMap();
    expected.put(expectedLocation, expectedLoad);
    SocketCreatorFactory.setDistributionConfig(new DistributionConfigImpl(new Properties()));
    ClientConnectionResponse response;
    response = (ClientConnectionResponse) new TcpClient().requestToServer(InetAddress.getByName(NetworkUtils.getServerHostName(host)), locatorPort, new ClientConnectionRequest(Collections.EMPTY_SET, null), 10000);
    Assert.assertEquals(expectedLocation, response.getServer());
    response = (ClientConnectionResponse) new TcpClient().requestToServer(InetAddress.getByName(NetworkUtils.getServerHostName(host)), locatorPort, new ClientConnectionRequest(Collections.EMPTY_SET, null), 10000, true);
    Assert.assertEquals(expectedLocation, response.getServer());
    // we expect that the connection load load will be 2 * the loadPerConnection
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    QueueConnectionResponse response2;
    response2 = (QueueConnectionResponse) new TcpClient().requestToServer(InetAddress.getByName(NetworkUtils.getServerHostName(host)), locatorPort, new QueueConnectionRequest(null, 2, Collections.EMPTY_SET, null, false), 10000, true);
    Assert.assertEquals(Collections.singletonList(expectedLocation), response2.getServers());
    response2 = (QueueConnectionResponse) new TcpClient().requestToServer(InetAddress.getByName(NetworkUtils.getServerHostName(host)), locatorPort, new QueueConnectionRequest(null, 5, Collections.EMPTY_SET, null, false), 10000, true);
    Assert.assertEquals(Collections.singletonList(expectedLocation), response2.getServers());
    // we expect that the queue load will increase by 2
    expectedLoad.setSubscriptionConnectionLoad(2f);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
}
Also used : QueueConnectionRequest(org.apache.geode.cache.client.internal.locator.QueueConnectionRequest) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) HashMap(java.util.HashMap) ClientConnectionRequest(org.apache.geode.cache.client.internal.locator.ClientConnectionRequest) Host(org.apache.geode.test.dunit.Host) Properties(java.util.Properties) ServerLoad(org.apache.geode.cache.server.ServerLoad) ClientConnectionResponse(org.apache.geode.cache.client.internal.locator.ClientConnectionResponse) DistributionConfigImpl(org.apache.geode.distributed.internal.DistributionConfigImpl) TcpClient(org.apache.geode.distributed.internal.tcpserver.TcpClient) VM(org.apache.geode.test.dunit.VM) QueueConnectionResponse(org.apache.geode.cache.client.internal.locator.QueueConnectionResponse) 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 15 with ServerLoad

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

the class ConnectionCountProbeJUnitTest method test.

@Test
public void test() {
    ConnectionCountProbe probe = new ConnectionCountProbe();
    ServerMetricsImpl metrics = new ServerMetricsImpl(800);
    ServerLoad load = probe.getLoad(metrics);
    assertEquals(0f, load.getConnectionLoad(), .0001f);
    assertEquals(0f, load.getSubscriptionConnectionLoad(), .0001f);
    assertEquals(1 / 800f, load.getLoadPerConnection(), .0001f);
    assertEquals(1f, load.getLoadPerSubscriptionConnection(), .0001f);
    for (int i = 0; i < 100; i++) {
        metrics.incConnectionCount();
    }
    load = probe.getLoad(metrics);
    assertEquals(0.125, load.getConnectionLoad(), .0001f);
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

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