public QueueLimitCalculator getNodeManagerQueueLimitCalculator() { return nodeMonitor.getThresholdCalculator(); }
private ClusterNode getNode(NodeId nId) { return nodeSelector.getClusterNodes().get(nId); }
private int getMetric(ClusterNode cn) { return (cn != null) ? ((LoadComparator)nodeSelector.getComparator()) .getMetric(cn) : 0; }
@Test public void testContainerQueuingLimit() { NodeQueueLoadMonitor selector = new NodeQueueLoadMonitor( NodeQueueLoadMonitor.LoadComparator.QUEUE_LENGTH); selector.updateNode(createRMNode("h1", 1, -1, 15)); selector.updateNode(createRMNode("h2", 2, -1, 5)); selector.updateNode(createRMNode("h3", 3, -1, 10)); selector.initThresholdCalculator(0, 6, 100); QueueLimitCalculator calculator = selector.getThresholdCalculator(); ContainerQueuingLimit containerQueuingLimit = calculator .createContainerQueuingLimit(); selector.updateNode(createRMNode("h1", 1, -1, 110)); selector.updateNode(createRMNode("h2", 2, -1, 120)); selector.updateNode(createRMNode("h3", 3, -1, 130)); selector.updateNode(createRMNode("h4", 4, -1, 140)); selector.updateNode(createRMNode("h5", 5, -1, 150)); selector.updateNode(createRMNode("h6", 6, -1, 160)); selector.computeTask.run(); containerQueuingLimit = calculator.createContainerQueuingLimit(); selector.updateNode(createRMNode("h1", 1, -1, 1)); selector.updateNode(createRMNode("h2", 2, -1, 2)); selector.updateNode(createRMNode("h3", 3, -1, 3)); selector.updateNode(createRMNode("h4", 4, -1, 4)); selector.updateNode(createRMNode("h5", 5, -1, 5)); selector.updateNode(createRMNode("h6", 6, -1, 6)); selector.computeTask.run(); containerQueuingLimit = calculator.createContainerQueuingLimit();
@Test public void testWaitTimeSort() { NodeQueueLoadMonitor selector = new NodeQueueLoadMonitor( NodeQueueLoadMonitor.LoadComparator.QUEUE_WAIT_TIME); selector.updateNode(createRMNode("h1", 1, 15, 10)); selector.updateNode(createRMNode("h2", 2, 5, 10)); selector.updateNode(createRMNode("h3", 3, 10, 10)); selector.computeTask.run(); List<NodeId> nodeIds = selector.selectNodes(); System.out.println("1-> " + nodeIds); Assert.assertEquals("h2:2", nodeIds.get(0).toString()); selector.updateNode(createRMNode("h3", 3, 2, 10)); selector.computeTask.run(); nodeIds = selector.selectNodes(); System.out.println("2-> "+ nodeIds); Assert.assertEquals("h3:3", nodeIds.get(0).toString()); selector.updateNode(createRMNode("h4", 4, -1, 10)); selector.computeTask.run(); nodeIds = selector.selectNodes(); System.out.println("3-> "+ nodeIds);
nodeMonitor.addNode(nodeAddedEvent.getContainerReports(), nodeAddedEvent.getAddedRMNode()); break; nodeMonitor.removeNode(nodeRemovedEvent.getRemovedRMNode()); break; case NODE_UPDATE: nodeMonitor.updateNode(nodeUpdatedEvent.getRMNode()); break; case NODE_RESOURCE_UPDATE: nodeMonitor.updateNodeResource(nodeResourceUpdatedEvent.getRMNode(), nodeResourceUpdatedEvent.getResourceOption()); break;
new NodeQueueLoadMonitor(nodeSortInterval, comparator); topKSelector.initThresholdCalculator(sigma, limitMin, limitMax); this.nodeMonitor = topKSelector;
/** * Returns all Node Ids as ordered list from Least to Most Loaded. * @return ordered list of nodes */ public List<NodeId> selectNodes() { return selectLeastLoadedNodes(-1); }
/** * Not thread safe. Caller should synchronize on sorted nodes list. */ void update() { List<NodeId> sortedNodes = nodeSelector.getSortedNodes(); if (sortedNodes.size() > 0) { // Calculate mean int sum = 0; for (NodeId n : sortedNodes) { sum += getMetric(getNode(n)); } mean.set(sum / sortedNodes.size()); // Calculate stdev int sqrSumMean = 0; for (NodeId n : sortedNodes) { int val = getMetric(getNode(n)); sqrSumMean += Math.pow(val - mean.get(), 2); } stdev.set( (int) Math.round(Math.sqrt( sqrSumMean / (float) sortedNodes.size()))); } }
@Test public void testQueueLengthSort() { NodeQueueLoadMonitor selector = new NodeQueueLoadMonitor( NodeQueueLoadMonitor.LoadComparator.QUEUE_LENGTH); selector.updateNode(createRMNode("h1", 1, -1, 15)); selector.updateNode(createRMNode("h2", 2, -1, 5)); selector.updateNode(createRMNode("h3", 3, -1, 10)); selector.computeTask.run(); List<NodeId> nodeIds = selector.selectNodes(); System.out.println("1-> " + nodeIds); Assert.assertEquals("h2:2", nodeIds.get(0).toString()); selector.updateNode(createRMNode("h3", 3, -1, 2)); selector.computeTask.run(); nodeIds = selector.selectNodes(); System.out.println("2-> "+ nodeIds); Assert.assertEquals("h3:3", nodeIds.get(0).toString()); selector.updateNode(createRMNode("h4", 4, -1, 20)); selector.computeTask.run(); nodeIds = selector.selectNodes(); System.out.println("3-> "+ nodeIds); selector.updateNode(createRMNode("h3", 3, -1, DEFAULT_MAX_QUEUE_LENGTH)); selector.computeTask.run(); nodeIds = selector.selectNodes(); System.out.println("4-> "+ nodeIds); Assert.assertEquals(3, nodeIds.size());
@VisibleForTesting synchronized List<RemoteNode> getLeastLoadedNodes() { long currTime = System.currentTimeMillis(); if ((currTime - lastCacheUpdateTime > cacheRefreshInterval) || (cachedNodes == null)) { cachedNodes = convertToRemoteNodes( this.nodeMonitor.selectLeastLoadedNodes(this.k)); if (cachedNodes.size() > 0) { lastCacheUpdateTime = currTime; } } return cachedNodes; }
public ContainerQueuingLimit createContainerQueuingLimit() { ContainerQueuingLimit containerQueuingLimit = ContainerQueuingLimit.newInstance(); if (nodeSelector.getComparator() == LoadComparator.QUEUE_WAIT_TIME) { containerQueuingLimit.setMaxQueueWaitTimeInMs(getThreshold()); containerQueuingLimit.setMaxQueueLength(-1); } else { containerQueuingLimit.setMaxQueueWaitTimeInMs(-1); containerQueuingLimit.setMaxQueueLength(getThreshold()); } return containerQueuingLimit; } }