Skip to content
Snippets Groups Projects
Commit b8a0b6ea authored by Aaron Davidson's avatar Aaron Davidson
Browse files

Memoize StorageLevels read from JVM

parent a63d4c7d
No related branches found
No related tags found
No related merge requests found
......@@ -275,7 +275,7 @@ private[spark] object PythonRDD {
* Returns the StorageLevel with the given string name.
* Throws an exception if the name is not a valid StorageLevel.
*/
def getStorageLevel(name: String) : StorageLevel = {
def getStorageLevelByName(name: String) : StorageLevel = {
// In Scala, "val MEMORY_ONLY" produces a public getter by the same name.
val storageLevelGetter = StorageLevel.getClass().getDeclaredMethod(name)
return storageLevelGetter.invoke(StorageLevel).asInstanceOf[StorageLevel]
......
......@@ -281,16 +281,23 @@ class SparkContext(object):
class StorageLevelReader:
"""
Mimics the Scala StorageLevel by directing all attribute requests
Mimics the Scala StorageLevel by delegating all attribute requests
(e.g., StorageLevel.DISK_ONLY) to the JVM for reflection.
Memoizes results to reduce JVM call/memory overheads.
"""
def __init__(self, sc):
self.sc = sc
self.memoized = {}
def __getattr__(self, name):
if name in self.memoized:
return self.memoized[name]
try:
return self.sc._jvm.PythonRDD.getStorageLevel(name)
storageLevel = self.sc._jvm.PythonRDD.getStorageLevelByName(name)
self.memoized[name] = storageLevel
return storageLevel
except:
print "Failed to find StorageLevel:", name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment