Force Partitioner to use entire entry of PairRDD as key

2016-02-22 Thread jluan
I was wondering, is there a way to force something like the hash partitioner
to use the entire entry of a PairRDD as a hash rather than just the key?

For Example, if we have an RDD with values: PairRDD = [(1,4), (1, 3), (2,
3), (2,5), (2, 10)]. Rather than using keys 1 and 2, can we force the
partitioner to hash the entire tuple such as (1,4)?



--
View this message in context: 
http://apache-spark-user-list.1001560.n3.nabble.com/Force-Partitioner-to-use-entire-entry-of-PairRDD-as-key-tp26299.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@spark.apache.org
For additional commands, e-mail: user-h...@spark.apache.org



[MLLIB] Best way to extract RandomForest decision splits

2016-02-10 Thread jluan
I've trained a RandomForest classifier where I can print my model's decisions
using model.toDebugString

However I was wondering if there's a way to extract tree programmatically by
traversing the nodes or in some other way such that I can write my own
decision file rather than just a debug string.



--
View this message in context: 
http://apache-spark-user-list.1001560.n3.nabble.com/MLLIB-Best-way-to-extract-RandomForest-decision-splits-tp26201.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@spark.apache.org
For additional commands, e-mail: user-h...@spark.apache.org



RangePartitioning skewed data

2016-01-25 Thread jluan
Lets say I have a dataset of (K,V) where the keys are really skewed:

myDataRDD = 
[(8, 1), (8, 13), (1,1), (2,4)]
[(8, 12), (8, 15), (8, 7), (8, 6), (8, 4), (8, 3), (8, 4), (10,2)]

If I applied a RangePartitioner to this set of data, say val rangePart = new
RangePartitioner(4, myDataRDD) and then repartitioned the data, would I be
able to get back 4 equally distributed partitions where Key=8 would be split
across multiple partitions, or would all the 8 keys end up in one partition?

Also, does myDataRDD need to be sorted in order to correctly create the
range partitioner? My research shows this may be the case.





--
View this message in context: 
http://apache-spark-user-list.1001560.n3.nabble.com/RangePartitioning-skewed-data-tp26055.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@spark.apache.org
For additional commands, e-mail: user-h...@spark.apache.org



how garbage collection works on parallelize

2016-01-08 Thread jluan
Hi,

I am curious about garbage collect on an object which gets parallelized. Say
if we have a really large array (say 40GB in ram) that we want to
parallelize across our machines. 

I have the following function:

