forked from LinhongLiu/OAP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpark.2.4.4.numa.patch
233 lines (221 loc) · 11.2 KB
/
Spark.2.4.4.numa.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
diff --git a/core/src/main/scala/org/apache/spark/executor/CoarseGrainedExecutorBackend.scala b/core/src/main/scala/org/apache/spark/executor/CoarseGrainedExecutorBackend.scala
index 48d3630..c001191 100644
--- a/core/src/main/scala/org/apache/spark/executor/CoarseGrainedExecutorBackend.scala
+++ b/core/src/main/scala/org/apache/spark/executor/CoarseGrainedExecutorBackend.scala
@@ -41,6 +41,7 @@ private[spark] class CoarseGrainedExecutorBackend(
override val rpcEnv: RpcEnv,
driverUrl: String,
executorId: String,
+ numaNodeId: Option[String],
hostname: String,
cores: Int,
userClassPath: Seq[URL],
@@ -177,6 +178,7 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging {
private def run(
driverUrl: String,
executorId: String,
+ numaNodeId: Option[String],
hostname: String,
cores: Int,
appId: String,
@@ -221,8 +223,10 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging {
val env = SparkEnv.createExecutorEnv(
driverConf, executorId, hostname, cores, cfg.ioEncryptionKey, isLocal = false)
+ SparkEnv.get.conf.set("spark.executor.numa.id", s"${numaNodeId.getOrElse(-1)}")
+
env.rpcEnv.setupEndpoint("Executor", new CoarseGrainedExecutorBackend(
- env.rpcEnv, driverUrl, executorId, hostname, cores, userClassPath, env))
+ env.rpcEnv, driverUrl, executorId, numaNodeId, hostname, cores, userClassPath, env))
workerUrl.foreach { url =>
env.rpcEnv.setupEndpoint("WorkerWatcher", new WorkerWatcher(env.rpcEnv, url))
}
@@ -233,6 +237,7 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging {
def main(args: Array[String]) {
var driverUrl: String = null
var executorId: String = null
+ var numaNodeId: Option[String] = null
var hostname: String = null
var cores: Int = 0
var appId: String = null
@@ -257,6 +262,9 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging {
case ("--app-id") :: value :: tail =>
appId = value
argv = tail
+ case ("--numa-node-id") :: value :: tail =>
+ numaNodeId = Some(value.trim.toString)
+ argv = tail
case ("--worker-url") :: value :: tail =>
// Worker url is used in spark standalone mode to enforce fate-sharing with worker
workerUrl = Some(value)
@@ -278,7 +286,8 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging {
printUsageAndExit()
}
- run(driverUrl, executorId, hostname, cores, appId, workerUrl, userClassPath)
+ logInfo(s"[NUMACHECK] numaNodeId $numaNodeId")
+ run(driverUrl, executorId, numaNodeId, hostname, cores, appId, workerUrl, userClassPath)
System.exit(0)
}
@@ -291,6 +300,7 @@ private[spark] object CoarseGrainedExecutorBackend extends Logging {
| Options are:
| --driver-url <driverUrl>
| --executor-id <executorId>
+ | --numa-node-id <numaNodeId>
| --hostname <hostname>
| --cores <cores>
| --app-id <appid>
diff --git a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala
index 5ff826a..954849a 100644
--- a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala
+++ b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala
@@ -428,7 +428,7 @@ private[spark] class ApplicationMaster(args: ApplicationMasterArguments) extends
val executorMemory = _sparkConf.get(EXECUTOR_MEMORY).toInt
val executorCores = _sparkConf.get(EXECUTOR_CORES)
val dummyRunner = new ExecutorRunnable(None, yarnConf, _sparkConf, driverUrl, "<executorId>",
- "<hostname>", executorMemory, executorCores, appId, securityMgr, localResources)
+ None, "<hostname>", executorMemory, executorCores, appId, securityMgr, localResources)
dummyRunner.launchContextDebugInfo()
}
diff --git a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnable.scala b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnable.scala
index 49a0b93..cf66363 100644
--- a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnable.scala
+++ b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnable.scala
@@ -36,6 +36,7 @@ import org.apache.hadoop.yarn.ipc.YarnRPC
import org.apache.hadoop.yarn.util.{ConverterUtils, Records}
import org.apache.spark.{SecurityManager, SparkConf, SparkException}
+import org.apache.spark.deploy.yarn.config._
import org.apache.spark.internal.Logging
import org.apache.spark.internal.config._
import org.apache.spark.network.util.JavaUtils
@@ -47,6 +48,7 @@ private[yarn] class ExecutorRunnable(
sparkConf: SparkConf,
masterAddress: String,
executorId: String,
+ numaNodeId: Option[String],
hostname: String,
executorMemory: Int,
executorCores: Int,
@@ -197,9 +199,23 @@ private[yarn] class ExecutorRunnable(
Seq("--user-class-path", "file:" + absPath)
}.toSeq
+ val numaEnabled = sparkConf.get(SPARK_YARN_NUMA_ENABLED)
+
+ logInfo(s"[NUMACHECK] numaEnabled $numaEnabled executorId $executorId")
+ // Don't need numa binding for driver.
+ val (numaCtlCommand, numaNodeOpts) = if (numaEnabled && executorId != "<executorId>"
+ && numaNodeId.nonEmpty) {
+ logInfo(s"numaNodeId ${numaNodeId.get}")
+ val command = s"numactl --cpubind=${numaNodeId.get} --membind=${numaNodeId.get} "
+ (command, Seq("--numa-node-id", numaNodeId.get.toString))
+ } else {
+ ("", Nil)
+ }
+
+ logInfo(s"[NUMACHECK] numactl command $numaCtlCommand")
YarnSparkHadoopUtil.addOutOfMemoryErrorArgument(javaOpts)
val commands = prefixEnv ++
- Seq(Environment.JAVA_HOME.$$() + "/bin/java", "-server") ++
+ Seq(numaCtlCommand + Environment.JAVA_HOME.$$() + "/bin/java", "-server") ++
javaOpts ++
Seq("org.apache.spark.executor.CoarseGrainedExecutorBackend",
"--driver-url", masterAddress,
@@ -207,11 +223,13 @@ private[yarn] class ExecutorRunnable(
"--hostname", hostname,
"--cores", executorCores.toString,
"--app-id", appId) ++
+ numaNodeOpts ++
userClassPath ++
Seq(
s"1>${ApplicationConstants.LOG_DIR_EXPANSION_VAR}/stdout",
s"2>${ApplicationConstants.LOG_DIR_EXPANSION_VAR}/stderr")
+ logInfo(s"[NUMACHECK] container command $commands")
// TODO: it would be nicer to just make sure there are no null commands here
commands.map(s => if (s == null) "null" else s).toList
}
diff --git a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnAllocator.scala b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnAllocator.scala
index 96bc1c7..de9ef6b 100644
--- a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnAllocator.scala
+++ b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/YarnAllocator.scala
@@ -171,6 +171,13 @@ private[yarn] class YarnAllocator(
def isAllNodeBlacklisted: Boolean = allocatorBlacklistTracker.isAllNodeBlacklisted
+ // The total number of numa node
+ private[yarn] val totalNumaNumber = sparkConf.get(SPARK_YARN_NUMA_NUMBER)
+ // Mapping from host to executor counter
+ private[yarn] case class NumaInfo(cotainer2numa: mutable.HashMap[String, Int], numaUsed: Array[Int])
+
+ private[yarn] val hostToNumaInfo = new mutable.HashMap[String, NumaInfo]()
+
/**
* A sequence of pending container requests that have not yet been fulfilled.
*/
@@ -507,11 +514,25 @@ private[yarn] class YarnAllocator(
for (container <- containersToUse) {
executorIdCounter += 1
val executorHostname = container.getNodeId.getHost
+ // Setting the numa id that the executor should binding.
+ // new numaid binding method
+ val numaInfo = hostToNumaInfo.getOrElseUpdate(executorHostname,
+ NumaInfo(new mutable.HashMap[String, Int], new Array[Int](totalNumaNumber)))
+ val minUsed = numaInfo.numaUsed.min
+ val newNumaNodeId = numaInfo.numaUsed.indexOf(minUsed)
+ numaInfo.cotainer2numa.put(container.getId.toString, newNumaNodeId)
+ numaInfo.numaUsed(newNumaNodeId) += 1
+
+ val numaNodeId = newNumaNodeId.toString
+ logInfo(s"numaNodeId: $numaNodeId on host $executorHostname," +
+ "container: " + container.getId.toString +
+ ", minUsed: " + minUsed)
+
val containerId = container.getId
val executorId = executorIdCounter.toString
assert(container.getResource.getMemory >= resource.getMemory)
logInfo(s"Launching container $containerId on host $executorHostname " +
- s"for executor with ID $executorId")
+ s"for executor with ID $executorId with numa ID $numaNodeId")
def updateInternalState(): Unit = synchronized {
runningExecutors.add(executorId)
@@ -537,6 +558,7 @@ private[yarn] class YarnAllocator(
sparkConf,
driverUrl,
executorId,
+ Some(numaNodeId),
executorHostname,
executorMemory,
executorCores,
@@ -595,6 +617,17 @@ private[yarn] class YarnAllocator(
// there are some exit status' we shouldn't necessarily count against us, but for
// now I think its ok as none of the containers are expected to exit.
val exitStatus = completedContainer.getExitStatus
+
+ var numaNodeId = -1
+ val hostName = hostOpt.getOrElse("nohost")
+ val numaInfoOp = hostToNumaInfo.get(hostName)
+ numaInfoOp match {
+ case Some(numaInfo) =>
+ numaNodeId = numaInfo.cotainer2numa.get(containerId.toString).getOrElse(-1)
+ if(-1 != numaNodeId) numaInfo.numaUsed(numaNodeId) -= 1
+ case _ => numaNodeId = -1
+ }
+
val (exitCausedByApp, containerExitReason) = exitStatus match {
case ContainerExitStatus.SUCCESS =>
(false, s"Executor for container $containerId exited because of a YARN event (e.g., " +
diff --git a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/config.scala b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/config.scala
index ab8273b..d5203a7 100644
--- a/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/config.scala
+++ b/resource-managers/yarn/src/main/scala/org/apache/spark/deploy/yarn/config.scala
@@ -129,6 +129,17 @@ package object config {
/* Launcher configuration. */
+ private[spark] val SPARK_YARN_NUMA_ENABLED = ConfigBuilder("spark.yarn.numa.enabled")
+ .doc("Whether enabling numa binding when executor start up. This is recommend to true " +
+ "when persistent memory is enabled.")
+ .booleanConf
+ .createWithDefault(false)
+
+ private[spark] val SPARK_YARN_NUMA_NUMBER = ConfigBuilder("spark.yarn.numa.number")
+ .doc("Total number of numanodes in physical server")
+ .intConf
+ .createWithDefault(2)
+
private[spark] val WAIT_FOR_APP_COMPLETION = ConfigBuilder("spark.yarn.submit.waitAppCompletion")
.doc("In cluster mode, whether to wait for the application to finish before exiting the " +
"launcher process.")