spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andras Nemeth <>
Subject Re: Spark unit testing best practices
Date Fri, 16 May 2014 11:06:17 GMT
Thanks for the answers!

On a concrete example, here is what I did to test my (wrong :) ) hypothesis
before writing my email:
class SomethingNotSerializable {
  def process(a: Int): Int = 2 *a
object NonSerializableClosure extends App {
  val sc = new spark.SparkContext(
  val sns = new SomethingNotSerializable
            .reduce(_ + _))

This program prints 12 correctly. If I change "local" to point to my spark
master the code fails on the worker with a NullPointerException in the line

But I have to say that my original assumption that this is a serialization
issue was wrong, as adding extends Serializable to my class does _not_
solve the problem in non-local mode. This seems to be something more
convoluted, the sns reference in my closure is probably not stored by
value, instead I guess it's a by name reference to
"NonSerializableClosure.sns". I'm a bit surprised why this results in a
NullPointerException instead of some error when trying to run the
constructor of this object on the worker. Maybe something to do with the
magic of App.

Anyways, while this is indeed an example of an error that doesn't manifest
in local mode, I guess it turns out to be convoluted enough that we won't
worry about it for now, use local in tests, and I'll ask again if we see
some actual prod vs unittest problems.

On using local-cluster, this does sound like exactly what I had in mind.
But it doesn't seem to work for application developers. It seems to assume
you are running within a spark build (it fails while looking for the file
bin/ So maybe that's a reason it's not documented...


On Wed, May 14, 2014 at 7:58 PM, Mark Hamstra <>wrote:

> Local mode does serDe, so it should expose serialization problems.
> On Wed, May 14, 2014 at 10:53 AM, Philip Ogren <>wrote:
>> Have you actually found this to be true?  I have found Spark local mode
>> to be quite good about blowing up if there is something non-serializable
>> and so my unit tests have been great for detecting this.  I have never seen
>> something that worked in local mode that didn't work on the cluster because
>> of different serialization requirements between the two.  Perhaps it is
>> different when using Kryo....
>> On 05/14/2014 04:34 AM, Andras Nemeth wrote:
>>> E.g. if I accidentally use a closure which has something
>>> non-serializable in it, then my test will happily succeed in local mode but
>>> go down in flames on a real cluster.

View raw message