use of org.apache.storm.scheduler.resource.RasNodes in project storm by apache.
the class BaseResourceAwareStrategy method prepareForScheduling.
/**
* Initialize instance variables as the first step in {@link #schedule(Cluster, TopologyDetails)}.
* This method may be extended by subclasses to initialize additional variables as in
* {@link ConstraintSolverStrategy#prepareForScheduling(Cluster, TopologyDetails)}.
*
* @param cluster on which executors will be scheduled.
* @param topologyDetails to be scheduled.
*/
protected void prepareForScheduling(Cluster cluster, TopologyDetails topologyDetails) {
this.cluster = cluster;
this.topologyDetails = topologyDetails;
// from Cluster
this.nodes = new RasNodes(cluster);
networkTopography = cluster.getNetworkTopography();
hostnameToNodes = this.nodes.getHostnameToNodes();
// from TopologyDetails
topoName = topologyDetails.getName();
execToComp = topologyDetails.getExecutorToComponent();
compToExecs = topologyDetails.getComponentToExecutors();
Map<String, Object> topoConf = topologyDetails.getConf();
orderExecutorsByProximity = isOrderByProximity(topoConf);
maxSchedulingTimeMs = computeMaxSchedulingTimeMs(topoConf);
// From Cluster and TopologyDetails - and cleaned-up
// all unassigned executors including system components execs
unassignedExecutors = Collections.unmodifiableSet(new HashSet<>(cluster.getUnassignedExecutors(topologyDetails)));
int confMaxStateSearch = getMaxStateSearchFromTopoConf(topologyDetails.getConf());
int daemonMaxStateSearch = ObjectReader.getInt(cluster.getConf().get(DaemonConfig.RESOURCE_AWARE_SCHEDULER_MAX_STATE_SEARCH));
maxStateSearch = Math.min(daemonMaxStateSearch, confMaxStateSearch);
LOG.debug("The max state search configured by topology {} is {}", topologyDetails.getId(), confMaxStateSearch);
LOG.debug("The max state search that will be used by topology {} is {}", topologyDetails.getId(), maxStateSearch);
searcherState = createSearcherState();
setNodeSorter(new NodeSorterHostProximity(cluster, topologyDetails, nodeSortType));
setExecSorter(orderExecutorsByProximity ? new ExecSorterByProximity(topologyDetails) : new ExecSorterByConnectionCount(topologyDetails));
logClusterInfo();
}
use of org.apache.storm.scheduler.resource.RasNodes in project storm by apache.
the class TestNodeSorterHostProximity method testMultipleRacksWithHostProximity.
/**
* Test if hosts are presented together regardless of resource availability.
* Supervisors are created with multiple Numa zones in such a manner that resources on two numa zones on the same host
* differ widely in resource availability.
*/
@Test
public void testMultipleRacksWithHostProximity() {
final Map<String, SupervisorDetails> supMap = new HashMap<>();
final int numRacks = 1;
final int numSupersPerRack = 12;
final int numPortsPerSuper = 4;
final int numZonesPerHost = 3;
final double numaResourceMultiplier = 0.4;
int rackStartNum = 0;
int supStartNum = 0;
final Map<String, SupervisorDetails> supMapRack0 = genSupervisorsWithRacksAndNuma(numRacks, numSupersPerRack, numZonesPerHost, numPortsPerSuper, rackStartNum++, supStartNum, 400, 8000, Collections.emptyMap(), numaResourceMultiplier);
// generate another rack of supervisors with less resources
supStartNum += numSupersPerRack;
final Map<String, SupervisorDetails> supMapRack1 = genSupervisorsWithRacksAndNuma(numRacks, numSupersPerRack, numZonesPerHost, numPortsPerSuper, rackStartNum++, supStartNum, 200, 4000, Collections.emptyMap(), numaResourceMultiplier);
// generate some supervisors that are depleted of one resource
supStartNum += numSupersPerRack;
final Map<String, SupervisorDetails> supMapRack2 = genSupervisorsWithRacksAndNuma(numRacks, numSupersPerRack, numZonesPerHost, numPortsPerSuper, rackStartNum++, supStartNum, 0, 8000, Collections.emptyMap(), numaResourceMultiplier);
// generate some that has a lot of memory but little of cpu
supStartNum += numSupersPerRack;
final Map<String, SupervisorDetails> supMapRack3 = genSupervisorsWithRacksAndNuma(numRacks, numSupersPerRack, numZonesPerHost, numPortsPerSuper, rackStartNum++, supStartNum, 10, 8000 * 2 + 4000, Collections.emptyMap(), numaResourceMultiplier);
// generate some that has a lot of cpu but little of memory
supStartNum += numSupersPerRack;
final Map<String, SupervisorDetails> supMapRack4 = genSupervisorsWithRacksAndNuma(numRacks, numSupersPerRack, numZonesPerHost, numPortsPerSuper, rackStartNum++, supStartNum, 400 + 200 + 10, 1000, Collections.emptyMap(), numaResourceMultiplier);
supMap.putAll(supMapRack0);
supMap.putAll(supMapRack1);
supMap.putAll(supMapRack2);
supMap.putAll(supMapRack3);
supMap.putAll(supMapRack4);
Config config = createClusterConfig(100, 500, 500, null);
config.put(Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB, Double.MAX_VALUE);
INimbus iNimbus = new INimbusTest();
// create test DNSToSwitchMapping plugin
TestDNSToSwitchMapping testDNSToSwitchMapping = new TestDNSToSwitchMapping(supMapRack0, supMapRack1, supMapRack2, supMapRack3, supMapRack4);
Config t1Conf = new Config();
t1Conf.putAll(config);
final List<String> t1FavoredHostNames = Arrays.asList("host-41", "host-42", "host-43");
t1Conf.put(Config.TOPOLOGY_SCHEDULER_FAVORED_NODES, t1FavoredHostNames);
final List<String> t1UnfavoredHostIds = Arrays.asList("host-1", "host-2", "host-3");
t1Conf.put(Config.TOPOLOGY_SCHEDULER_UNFAVORED_NODES, t1UnfavoredHostIds);
// generate topologies
TopologyDetails topo1 = genTopology("topo-1", t1Conf, 8, 0, 2, 0, CURRENT_TIME - 2, 10, "user");
Config t2Conf = new Config();
t2Conf.putAll(config);
t2Conf.put(Config.TOPOLOGY_SCHEDULER_FAVORED_NODES, Arrays.asList("host-31", "host-32", "host-33"));
t2Conf.put(Config.TOPOLOGY_SCHEDULER_UNFAVORED_NODES, Arrays.asList("host-11", "host-12", "host-13"));
TopologyDetails topo2 = genTopology("topo-2", t2Conf, 8, 0, 2, 0, CURRENT_TIME - 2, 10, "user");
Topologies topologies = new Topologies(topo1, topo2);
Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config);
cluster.setNetworkTopography(testDNSToSwitchMapping.getRackToHosts());
INodeSorter nodeSorter = new NodeSorterHostProximity(cluster, topo1);
nodeSorter.prepare(null);
Set<String> seenHosts = new HashSet<>();
String prevHost = null;
List<String> errLines = new ArrayList();
Map<String, String> nodeToHost = new RasNodes(cluster).getNodeIdToHostname();
for (String nodeId : nodeSorter.sortAllNodes()) {
String host = nodeToHost.getOrDefault(nodeId, "no-host-for-node-" + nodeId);
errLines.add(String.format("\tnodeId:%s, host:%s", nodeId, host));
if (!host.equals(prevHost) && seenHosts.contains(host)) {
String err = String.format("Host %s for node %s is out of order:\n\t%s", host, nodeId, String.join("\n\t", errLines));
Assert.fail(err);
}
seenHosts.add(host);
prevHost = host;
}
}
Aggregations