Skip to content

Commit a2a8be1

Browse files
YARN-9629. Support configurable MIN_LOG_ROLLING_INTERVAL. Contributed by Adam Antal.
1 parent 15d82fc commit a2a8be1

File tree

4 files changed

+112
-31
lines changed

4 files changed

+112
-31
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/conf/YarnConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,14 @@ public static boolean isAclEnabled(Configuration conf) {
14111411
public static final long
14121412
DEFAULT_NM_LOG_AGGREGATION_ROLL_MONITORING_INTERVAL_SECONDS = -1;
14131413

1414+
/**
1415+
* The allowed hard minimum limit for {@link
1416+
* YarnConfiguration#NM_LOG_AGGREGATION_ROLL_MONITORING_INTERVAL_SECONDS}.
1417+
*/
1418+
public static final String MIN_LOG_ROLLING_INTERVAL_SECONDS = NM_PREFIX
1419+
+ "log-aggregation.roll-monitoring-interval-seconds.min";
1420+
public static final long MIN_LOG_ROLLING_INTERVAL_SECONDS_DEFAULT = 3600;
1421+
14141422
/**
14151423
* Define how many aggregated log files per application per NM we can have
14161424
* in remote file system.

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/resources/yarn-default.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,14 +3219,25 @@
32193219
<property>
32203220
<description>Defines how often NMs wake up to upload log files.
32213221
The default value is -1. By default, the logs will be uploaded when
3222-
the application is finished. By setting this configure, logs can be uploaded
3223-
periodically when the application is running. The minimum rolling-interval-seconds
3224-
can be set is 3600.
3222+
the application is finished. By setting this configuration logs can
3223+
be uploaded periodically while the application is running.
3224+
The minimum positive accepted value can be configured by the setting
3225+
"yarn.nodemanager.log-aggregation.roll-monitoring-interval-seconds.min".
32253226
</description>
32263227
<name>yarn.nodemanager.log-aggregation.roll-monitoring-interval-seconds</name>
32273228
<value>-1</value>
32283229
</property>
32293230

3231+
<property>
3232+
<description>Defines the positive minimum hard limit for
3233+
"yarn.nodemanager.log-aggregation.roll-monitoring-interval-seconds".
3234+
If this configuration has been set less than its default value (3600)
3235+
the NodeManager may raise a warning.
3236+
</description>
3237+
<name>yarn.nodemanager.log-aggregation.roll-monitoring-interval-seconds.min</name>
3238+
<value>3600</value>
3239+
</property>
3240+
32303241
<property>
32313242
<description>Define how many aggregated log files per application per NM
32323243
we can have in remote file system. By default, the total number of

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/LogAggregationService.java

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public class LogAggregationService extends AbstractService implements
7171

7272
private static final Logger LOG =
7373
LoggerFactory.getLogger(LogAggregationService.class);
74-
private static final long MIN_LOG_ROLLING_INTERVAL = 3600;
7574
// This configuration is for debug and test purpose. By setting
7675
// this configuration as true. We can break the lower bound of
7776
// NM_LOG_AGGREGATION_ROLL_MONITORING_INTERVAL_SECONDS.
@@ -106,40 +105,60 @@ public LogAggregationService(Dispatcher dispatcher, Context context,
106105
this.invalidTokenApps = ConcurrentHashMap.newKeySet();
107106
}
108107

108+
private static long calculateRollingMonitorInterval(Configuration conf) {
109+
long interval = conf.getLong(
110+
YarnConfiguration.NM_LOG_AGGREGATION_ROLL_MONITORING_INTERVAL_SECONDS,
111+
YarnConfiguration.
112+
DEFAULT_NM_LOG_AGGREGATION_ROLL_MONITORING_INTERVAL_SECONDS);
113+
114+
if (interval <= 0) {
115+
LOG.info("rollingMonitorInterval is set as " + interval
116+
+ ". The log rolling monitoring interval is disabled. "
117+
+ "The logs will be aggregated after this application is finished.");
118+
} else {
119+
boolean logAggregationDebugMode =
120+
conf.getBoolean(NM_LOG_AGGREGATION_DEBUG_ENABLED, false);
121+
long minRollingMonitorInterval = conf.getLong(
122+
YarnConfiguration.MIN_LOG_ROLLING_INTERVAL_SECONDS,
123+
YarnConfiguration.MIN_LOG_ROLLING_INTERVAL_SECONDS_DEFAULT);
124+
125+
boolean warnHardMinLimitLowerThanDefault = minRollingMonitorInterval <
126+
YarnConfiguration.MIN_LOG_ROLLING_INTERVAL_SECONDS_DEFAULT &&
127+
!logAggregationDebugMode;
128+
if (warnHardMinLimitLowerThanDefault) {
129+
LOG.warn("{} has been set to {}, which is less than the default "
130+
+ "minimum value {}. This may impact NodeManager's performance.",
131+
YarnConfiguration.MIN_LOG_ROLLING_INTERVAL_SECONDS,
132+
minRollingMonitorInterval,
133+
YarnConfiguration.MIN_LOG_ROLLING_INTERVAL_SECONDS_DEFAULT);
134+
}
135+
boolean lowerThanHardLimit = interval < minRollingMonitorInterval;
136+
if (lowerThanHardLimit) {
137+
if (logAggregationDebugMode) {
138+
LOG.info("Log aggregation debug mode enabled. " +
139+
"Skipped checking minimum limit.");
140+
} else {
141+
LOG.warn("rollingMonitorInterval should be more than " +
142+
"or equal to {} seconds. Using {} seconds instead.",
143+
minRollingMonitorInterval, minRollingMonitorInterval);
144+
interval = minRollingMonitorInterval;
145+
}
146+
}
147+
}
148+
return interval;
149+
}
150+
109151
protected void serviceInit(Configuration conf) throws Exception {
110152
int threadPoolSize = getAggregatorThreadPoolSize(conf);
111153
this.threadPool = HadoopExecutors.newFixedThreadPool(threadPoolSize,
112154
new ThreadFactoryBuilder()
113155
.setNameFormat("LogAggregationService #%d")
114156
.build());
115157

116-
rollingMonitorInterval = conf.getLong(
117-
YarnConfiguration.NM_LOG_AGGREGATION_ROLL_MONITORING_INTERVAL_SECONDS,
118-
YarnConfiguration.DEFAULT_NM_LOG_AGGREGATION_ROLL_MONITORING_INTERVAL_SECONDS);
119-
120-
boolean logAggregationDebugMode =
121-
conf.getBoolean(NM_LOG_AGGREGATION_DEBUG_ENABLED, false);
122-
123-
if (rollingMonitorInterval > 0
124-
&& rollingMonitorInterval < MIN_LOG_ROLLING_INTERVAL) {
125-
if (logAggregationDebugMode) {
126-
LOG.info("Log aggregation debug mode enabled. rollingMonitorInterval = "
127-
+ rollingMonitorInterval);
128-
} else {
129-
LOG.warn("rollingMonitorInterval should be more than or equal to {} " +
130-
"seconds. Using {} seconds instead.",
131-
MIN_LOG_ROLLING_INTERVAL, MIN_LOG_ROLLING_INTERVAL);
132-
this.rollingMonitorInterval = MIN_LOG_ROLLING_INTERVAL;
133-
}
134-
} else if (rollingMonitorInterval <= 0) {
135-
LOG.info("rollingMonitorInterval is set as " + rollingMonitorInterval
136-
+ ". The log rolling monitoring interval is disabled. "
137-
+ "The logs will be aggregated after this application is finished.");
138-
} else {
139-
LOG.info("rollingMonitorInterval is set as " + rollingMonitorInterval
140-
+ ". The logs will be aggregated every " + rollingMonitorInterval
141-
+ " seconds");
142-
}
158+
rollingMonitorInterval = calculateRollingMonitorInterval(conf);
159+
LOG.info("rollingMonitorInterval is set as {}. The logs will be " +
160+
"aggregated every {} seconds", rollingMonitorInterval,
161+
rollingMonitorInterval);
143162

144163
super.serviceInit(conf);
145164
}
@@ -413,6 +432,10 @@ public NodeId getNodeId() {
413432
return this.nodeId;
414433
}
415434

435+
@VisibleForTesting
436+
public long getRollingMonitorInterval() {
437+
return rollingMonitorInterval;
438+
}
416439

417440
private int getAggregatorThreadPoolSize(Configuration conf) {
418441
int threadPoolSize;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/logaggregation/TestLogAggregationService.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,4 +2641,43 @@ public List<String> getLogFileTypesInLastCycle() {
26412641
return this.logFileTypesInLastCycle;
26422642
}
26432643
}
2644+
2645+
@Test
2646+
public void testRollingMonitorIntervalDefault() {
2647+
LogAggregationService logAggregationService =
2648+
new LogAggregationService(dispatcher, this.context, this.delSrvc,
2649+
super.dirsHandler);
2650+
logAggregationService.init(this.conf);
2651+
2652+
long interval = logAggregationService.getRollingMonitorInterval();
2653+
assertEquals(-1L, interval);
2654+
}
2655+
2656+
@Test
2657+
public void testRollingMonitorIntervalGreaterThanSet() {
2658+
this.conf.set(YarnConfiguration.MIN_LOG_ROLLING_INTERVAL_SECONDS, "1800");
2659+
this.conf.set(YarnConfiguration
2660+
.NM_LOG_AGGREGATION_ROLL_MONITORING_INTERVAL_SECONDS, "2700");
2661+
LogAggregationService logAggregationService =
2662+
new LogAggregationService(dispatcher, this.context, this.delSrvc,
2663+
super.dirsHandler);
2664+
logAggregationService.init(this.conf);
2665+
2666+
long interval = logAggregationService.getRollingMonitorInterval();
2667+
assertEquals(2700L, interval);
2668+
}
2669+
2670+
@Test
2671+
public void testRollingMonitorIntervalLessThanSet() {
2672+
this.conf.set(YarnConfiguration.MIN_LOG_ROLLING_INTERVAL_SECONDS, "1800");
2673+
this.conf.set(YarnConfiguration
2674+
.NM_LOG_AGGREGATION_ROLL_MONITORING_INTERVAL_SECONDS, "600");
2675+
LogAggregationService logAggregationService =
2676+
new LogAggregationService(dispatcher, this.context, this.delSrvc,
2677+
super.dirsHandler);
2678+
logAggregationService.init(this.conf);
2679+
2680+
long interval = logAggregationService.getRollingMonitorInterval();
2681+
assertEquals(1800L, interval);
2682+
}
26442683
}

0 commit comments

Comments
 (0)