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());
}
}
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));
}
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"));
}
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;
}
Aggregations