title: Using Futures within Spark
body: <p>A Spark job makes a remote web service for every element in an RDD. A simple implementation might look something like this:</p>
  
  <pre><code>def webServiceCall(url: String) = scala.io.Source.fromURL(url).mkString
  rdd2 = rdd1.map(x =&gt; webServiceCall(x.field1))
  </code></pre>
  
  <p>(The above example has been kept simple and does not handle timeouts).</p>
  
  <p>There is no interdependency between any of the results for different elements of the RDD. </p>
  
  <p>Would the above be improved by using Futures to optimise performance by making parallel calls to the web service for each element of the RDD? Or does Spark itself have that level of optimization built in, so that it will run the operations on each element in the RDD in parallel?</p>
  
  <p>If the above can be optimized by using Futures, does anyone have some code examples showing the correct way to use Futures within a function passed to a Spark RDD.</p>
  
  <p>Thanks</p>