Skip to content

Commit d64dd65

Browse files
Shirish Deshmukhsumwale
authored andcommitted
[SNAPPYDATA] Allow configurable MemoryManager
To plugin SnappyData's Unified Memory Manager (SnappyUnifiedMemoryManager), the MemoryManager is made configurable using "spark.memory.manager" configuration property that is set to the SnappyData's manager in embedded mode. [SNAP-1256] (#41) set the memory manager as spark's UnifiedMemoryManager, if spark.memory.manager is set as default [SNAP-2084] (#86) If SnappyUMM is found in classpath , SparkEnv will assign the memory manager to SnappyUMM. If user has explicitly set the memory manager that will take precedence.
1 parent 3a2f83e commit d64dd65

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

core/src/main/scala/org/apache/spark/SparkEnv.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,18 @@ object SparkEnv extends Logging {
342342

343343
val useLegacyMemoryManager = conf.getBoolean("spark.memory.useLegacyMode", false)
344344
val memoryManager: MemoryManager =
345-
if (useLegacyMemoryManager) {
346-
new StaticMemoryManager(conf, numUsableCores)
347-
} else {
348-
UnifiedMemoryManager(conf, numUsableCores)
345+
conf.getOption("spark.memory.manager").filterNot(_.equalsIgnoreCase("default"))
346+
.map(Utils.classForName(_)
347+
.getConstructor(classOf[SparkConf], classOf[Int])
348+
.newInstance(conf, Int.box(numUsableCores))
349+
.asInstanceOf[MemoryManager]).getOrElse {
350+
SparkSnappyUtils.loadSnappyManager(conf, numUsableCores).getOrElse {
351+
if (useLegacyMemoryManager) {
352+
new StaticMemoryManager(conf, numUsableCores)
353+
} else {
354+
UnifiedMemoryManager(conf, numUsableCores)
355+
}
356+
}
349357
}
350358

351359
val blockManagerPort = if (isDriver) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
* Copyright (c) 2017 SnappyData, Inc. All rights reserved.
19+
*
20+
* Licensed under the Apache License, Version 2.0 (the "License"); you
21+
* may not use this file except in compliance with the License. You
22+
* may obtain a copy of the License at
23+
*
24+
* http://www.apache.org/licenses/LICENSE-2.0
25+
*
26+
* Unless required by applicable law or agreed to in writing, software
27+
* distributed under the License is distributed on an "AS IS" BASIS,
28+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
29+
* implied. See the License for the specific language governing
30+
* permissions and limitations under the License. See accompanying
31+
* LICENSE file.
32+
*/
33+
34+
package org.apache.spark
35+
36+
import org.apache.spark.memory.MemoryManager
37+
import org.apache.spark.util.Utils
38+
39+
40+
object SparkSnappyUtils {
41+
42+
val SNAPPY_UNIFIED_MEMORY_MANAGER_CLASS = "org.apache.spark.memory.SnappyUnifiedMemoryManager"
43+
44+
def loadSnappyManager(conf: SparkConf, numUsableCores: Int): Option[MemoryManager] = {
45+
try {
46+
Some(Utils.classForName(SNAPPY_UNIFIED_MEMORY_MANAGER_CLASS)
47+
.getConstructor(classOf[SparkConf], classOf[Int])
48+
.newInstance(conf, Int.box(numUsableCores))
49+
.asInstanceOf[MemoryManager])
50+
} catch {
51+
case ex: ClassNotFoundException => None
52+
}
53+
}
54+
55+
}

0 commit comments

Comments
 (0)