Skip to content

Commit 8abff51

Browse files
YARN-10292. FS-CS converter: add an option to enable asynchronous scheduling in CapacityScheduler. Contributed by Benjamin Teke
1 parent 545a0a1 commit 8abff51

File tree

7 files changed

+122
-9
lines changed

7 files changed

+122
-9
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/ConversionOptions.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ConversionOptions {
2222
private DryRunResultHolder dryRunResultHolder;
2323
private boolean dryRun;
2424
private boolean noTerminalRuleCheck;
25+
private boolean enableAsyncScheduler;
2526

2627
public ConversionOptions(DryRunResultHolder dryRunResultHolder,
2728
boolean dryRun) {
@@ -41,6 +42,14 @@ public boolean isNoRuleTerminalCheck() {
4142
return noTerminalRuleCheck;
4243
}
4344

45+
public void setEnableAsyncScheduler(boolean enableAsyncScheduler) {
46+
this.enableAsyncScheduler = enableAsyncScheduler;
47+
}
48+
49+
public boolean isEnableAsyncScheduler() {
50+
return enableAsyncScheduler;
51+
}
52+
4453
public void handleWarning(String msg, Logger log) {
4554
if (dryRun) {
4655
dryRunResultHolder.addDryRunWarning(msg);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigToCSConfigArgumentHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public enum CliOption {
109109
SKIP_VERIFICATION("skip verification", "s",
110110
"skip-verification",
111111
"Skips the verification of the converted configuration", false),
112+
ENABLE_ASYNC_SCHEDULER("enable asynchronous scheduler", "a", "enable-async-scheduler",
113+
"Enables the Asynchronous scheduler which decouples the CapacityScheduler" +
114+
" scheduling from Node Heartbeats.", false),
112115
HELP("help", "h", "help", "Displays the list of options", false);
113116

114117
private final String name;
@@ -220,6 +223,8 @@ private FSConfigToCSConfigConverter prepareAndGetConverter(
220223
conversionOptions.setDryRun(dryRun);
221224
conversionOptions.setNoTerminalRuleCheck(
222225
cliParser.hasOption(CliOption.NO_TERMINAL_RULE_CHECK.shortSwitch));
226+
conversionOptions.setEnableAsyncScheduler(
227+
cliParser.hasOption(CliOption.ENABLE_ASYNC_SCHEDULER.shortSwitch));
223228

224229
checkOptionPresent(cliParser, CliOption.YARN_SITE);
225230
checkOutputDefined(cliParser, dryRun);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSConfigToCSConfigConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ private void convertYarnSiteXml(Configuration inputYarnSiteConfig,
270270
FSYarnSiteConverter siteConverter =
271271
new FSYarnSiteConverter();
272272
siteConverter.convertSiteProperties(inputYarnSiteConfig,
273-
convertedYarnSiteConfig, drfUsed);
273+
convertedYarnSiteConfig, drfUsed,
274+
conversionOptions.isEnableAsyncScheduler());
274275

275276
// See docs: "allow-undeclared-pools" and "user-as-default-queue" are
276277
// ignored if we have placement rules

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/FSYarnSiteConverter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class FSYarnSiteConverter {
3838

3939
@SuppressWarnings({"deprecation", "checkstyle:linelength"})
4040
public void convertSiteProperties(Configuration conf,
41-
Configuration yarnSiteConfig, boolean drfUsed) {
41+
Configuration yarnSiteConfig, boolean drfUsed, boolean enableAsyncScheduler) {
4242
yarnSiteConfig.set(YarnConfiguration.RM_SCHEDULER,
4343
CapacityScheduler.class.getCanonicalName());
4444

@@ -131,6 +131,10 @@ public void convertSiteProperties(Configuration conf,
131131
CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS,
132132
DominantResourceCalculator.class.getCanonicalName());
133133
}
134+
135+
if (enableAsyncScheduler) {
136+
yarnSiteConfig.setBoolean(CapacitySchedulerConfiguration.SCHEDULE_ASYNCHRONOUSLY_ENABLE, true);
137+
}
134138
}
135139

136140
public boolean isPreemptionEnabled() {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/TestFSConfigToCSConfigArgumentHandler.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,4 +651,35 @@ public void testValidationSkippedWhenOutputIsConsole() throws Exception {
651651

652652
verifyZeroInteractions(mockValidator);
653653
}
654+
655+
@Test
656+
public void testEnabledAsyncScheduling() throws Exception {
657+
setupFSConfigConversionFiles(true);
658+
659+
FSConfigToCSConfigArgumentHandler argumentHandler =
660+
new FSConfigToCSConfigArgumentHandler(conversionOptions, mockValidator);
661+
662+
String[] args = getArgumentsAsArrayWithDefaults("-f",
663+
FSConfigConverterTestCommons.FS_ALLOC_FILE, "-p",
664+
"-a");
665+
argumentHandler.parseAndConvert(args);
666+
667+
assertTrue("-a switch had no effect",
668+
conversionOptions.isEnableAsyncScheduler());
669+
}
670+
671+
@Test
672+
public void testDisabledAsyncScheduling() throws Exception {
673+
setupFSConfigConversionFiles(true);
674+
675+
FSConfigToCSConfigArgumentHandler argumentHandler =
676+
new FSConfigToCSConfigArgumentHandler(conversionOptions, mockValidator);
677+
678+
String[] args = getArgumentsAsArrayWithDefaults("-f",
679+
FSConfigConverterTestCommons.FS_ALLOC_FILE, "-p");
680+
argumentHandler.parseAndConvert(args);
681+
682+
assertFalse("-a switch wasn't provided but async scheduling option is true",
683+
conversionOptions.isEnableAsyncScheduler());
684+
}
654685
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/TestFSConfigToCSConfigConverter.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,41 @@ public void testPlacementRulesConversionEnabled() throws Exception {
717717
any(Boolean.class));
718718
}
719719

720+
@Test
721+
public void testConversionWhenAsyncSchedulingIsEnabled()
722+
throws Exception {
723+
boolean schedulingEnabledValue = testConversionWithAsyncSchedulingOption(true);
724+
assertTrue("Asynchronous scheduling should be true", schedulingEnabledValue);
725+
}
726+
727+
@Test
728+
public void testConversionWhenAsyncSchedulingIsDisabled() throws Exception {
729+
boolean schedulingEnabledValue = testConversionWithAsyncSchedulingOption(false);
730+
assertEquals("Asynchronous scheduling should be the default value",
731+
CapacitySchedulerConfiguration.DEFAULT_SCHEDULE_ASYNCHRONOUSLY_ENABLE,
732+
schedulingEnabledValue);
733+
}
734+
735+
private boolean testConversionWithAsyncSchedulingOption(boolean enabled) throws Exception {
736+
FSConfigToCSConfigConverterParams params = createDefaultParamsBuilder()
737+
.withClusterResource(CLUSTER_RESOURCE_STRING)
738+
.withFairSchedulerXmlConfig(FAIR_SCHEDULER_XML)
739+
.build();
740+
741+
ConversionOptions conversionOptions = createDefaultConversionOptions();
742+
conversionOptions.setEnableAsyncScheduler(enabled);
743+
744+
converter = new FSConfigToCSConfigConverter(ruleHandler,
745+
conversionOptions);
746+
747+
converter.convert(params);
748+
749+
Configuration convertedConfig = converter.getYarnSiteConfig();
750+
751+
return convertedConfig.getBoolean(CapacitySchedulerConfiguration.SCHEDULE_ASYNCHRONOUSLY_ENABLE,
752+
CapacitySchedulerConfiguration.DEFAULT_SCHEDULE_ASYNCHRONOUSLY_ENABLE);
753+
}
754+
720755
private Configuration getConvertedCSConfig(String dir) throws IOException {
721756
File capacityFile = new File(dir, "capacity-scheduler.xml");
722757
ByteArrayInputStream input =

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/fair/converter/TestFSYarnSiteConverter.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.junit.Test;
2727

2828
import static org.junit.Assert.assertEquals;
29+
import static org.junit.Assert.assertFalse;
2930
import static org.junit.Assert.assertTrue;
3031

3132
/**
@@ -52,7 +53,8 @@ public void testSiteContinuousSchedulingConversion() {
5253
yarnConfig.setInt(
5354
FairSchedulerConfiguration.CONTINUOUS_SCHEDULING_SLEEP_MS, 666);
5455

55-
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false);
56+
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false,
57+
false);
5658

5759
assertTrue("Cont. scheduling", yarnConvertedConfig.getBoolean(
5860
CapacitySchedulerConfiguration.SCHEDULE_ASYNCHRONOUSLY_ENABLE, false));
@@ -70,7 +72,8 @@ public void testSitePreemptionConversion() {
7072
FairSchedulerConfiguration.WAIT_TIME_BEFORE_NEXT_STARVATION_CHECK_MS,
7173
321);
7274

73-
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false);
75+
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false,
76+
false);
7477

7578
assertTrue("Preemption enabled",
7679
yarnConvertedConfig.getBoolean(
@@ -90,7 +93,8 @@ public void testSitePreemptionConversion() {
9093
public void testSiteAssignMultipleConversion() {
9194
yarnConfig.setBoolean(FairSchedulerConfiguration.ASSIGN_MULTIPLE, true);
9295

93-
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false);
96+
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false,
97+
false);
9498

9599
assertTrue("Assign multiple",
96100
yarnConvertedConfig.getBoolean(
@@ -102,7 +106,8 @@ public void testSiteAssignMultipleConversion() {
102106
public void testSiteMaxAssignConversion() {
103107
yarnConfig.setInt(FairSchedulerConfiguration.MAX_ASSIGN, 111);
104108

105-
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false);
109+
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false,
110+
false);
106111

107112
assertEquals("Max assign", 111,
108113
yarnConvertedConfig.getInt(
@@ -116,7 +121,8 @@ public void testSiteLocalityThresholdConversion() {
116121
yarnConfig.set(FairSchedulerConfiguration.LOCALITY_THRESHOLD_RACK,
117122
"321.321");
118123

119-
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false);
124+
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false,
125+
false);
120126

121127
assertEquals("Locality threshold node", "123.123",
122128
yarnConvertedConfig.get(
@@ -128,7 +134,8 @@ public void testSiteLocalityThresholdConversion() {
128134

129135
@Test
130136
public void testSiteDrfEnabledConversion() {
131-
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, true);
137+
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, true,
138+
false);
132139

133140
assertEquals("Resource calculator type", DominantResourceCalculator.class,
134141
yarnConvertedConfig.getClass(
@@ -137,11 +144,32 @@ public void testSiteDrfEnabledConversion() {
137144

138145
@Test
139146
public void testSiteDrfDisabledConversion() {
140-
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false);
147+
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false,
148+
false);
141149

142150
assertEquals("Resource calculator type", DefaultResourceCalculator.class,
143151
yarnConvertedConfig.getClass(
144152
CapacitySchedulerConfiguration.RESOURCE_CALCULATOR_CLASS,
145153
CapacitySchedulerConfiguration.DEFAULT_RESOURCE_CALCULATOR_CLASS));
146154
}
155+
156+
@Test
157+
public void testAsyncSchedulingEnabledConversion() {
158+
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, true,
159+
true);
160+
161+
assertTrue("Asynchronous scheduling", yarnConvertedConfig.getBoolean(
162+
CapacitySchedulerConfiguration.SCHEDULE_ASYNCHRONOUSLY_ENABLE,
163+
CapacitySchedulerConfiguration.DEFAULT_SCHEDULE_ASYNCHRONOUSLY_ENABLE));
164+
}
165+
166+
@Test
167+
public void testAsyncSchedulingDisabledConversion() {
168+
converter.convertSiteProperties(yarnConfig, yarnConvertedConfig, false,
169+
false);
170+
171+
assertFalse("Asynchronous scheduling", yarnConvertedConfig.getBoolean(
172+
CapacitySchedulerConfiguration.SCHEDULE_ASYNCHRONOUSLY_ENABLE,
173+
CapacitySchedulerConfiguration.DEFAULT_SCHEDULE_ASYNCHRONOUSLY_ENABLE));
174+
}
147175
}

0 commit comments

Comments
 (0)