YARN-10924. Clean up CapacityScheduler#initScheduler (#3581) Contributed by Szilard Nemeth

This commit is contained in:
Szilard Nemeth 2021-10-27 17:13:49 +02:00 committed by GitHub
parent c1a8285363
commit 66ac476b48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -302,38 +302,13 @@ void initScheduler(Configuration configuration) throws
IOException, YarnException { IOException, YarnException {
writeLock.lock(); writeLock.lock();
try { try {
String confProviderStr = configuration.get( this.csConfProvider = getCsConfProvider(configuration);
YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
YarnConfiguration.DEFAULT_CONFIGURATION_STORE);
switch (confProviderStr) {
case YarnConfiguration.FILE_CONFIGURATION_STORE:
this.csConfProvider =
new FileBasedCSConfigurationProvider(rmContext);
break;
case YarnConfiguration.MEMORY_CONFIGURATION_STORE:
case YarnConfiguration.LEVELDB_CONFIGURATION_STORE:
case YarnConfiguration.ZK_CONFIGURATION_STORE:
case YarnConfiguration.FS_CONFIGURATION_STORE:
this.csConfProvider = new MutableCSConfigurationProvider(rmContext);
break;
default:
throw new IOException("Invalid configuration store class: " +
confProviderStr);
}
this.csConfProvider.init(configuration); this.csConfProvider.init(configuration);
this.conf = this.csConfProvider.loadConfiguration(configuration); this.conf = this.csConfProvider.loadConfiguration(configuration);
validateConf(this.conf); validateConf(this.conf);
this.minimumAllocation = super.getMinimumAllocation(); this.minimumAllocation = super.getMinimumAllocation();
initMaximumResourceCapability(super.getMaximumAllocation()); initMaximumResourceCapability(super.getMaximumAllocation());
this.calculator = this.conf.getResourceCalculator(); this.calculator = initResourceCalculator();
if (this.calculator instanceof DefaultResourceCalculator
&& ResourceUtils.getNumberOfKnownResourceTypes() > 2) {
throw new YarnRuntimeException("RM uses DefaultResourceCalculator which"
+ " used only memory as resource-type but invalid resource-types"
+ " specified " + ResourceUtils.getResourceTypes() + ". Use"
+ " DominantResourceCalculator instead to make effective use of"
+ " these resource-types");
}
this.usePortForNodeName = this.conf.getUsePortForNodeName(); this.usePortForNodeName = this.conf.getUsePortForNodeName();
this.applications = new ConcurrentHashMap<>(); this.applications = new ConcurrentHashMap<>();
this.labelManager = rmContext.getNodeLabelManager(); this.labelManager = rmContext.getNodeLabelManager();
@ -341,28 +316,65 @@ void initScheduler(Configuration configuration) throws
this.queueManager = new CapacitySchedulerQueueManager(yarnConf, this.queueManager = new CapacitySchedulerQueueManager(yarnConf,
this.labelManager, this.appPriorityACLManager); this.labelManager, this.appPriorityACLManager);
this.queueManager.setCapacitySchedulerContext(this); this.queueManager.setCapacitySchedulerContext(this);
this.workflowPriorityMappingsMgr = new WorkflowPriorityMappingsManager(); this.workflowPriorityMappingsMgr = new WorkflowPriorityMappingsManager();
this.activitiesManager = new ActivitiesManager(rmContext); this.activitiesManager = new ActivitiesManager(rmContext);
activitiesManager.init(conf); activitiesManager.init(conf);
initializeQueues(this.conf); initializeQueues(this.conf);
this.isLazyPreemptionEnabled = conf.getLazyPreemptionEnabled(); this.isLazyPreemptionEnabled = conf.getLazyPreemptionEnabled();
this.assignMultipleEnabled = this.conf.getAssignMultipleEnabled();
this.maxAssignPerHeartbeat = this.conf.getMaxAssignPerHeartbeat();
this.appShouldFailFast = CapacitySchedulerConfiguration.shouldAppFailFast(getConfig());
initAsyncSchedulingProperties();
// Setup how many containers we can allocate for each round
offswitchPerHeartbeatLimit = this.conf.getOffSwitchPerHeartbeatLimit();
initMultiNodePlacement();
printSchedulerInitialized();
} finally {
writeLock.unlock();
}
}
private CSConfigurationProvider getCsConfProvider(Configuration configuration)
throws IOException {
String confProviderStr = configuration.get(
YarnConfiguration.SCHEDULER_CONFIGURATION_STORE_CLASS,
YarnConfiguration.DEFAULT_CONFIGURATION_STORE);
switch (confProviderStr) {
case YarnConfiguration.FILE_CONFIGURATION_STORE:
return new FileBasedCSConfigurationProvider(rmContext);
case YarnConfiguration.MEMORY_CONFIGURATION_STORE:
case YarnConfiguration.LEVELDB_CONFIGURATION_STORE:
case YarnConfiguration.ZK_CONFIGURATION_STORE:
case YarnConfiguration.FS_CONFIGURATION_STORE:
return new MutableCSConfigurationProvider(rmContext);
default:
throw new IOException("Invalid configuration store class: " + confProviderStr);
}
}
private ResourceCalculator initResourceCalculator() {
ResourceCalculator resourceCalculator = this.conf.getResourceCalculator();
if (resourceCalculator instanceof DefaultResourceCalculator
&& ResourceUtils.getNumberOfKnownResourceTypes() > 2) {
throw new YarnRuntimeException("RM uses DefaultResourceCalculator which"
+ " used only memory as resource-type but invalid resource-types"
+ " specified " + ResourceUtils.getResourceTypes() + ". Use"
+ " DominantResourceCalculator instead to make effective use of"
+ " these resource-types");
}
return resourceCalculator;
}
private void initAsyncSchedulingProperties() {
scheduleAsynchronously = this.conf.getScheduleAynschronously(); scheduleAsynchronously = this.conf.getScheduleAynschronously();
asyncScheduleInterval = this.conf.getLong(ASYNC_SCHEDULER_INTERVAL, asyncScheduleInterval = this.conf.getLong(ASYNC_SCHEDULER_INTERVAL,
DEFAULT_ASYNC_SCHEDULER_INTERVAL); DEFAULT_ASYNC_SCHEDULER_INTERVAL);
this.assignMultipleEnabled = this.conf.getAssignMultipleEnabled();
this.maxAssignPerHeartbeat = this.conf.getMaxAssignPerHeartbeat();
this.appShouldFailFast = CapacitySchedulerConfiguration.shouldAppFailFast(
getConfig());
// number of threads for async scheduling // number of threads for async scheduling
int maxAsyncSchedulingThreads = this.conf.getInt( int maxAsyncSchedulingThreads = this.conf.getInt(
CapacitySchedulerConfiguration.SCHEDULE_ASYNCHRONOUSLY_MAXIMUM_THREAD, CapacitySchedulerConfiguration.SCHEDULE_ASYNCHRONOUSLY_MAXIMUM_THREAD, 1);
1);
maxAsyncSchedulingThreads = Math.max(maxAsyncSchedulingThreads, 1); maxAsyncSchedulingThreads = Math.max(maxAsyncSchedulingThreads, 1);
if (scheduleAsynchronously) { if (scheduleAsynchronously) {
@ -377,33 +389,34 @@ void initScheduler(Configuration configuration) throws
CapacitySchedulerConfiguration. CapacitySchedulerConfiguration.
DEFAULT_SCHEDULE_ASYNCHRONOUSLY_MAXIMUM_PENDING_BACKLOGS); DEFAULT_SCHEDULE_ASYNCHRONOUSLY_MAXIMUM_PENDING_BACKLOGS);
} }
}
// Setup how many containers we can allocate for each round private void initMultiNodePlacement() {
offswitchPerHeartbeatLimit = this.conf.getOffSwitchPerHeartbeatLimit();
// Register CS specific multi-node policies to common MultiNodeManager // Register CS specific multi-node policies to common MultiNodeManager
// which will add to a MultiNodeSorter which gives a pre-sorted list of // which will add to a MultiNodeSorter which gives a pre-sorted list of
// nodes to scheduler's allocation. // nodes to scheduler's allocation.
multiNodePlacementEnabled = this.conf.getMultiNodePlacementEnabled(); multiNodePlacementEnabled = this.conf.getMultiNodePlacementEnabled();
if(rmContext.getMultiNodeSortingManager() != null) { if (rmContext.getMultiNodeSortingManager() != null) {
rmContext.getMultiNodeSortingManager().registerMultiNodePolicyNames( rmContext.getMultiNodeSortingManager().registerMultiNodePolicyNames(
multiNodePlacementEnabled, multiNodePlacementEnabled,
this.conf.getMultiNodePlacementPolicies()); this.conf.getMultiNodePlacementPolicies());
} }
LOG.info("Initialized CapacityScheduler with " + "calculator="
+ getResourceCalculator().getClass() + ", " + "minimumAllocation="
+ getMinimumResourceCapability() + ", " + "maximumAllocation="
+ getMaximumResourceCapability() + ", " + "asynchronousScheduling="
+ scheduleAsynchronously + ", " + "asyncScheduleInterval="
+ asyncScheduleInterval + "ms" + ",multiNodePlacementEnabled="
+ multiNodePlacementEnabled + ", " + "assignMultipleEnabled="
+ assignMultipleEnabled + ", " + "maxAssignPerHeartbeat="
+ maxAssignPerHeartbeat + ", " + "offswitchPerHeartbeatLimit="
+ offswitchPerHeartbeatLimit);
} finally {
writeLock.unlock();
} }
private void printSchedulerInitialized() {
LOG.info("Initialized CapacityScheduler with calculator={}, minimumAllocation={}, " +
"maximumAllocation={}, asynchronousScheduling={}, asyncScheduleInterval={} ms, " +
"multiNodePlacementEnabled={}, assignMultipleEnabled={}, maxAssignPerHeartbeat={}, " +
"offswitchPerHeartbeatLimit={}",
getResourceCalculator().getClass(),
getMinimumResourceCapability(),
getMaximumResourceCapability(),
scheduleAsynchronously,
asyncScheduleInterval,
multiNodePlacementEnabled,
assignMultipleEnabled,
maxAssignPerHeartbeat,
offswitchPerHeartbeatLimit);
} }
private void startSchedulerThreads() { private void startSchedulerThreads() {