title: In Spark is it good practice to persist after an action?
body: <p>Given this example;</p>
  
  <pre><code>    val someRDD = firstRDD.flatMap{ case(x,y) =&gt; SomeFunc(y)}
      val oneRDD = someRDD.reduceByKey(_+_)
      oneRDD.saveAsNewAPIHadoopFile("dir/to/write/to", classOf[Text], classOf[Text], classOf[TextOutputFormat[Text, Text]])
  </code></pre>
  
  <p>Which would be better to do?</p>
  
  <pre><code>    val someRDD = firstRDD.flatMap{ case(x,y) =&gt; SomeFunc(y)}.persist(storage.StorageLevel.MEMORY_AND_DISK_SER)
      val oneRDD = someRDD.reduceByKey(_+_)
      oneRDD.saveAsNewAPIHadoopFile("dir/to/write/to", classOf[Text], classOf[Text], classOf[TextOutputFormat[Text, Text]])
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>    val someRDD = firstRDD.flatMap{ case(x,y) =&gt; SomeFunc(y)}.persist(storage.StorageLevel.MEMORY_AND_DISK_SER)
      val oneRDD = someRDD.reduceByKey(_+_).persist(storage.StorageLevel.MEMORY_AND_DISK_SER)
      oneRDD.saveAsNewAPIHadoopFile("dir/to/write/to", classOf[Text], classOf[Text], classOf[TextOutputFormat[Text, Text]])
  </code></pre>
  
  <p>or something else? </p>
  
  <p>I see that it is good to persist when you are performing <strong>more than one action on the same RDD</strong>.</p>
  
  <p>example being;</p>
  
  <pre><code>val newRDD = context.parallelize(0 until numMappers, numPartitions).persist(storage.StorageLevel.MEMORY_AND_DISK_SER)  #persisted bc there are two follow on actions preformed on it.
  newRDD.count() #same RDD
  newRDD.saveAsNewAPIHadoopFile() #same RDD
  ...other actions etc.
  </code></pre>
  
  <p>Here it is only one RDD and two actions in line. Should I persist as all. </p>