Skip to content

Commit 49a01c7

Browse files
jongyoulsrowen
authored andcommitted
[SPARK-6423][Mesos] MemoryUtils should use memoryOverhead if it's set
- Fixed calculateTotalMemory to use spark.mesos.executor.memoryOverhead - Added testCase Author: Jongyoul Lee <[email protected]> Closes #5099 from jongyoul/SPARK-6423 and squashes the following commits: 6747fce [Jongyoul Lee] [SPARK-6423][Mesos] MemoryUtils should use memoryOverhead if it's set - Changed a description of spark.mesos.executor.memoryOverhead 475a7c8 [Jongyoul Lee] [SPARK-6423][Mesos] MemoryUtils should use memoryOverhead if it's set - Fit the import rules 453c5a2 [Jongyoul Lee] [SPARK-6423][Mesos] MemoryUtils should use memoryOverhead if it's set - Fixed calculateTotalMemory to use spark.mesos.executor.memoryOverhead - Added testCase
1 parent 6b36470 commit 49a01c7

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

core/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MemoryUtils.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@ import org.apache.spark.SparkContext
2121

2222
private[spark] object MemoryUtils {
2323
// These defaults copied from YARN
24-
val OVERHEAD_FRACTION = 1.10
24+
val OVERHEAD_FRACTION = 0.10
2525
val OVERHEAD_MINIMUM = 384
2626

2727
def calculateTotalMemory(sc: SparkContext) = {
28-
math.max(
29-
sc.conf.getOption("spark.mesos.executor.memoryOverhead")
30-
.getOrElse(OVERHEAD_MINIMUM.toString)
31-
.toInt + sc.executorMemory,
32-
OVERHEAD_FRACTION * sc.executorMemory
33-
)
28+
sc.conf.getInt("spark.mesos.executor.memoryOverhead",
29+
math.max(OVERHEAD_FRACTION * sc.executorMemory, OVERHEAD_MINIMUM).toInt) + sc.executorMemory
3430
}
3531
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.scheduler.cluster.mesos
19+
20+
import org.mockito.Mockito._
21+
import org.scalatest.FunSuite
22+
import org.scalatest.mock.MockitoSugar
23+
24+
import org.apache.spark.{SparkConf, SparkContext}
25+
26+
class MemoryUtilsSuite extends FunSuite with MockitoSugar {
27+
test("MesosMemoryUtils should always override memoryOverhead when it's set") {
28+
val sparkConf = new SparkConf
29+
30+
val sc = mock[SparkContext]
31+
when(sc.conf).thenReturn(sparkConf)
32+
33+
// 384 > sc.executorMemory * 0.1 => 512 + 384 = 896
34+
when(sc.executorMemory).thenReturn(512)
35+
assert(MemoryUtils.calculateTotalMemory(sc) === 896)
36+
37+
// 384 < sc.executorMemory * 0.1 => 4096 + (4096 * 0.1) = 4505.6
38+
when(sc.executorMemory).thenReturn(4096)
39+
assert(MemoryUtils.calculateTotalMemory(sc) === 4505)
40+
41+
// set memoryOverhead
42+
sparkConf.set("spark.mesos.executor.memoryOverhead", "100")
43+
assert(MemoryUtils.calculateTotalMemory(sc) === 4196)
44+
sparkConf.set("spark.mesos.executor.memoryOverhead", "400")
45+
assert(MemoryUtils.calculateTotalMemory(sc) === 4496)
46+
}
47+
}

docs/running-on-mesos.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,9 @@ See the [configuration page](configuration.html) for information on Spark config
224224
<td><code>spark.mesos.executor.memoryOverhead</code></td>
225225
<td>executor memory * 0.10, with minimum of 384</td>
226226
<td>
227-
This value is an additive for <code>spark.executor.memory</code>, specified in MB,
228-
which is used to calculate the total Mesos task memory. A value of <code>384</code>
229-
implies a 384MB overhead. Additionally, there is a hard-coded 10% minimum
230-
overhead. The final overhead will be the larger of either
231-
`spark.mesos.executor.memoryOverhead` or 10% of `spark.executor.memory`.
227+
The amount of additional memory, specified in MB, to be allocated per executor. By default,
228+
the overhead will be larger of either 384 or 10% of `spark.executor.memory`. If it's set,
229+
the final overhead will be this value.
232230
</td>
233231
</tr>
234232
</table>

0 commit comments

Comments
 (0)