def doSomething(): RDD[Double] = {
val reallyBigArray = Array[Double[(some really big value)
sc.parallelize(reallyBigArray)
}

Theoretically, will reallyBigArray be marked for GC? Or will reallyBigArray
not be GC'd because parallelize somehow has a reference on reallyBigArray?




--
View this message in context: 
http://apache-spark-user-list.1001560.n3.nabble.com/how-garbage-collection-works-on-parallelize-tp25926.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@spark.apache.org
For additional commands, e-mail: user-h...@spark.apache.org



Re: Spark ClosureCleaner or java serializer OOM when trying to grow

2015-09-24 Thread jluan
With spark.serializer.objectStreamReset set to 1, I ran a sample scala test
code which still seems to be crashing at the same place. If someone could
verify this independently, I would greatly appreciate it.

Scala Code:
--
import scala.util.Random
import scala.collection.mutable.ArrayBuffer

import org.apache.spark.mllib.tree.RandomForest
import org.apache.spark.mllib.tree.model.RandomForestModel
import org.apache.spark.mllib.util.MLUtils

import org.apache.spark.mllib.linalg.Vectors
import org.apache.spark.mllib.regression.LabeledPoint

val r = Random

var size = 1500
var count = 3000
val indptr = (1 to size by size/count).toArray
val data = Seq.fill(count)(r.nextDouble()).toArray

var dset = ArrayBuffer[LabeledPoint]()
for (i <- 1 to 10) {
dset += LabeledPoint(r.nextInt(2), Vectors.sparse(size, indptr, data));
}

val distData = sc.parallelize(dset)
val splits = distData.randomSplit(Array(0.7, 0.3))
val (trainingData, testData) = (splits(0), splits(1))

// Train a RandomForest model.
//  Empty categoricalFeaturesInfo indicates all features are continuous.
val numClasses = 2
val categoricalFeaturesInfo = Map[Int, Int]()
val numTrees = 3 // Use more in practice.
val featureSubsetStrategy = "auto" // Let the algorithm choose.
val impurity = "gini"
val maxDepth = 4
val maxBins = 32

val model = RandomForest.trainClassifier(trainingData, numClasses,
categoricalFeaturesInfo,
  numTrees, featureSubsetStrategy, impurity, maxDepth, maxBins)



--
View this message in context: 
http://apache-spark-user-list.1001560.n3.nabble.com/Spark-ClosureCleaner-or-java-serializer-OOM-when-trying-to-grow-tp24796p24818.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@spark.apache.org
For additional commands, e-mail: user-h...@spark.apache.org



Spark ClosureCleaner or java serializer OOM when trying to grow

2015-09-23 Thread jluan
I have been stuck on this problem for the last few days:

I am attempting to run random forest from MLLIB, it gets through most of it,
but breaks when doing a mapPartition operation. The following stack trace is
shown:

: An error occurred while calling o94.trainRandomForestModel.
: java.lang.OutOfMemoryError
at
java.io.ByteArrayOutputStream.hugeCapacity(ByteArrayOutputStream.java:123)
at
java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:117)
at
java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at
java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
at
java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
at
java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1786)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1189)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at
org.apache.spark.serializer.JavaSerializationStream.writeObject(JavaSerializer.scala:44)
at
org.apache.spark.serializer.JavaSerializerInstance.serialize(JavaSerializer.scala:84)
at
org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:301)
at
org.apache.spark.util.ClosureCleaner$.org$apache$spark$util$ClosureCleaner$$clean(ClosureCleaner.scala:294)
at org.apache.spark.util.ClosureCleaner$.clean(ClosureCleaner.scala:122)
at org.apache.spark.SparkContext.clean(SparkContext.scala:2021)
at
org.apache.spark.rdd.RDD$$anonfun$mapPartitions$1.apply(RDD.scala:703)
at
org.apache.spark.rdd.RDD$$anonfun$mapPartitions$1.apply(RDD.scala:702)
at
org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:147)
at
org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:108)
at org.apache.spark.rdd.RDD.withScope(RDD.scala:306)
at org.apache.spark.rdd.RDD.mapPartitions(RDD.scala:702)
at
org.apache.spark.mllib.tree.DecisionTree$.findBestSplits(DecisionTree.scala:625)
at
org.apache.spark.mllib.tree.RandomForest.run(RandomForest.scala:235)
at
org.apache.spark.mllib.tree.RandomForest$.trainClassifier(RandomForest.scala:291)
at
org.apache.spark.mllib.api.python.PythonMLLibAPI.trainRandomForestModel(PythonMLLibAPI.scala:742)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
at
py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)
at py4j.Gateway.invoke(Gateway.java:259)
at
py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:207)
at java.lang.Thread.run(Thread.java:745)

It seems to me that it's trying to serialize the mapPartitions closure, but
runs out of space doing so. However I don't understand how it could run out
of space when I gave the driver ~190GB for a file that's 45MB.

I have a cluster setup on AWS such that my master is a r3.8xlarge along with
two r3.4xlarge workers. I have the following configurations:

spark version: 1.5.0
---
spark.executor.memory 32000m
spark.driver.memory 23m
spark.driver.cores 10
spark.executor.cores 5
spark.executor.instances 17
spark.driver.maxResultSize 0
spark.storage.safetyFraction 1
spark.storage.memoryFraction 0.9
spark.storage.shuffleFraction 0.05
spark.default.parallelism 128

The master machine has approximately 240 GB of ram and each worker has about
120GB of ram. 

I load in a relatively tiny RDD of MLLIB LabeledPoint objects, with each
holding sparse vectors inside. This RDD has a total size of roughly 45MB. My
sparse vector has a total length of ~15 million while only about 3000 or so
are non-zeros.






--
View this message in context: 
http://apache-spark-user-list.1001560.n3.nabble.com/Spark-ClosureCleaner-or-java-serializer-OOM-when-trying-to-grow-tp24796.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: user-unsubscr...@spark.apache.org
For additional commands, e-mail: user-h...@spark.apache.org



DecisionTree hangs, then crashes

2015-09-17 Thread jluan
See my stack overflow questions for better formatted info: 
http://stackoverflow.com/questions/32621267/spark-1-5-0-hangs-running-randomforest

  

