/** * Test that we can remove a server from the snapshot. It should not suggest * that server after it has been removed. */ public void testRemoveServer() { 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, 10, .2f)); Assert.assertEquals(l1, sn.getServerForConnection(null, Collections.EMPTY_SET)); Assert.assertEquals(Arrays.asList(new ServerLocation[] {l1, l2} ), sn.getServersForQueue(null, Collections.EMPTY_SET, -1)); sn.removeServer(l1); Assert.assertEquals(l2, sn.getServerForConnection(null, Collections.EMPTY_SET)); Assert.assertEquals(Collections.singletonList(l2), sn.getServersForQueue(null, Collections.EMPTY_SET, -1)); }
/** * Test hook to get the load on all of the servers. Returns a map of * ServerLocation-> Load object with the current load on that server */ public Map getLoadMap() { return loadSnapshot.getLoadMap(); }
public void testAreBalanced() { final LocatorLoadSnapshot sn = new LocatorLoadSnapshot(); Assert.assertTrue(sn.hasBalancedConnections(null)); Assert.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)); Assert.assertTrue(sn.hasBalancedConnections(null)); Assert.assertTrue(sn.hasBalancedConnections("a")); Assert.assertTrue(sn.hasBalancedConnections("b")); sn.updateLoad(l1, new ServerLoad(1,1,0,1)); Assert.assertTrue(sn.hasBalancedConnections(null)); Assert.assertTrue(sn.hasBalancedConnections("a")); Assert.assertTrue(sn.hasBalancedConnections("b")); sn.updateLoad(l2, new ServerLoad(2,1,0,1)); Assert.assertFalse(sn.hasBalancedConnections(null)); Assert.assertTrue(sn.hasBalancedConnections("a")); Assert.assertFalse(sn.hasBalancedConnections("b")); }
/** * Test to make sure than an empty snapshot returns the * correct values. */ public void testEmptySnapshot() { LocatorLoadSnapshot sn = new LocatorLoadSnapshot(); Assert.assertNull(sn.getServerForConnection("group", Collections.EMPTY_SET)); Assert.assertNull(sn.getServerForConnection(null, Collections.EMPTY_SET)); Assert.assertEquals(Collections.EMPTY_LIST, sn.getServersForQueue(null, Collections.EMPTY_SET, 5)); }
/** * Test the updateLoad method. The snapshot should use the new * load when choosing a server. */ 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)); Assert.assertEquals(l1, sn.getServerForConnection(null, Collections.EMPTY_SET)); Assert.assertEquals(l1, sn.getServerForConnection(null, Collections.EMPTY_SET)); sn.updateLoad(l1, new ServerLoad(200, 1, 1, 1)); Assert.assertEquals(l2, sn.getServerForConnection(null, Collections.EMPTY_SET)); Assert.assertEquals(l2, sn.getServerForConnection(null, Collections.EMPTY_SET)); }
public void test2() { final LocatorLoadSnapshot sn = new LocatorLoadSnapshot(); sn.addServer(new ServerLocation("hs20h.gemstone.com",28543), new String[0], new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); sn.addServer(new ServerLocation("hs20l.gemstone.com",22385), new String[0], new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); sn.addServer(new ServerLocation("hs20n.gemstone.com",23482), new String[0], new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); sn.addServer(new ServerLocation("hs20m.gemstone.com",23429), new String[0], new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); sn.addServer(new ServerLocation("hs20e.gemstone.com",20154), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); sn.addServer(new ServerLocation("hs20j.gemstone.com",24273), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); sn.addServer(new ServerLocation("hs20g.gemstone.com",27125), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); sn.addServer(new ServerLocation("hs20i.gemstone.com",25201), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); sn.addServer(new ServerLocation("hs20k.gemstone.com",23711), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); sn.addServer(new ServerLocation("hs20f.gemstone.com",21025), new String[0],new ServerLoad(0.0f, 0.00125f, 0.0f, 1.0f)); }
/** * Add a new server to the load snapshot. */ public synchronized void addServer(ServerLocation location, String[] groups, ServerLoad initialLoad, long loadPollInterval) { serverGroupMap.put(location, groups); LoadHolder connectionLoad = new LoadHolder(location, initialLoad.getConnectionLoad(), initialLoad.getLoadPerConnection(), loadPollInterval); addGroups(connectionLoadMap, groups, connectionLoad); LoadHolder queueLoad = new LoadHolder(location, initialLoad.getSubscriptionConnectionLoad(), initialLoad.getLoadPerSubscriptionConnection(), loadPollInterval); addGroups(queueLoadMap, groups, queueLoad); updateLoad(location, initialLoad); }
public void restarting(DistributedSystem ds, GemFireCache cache) { if (ds != null) { this.loadSnapshot = new LocatorLoadSnapshot(); this.ds = (InternalDistributedSystem)ds; this.advisor = ControllerAdvisor.createControllerAdvisor(this); // escapes constructor but allows field to be final } }
public void addServer(ServerLocation location, String[] groups, ServerLoad initialLoad) { addServer(location, groups, initialLoad, 30000); }
public void run() { for(int ii = 0; ii < NUM_REQUESTS; ii++) { ServerLocation location; // synchronized(lock) { location = sn.getServerForConnection(null, Collections.EMPTY_SET); // } AtomicInteger count = loadCounts.get(location); count.incrementAndGet(); } } };
public void updateLoad(ServerLocation location, ServerLoad newLoad) { updateLoad(location, newLoad, null); }
/** * Pick the least loaded servers in the given group. * * @param group * the group, or null or "" if the client has no server group. * @param excludedServers * a list of servers to exclude as choices * @param count * how many distinct servers to pick. * @return a list containing the best servers. The size of the list will be * less than or equal to count, depending on if there are enough * servers available. */ public List getServersForQueue(String group, Set excludedServers, int count) { return getServersForQueue(null/* no id */, group, excludedServers, count); }
List/* <LoadHolder> */bestLHs = findBestServers(groupServers, excludedServers, count); ArrayList/* <ServerLocation> */result = new ArrayList(bestLHs.size()); addEstimate(key, task); } catch (RejectedExecutionException e) {
if (serverLoc != null) { final ServerLocation server = serverLoc.getLoadSnapshot() .getServerForGroups(serverGroups, intersectGroups, excludedServerSet); if (server != null) {
private Object getLocatorListResponse(LocatorListRequest request) { ArrayList controllers = getLocators(); boolean balanced = loadSnapshot.hasBalancedConnections(request.getServerGroup()); return new LocatorListResponse(controllers, balanced); }
/** * @param profile */ public void profileRemoved(Profile profile) { if(profile instanceof CacheServerProfile) { CacheServerProfile bp = (CacheServerProfile) profile; //InternalDistributedMember id = bp.getDistributedMember(); ServerLocation location = buildServerLocation(bp); loadSnapshot.removeServer(location); if(logger.isDebugEnabled()) { logger.debug("ServerLocator: server departed {}", location); } synchronized(ownerMap) { ownerMap.remove(location); } } else { cachedLocators = null; } }
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)); ServerLocation l = sn.getServerForConnection("a", Collections.EMPTY_SET); Assert.assertTrue(l1.equals(l) || l2.equals(l)); l = sn.getServerForConnection("b", Collections.EMPTY_SET); Assert.assertTrue(l2.equals(l) || l3.equals(l)); expected.put(l2, expectedLoad); expected.put(l3, expectedLoad); Assert.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)); ServerLocation l = sn.getServerForConnection("a", Collections.EMPTY_SET); Assert.assertTrue(l1.equals(l) || l2.equals(l)); expected.put(l2, new ServerLoad(30f, 1f, 0f, 1f)); expected.put(l3, new ServerLoad(0f, 1f, 0f, 1f)); Assert.assertEquals(expected, sn.getLoadMap()); ServerLocation l = sn.getServerForConnection("b", Collections.EMPTY_SET);
final LocatorLoadSnapshot sn = new LocatorLoadSnapshot(); final ServerLocation l1 = new ServerLocation("localhost", 1); final ServerLocation l2 = new ServerLocation("localhost", 2); int initialLoad3 = (int) (Math.random() * (NUM_REQUESTS / 2)); sn.addServer(l1, new String[0], new ServerLoad(initialLoad1, 1, 0, 1)); sn.addServer(l2, new String[0], new ServerLoad(initialLoad2, 1, 0, 1)); sn.addServer(l3, new String[0], new ServerLoad(initialLoad3, 1, 0, 1));
/** * Add a new server to the load snapshot. */ public synchronized void addServer(ServerLocation location, String[] groups, ServerLoad initialLoad, long loadPollInterval) { serverGroupMap.put(location, groups); LoadHolder connectionLoad = new LoadHolder(location, initialLoad.getConnectionLoad(), initialLoad.getLoadPerConnection(), loadPollInterval); addGroups(connectionLoadMap, groups, connectionLoad); LoadHolder queueLoad = new LoadHolder(location, initialLoad.getSubscriptionConnectionLoad(), initialLoad.getLoadPerSubscriptionConnection(), loadPollInterval); addGroups(queueLoadMap, groups, queueLoad); updateLoad(location, initialLoad); }
public void restarting(DistributedSystem ds, GemFireCache cache, SharedConfiguration sharedConfig) { if (ds != null) { this.loadSnapshot = new LocatorLoadSnapshot(); this.ds = (InternalDistributedSystem)ds; this.advisor = ControllerAdvisor.createControllerAdvisor(this); // escapes constructor but allows field to be final } }