Skip to content

Commit a948b97

Browse files
sryzapdeyhim
authored andcommitted
SPARK-1252. On YARN, use container-log4j.properties for executors
container-log4j.properties is a file that YARN provides so that containers can have log4j.properties distinct from that of the NodeManagers. Logs now go to syslog, and stderr and stdout just have the process's standard err and standard out. I tested this on pseudo-distributed clusters for both yarn (Hadoop 2.2) and yarn-alpha (Hadoop 0.23.7)/ Author: Sandy Ryza <[email protected]> Closes apache#148 from sryza/sandy-spark-1252 and squashes the following commits: c0043b8 [Sandy Ryza] Put log4j.properties file under common 55823da [Sandy Ryza] Add license headers to new files 10934b8 [Sandy Ryza] Add log4j-spark-container.properties and support SPARK_LOG4J_CONF e74450b [Sandy Ryza] SPARK-1252. On YARN, use container-log4j.properties for executors
1 parent f50c3b8 commit a948b97

File tree

7 files changed

+53
-5
lines changed

7 files changed

+53
-5
lines changed

yarn/alpha/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnable.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class ExecutorRunnable(
8181
credentials.writeTokenStorageToStream(dob)
8282
ctx.setContainerTokens(ByteBuffer.wrap(dob.getData()))
8383

84-
val commands = prepareCommand(masterAddress, slaveId, hostname, executorMemory, executorCores)
84+
val commands = prepareCommand(masterAddress, slaveId, hostname, executorMemory, executorCores,
85+
localResources.contains(ClientBase.LOG4J_PROP))
8586
logInfo("Setting up executor with commands: " + commands)
8687
ctx.setCommands(commands)
8788

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License. See accompanying LICENSE file.
13+
14+
# Set everything to be logged to the console
15+
log4j.rootCategory=INFO, console
16+
log4j.appender.console=org.apache.log4j.ConsoleAppender
17+
log4j.appender.console.target=System.err
18+
log4j.appender.console.layout=org.apache.log4j.PatternLayout
19+
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n
20+
21+
# Settings to quiet third party logs that are too verbose
22+
log4j.logger.org.eclipse.jetty=WARN
23+
log4j.logger.org.apache.spark.repl.SparkIMain$exprTyper=INFO
24+
log4j.logger.org.apache.spark.repl.SparkILoop$SparkILoopInterpreter=INFO

yarn/common/src/main/scala/org/apache/spark/deploy/yarn/ClientBase.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ trait ClientBase extends Logging {
266266
localResources: HashMap[String, LocalResource],
267267
stagingDir: String): HashMap[String, String] = {
268268
logInfo("Setting up the launch environment")
269-
val log4jConfLocalRes = localResources.getOrElse(ClientBase.LOG4J_PROP, null)
270269

271270
val env = new HashMap[String, String]()
272271

273-
ClientBase.populateClasspath(yarnConf, sparkConf, log4jConfLocalRes != null, env)
272+
ClientBase.populateClasspath(yarnConf, sparkConf, localResources.contains(ClientBase.LOG4J_PROP),
273+
env)
274274
env("SPARK_YARN_MODE") = "true"
275275
env("SPARK_YARN_STAGING_DIR") = stagingDir
276276
env("SPARK_USER") = UserGroupInformation.getCurrentUser().getShortUserName()
@@ -344,6 +344,10 @@ trait ClientBase extends Logging {
344344
JAVA_OPTS += " " + env("SPARK_JAVA_OPTS")
345345
}
346346

347+
if (!localResources.contains(ClientBase.LOG4J_PROP)) {
348+
JAVA_OPTS += " " + YarnSparkHadoopUtil.getLoggingArgsForContainerCommandLine()
349+
}
350+
347351
// Command for the ApplicationMaster
348352
val commands = List[String](
349353
Environment.JAVA_HOME.$() + "/bin/java" +

yarn/common/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnableUtil.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ trait ExecutorRunnableUtil extends Logging {
5050
slaveId: String,
5151
hostname: String,
5252
executorMemory: Int,
53-
executorCores: Int) = {
53+
executorCores: Int,
54+
userSpecifiedLogFile: Boolean) = {
5455
// Extra options for the JVM
5556
var JAVA_OPTS = ""
5657
// Set the JVM memory
@@ -63,6 +64,10 @@ trait ExecutorRunnableUtil extends Logging {
6364
JAVA_OPTS += " -Djava.io.tmpdir=" +
6465
new Path(Environment.PWD.$(), YarnConfiguration.DEFAULT_CONTAINER_TEMP_DIR) + " "
6566

67+
if (!userSpecifiedLogFile) {
68+
JAVA_OPTS += " " + YarnSparkHadoopUtil.getLoggingArgsForContainerCommandLine()
69+
}
70+
6671
// Commenting it out for now - so that people can refer to the properties if required. Remove
6772
// it once cpuset version is pushed out.
6873
// The context is, default gc for server class machines end up using all cores to do gc - hence

yarn/common/src/main/scala/org/apache/spark/deploy/yarn/YarnSparkHadoopUtil.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.apache.hadoop.mapred.JobConf
2222
import org.apache.hadoop.security.Credentials
2323
import org.apache.hadoop.security.UserGroupInformation
2424
import org.apache.hadoop.yarn.conf.YarnConfiguration
25+
import org.apache.hadoop.yarn.api.ApplicationConstants
2526
import org.apache.hadoop.conf.Configuration
2627
import org.apache.spark.deploy.SparkHadoopUtil
2728

@@ -67,3 +68,9 @@ class YarnSparkHadoopUtil extends SparkHadoopUtil {
6768
}
6869

6970
}
71+
72+
object YarnSparkHadoopUtil {
73+
def getLoggingArgsForContainerCommandLine(): String = {
74+
"-Dlog4j.configuration=log4j-spark-container.properties"
75+
}
76+
}

yarn/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@
167167

168168
<outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>
169169
<testOutputDirectory>target/scala-${scala.binary.version}/test-classes</testOutputDirectory>
170+
171+
<resources>
172+
<resource>
173+
<directory>../common/src/main/resources</directory>
174+
</resource>
175+
</resources>
170176
</build>
171177

172178
</project>

yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnable.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class ExecutorRunnable(
7878
credentials.writeTokenStorageToStream(dob)
7979
ctx.setTokens(ByteBuffer.wrap(dob.getData()))
8080

81-
val commands = prepareCommand(masterAddress, slaveId, hostname, executorMemory, executorCores)
81+
val commands = prepareCommand(masterAddress, slaveId, hostname, executorMemory, executorCores,
82+
localResources.contains(ClientBase.LOG4J_PROP))
8283

8384
logInfo("Setting up executor with commands: " + commands)
8485
ctx.setCommands(commands)

0 commit comments

Comments
 (0)