I am trying to run a basic decision tree from MLLIB. My spark version is
1.4.0. My configuration is: 
EC2 r3.4xlarge (1 master, 2 workers)
146.6 GB Total

spark.executor.memory   10m
spark.driver.memory 9m
spark.driver.maxResultSize 0
spark.storage.memoryFraction 0.6
spark.default.parallelism 64


I have loaded a test dataset of LabeledPoint values, with each LabeledPoint
containing a SparseVector features. My LabeledPoint object looks like this:
LabeledPoint(0.0, (1080963,[44673,64508,65588,122081,306819,306820,382530
...], [1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0 ...]))

Additional information on each *RDD item*:
>>> d = data.first()
>>> d.label
0.0
>>> d.features.size
1080963
>>> len(d.features.values)
2286

My *model training* is very standard:
(trainingData, testData) = data.randomSplit([0.7, 0.3])
model = RandomForest.trainClassifier(trainingData, numClasses=2,
categoricalFeaturesInfo={},
 numTrees=3,
featureSubsetStrategy="auto",
 impurity='gini', maxDepth=4,
maxBins=32)


My *Error trace* is as follows:
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_4_piece0
on 10.0.28.233:38432 in memory (size: 4.4 KB, free: 45.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_4_piece0
on 10.0.28.28:58416 in memory (size: 4.4 KB, free: 50.5 GB)
15/09/17 19:36:13 INFO storage.BlockManager: Removing RDD 10
15/09/17 19:36:13 INFO spark.ContextCleaner: Cleaned RDD 10
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_3_piece0
on 10.0.28.233:38432 in memory (size: 4.2 KB, free: 45.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_3_piece0
on 10.0.28.28:58416 in memory (size: 4.2 KB, free: 50.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_2_piece0
on 10.0.28.233:38432 in memory (size: 3.7 KB, free: 45.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_2_piece0
on 10.0.28.28:58416 in memory (size: 3.7 KB, free: 50.5 GB)
15/09/17 19:36:13 INFO storage.BlockManagerInfo: Removed broadcast_2_piece0
on 10.0.28.31:56554 in memory (size: 3.7 KB, free: 50.5 GB)
15/09/17 20:33:43 INFO rdd.MapPartitionsRDD: Removing RDD 28 from
persistence list
15/09/17 20:33:43 INFO storage.BlockManager: Removing RDD 28
Traceback (most recent call last):
  File "", line 1, in 
  File "random_forest_spark.py", line 144, in trainModel
impurity='gini', maxDepth=4, maxBins=32)
  File "/root/spark/python/pyspark/mllib/tree.py", line 352, in
trainClassifier
maxDepth, maxBins, seed)
  File "/root/spark/python/pyspark/mllib/tree.py", line 270, in _train
maxDepth, maxBins, seed)
  File "/root/spark/python/pyspark/mllib/common.py", line 128, in
callMLlibFunc
return callJavaFunc(sc, api, *args)
  File "/root/spark/python/pyspark/mllib/common.py", line 121, in
callJavaFunc
return _java2py(sc, func(*args))
  File "/root/spark/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py",
line 538, in __call__
  File "/root/spark/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py", line
300, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling
o104.trainRandomForestModel.
: java.lang.OutOfMemoryError
at
java.io.ByteArrayOutputStream.hugeCapacity(ByteArrayOutputStream.java:123)
at
java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:117)
at
java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at
java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
at
java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1876)
at
java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1785)
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1188)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
at
org.apache.spark.serializer.JavaSerializationStream.writeObject(JavaSerializer.scala:44)
at
org.apache.spark.serializer.JavaSerializerInstance.serialize(JavaSerializer.scala:81)
at
org.apache.spark.util.ClosureCleaner$.ensureSerializable(ClosureCleaner.scala:312)
at
org.apache.spark.util.ClosureCleaner$.org$apache$spark$util$ClosureCleaner$$clean(ClosureCleaner.scala:305)
at
org.apache.spark.util.ClosureCleaner$.clean(ClosureCleaner.scala:132)
at org.apache.spark.SparkContext.clean(SparkContext.scala:1891)
at org.apache.spark.rdd.RDD$$anonfun$map$1.apply(RDD.scala:294)
at org.apache.spark.rdd.RDD$$anonfun$map$1.apply(RDD.scala:293)
at
org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:148)
at