Using Stocator to Connect Object Stores to Apache Spark™ 2.0

In a previous blog post, Gil Vernik gave a high-level overview of Stocator, a driver to access data in an object store. After the release of Apache Spark™ 2.0, we tested the process of connecting to object storage and Spark using the Stocator driver — and found that it works seamlessly with Spark 2.0.

This blog will cover the three basic steps to use the Stocator driver in Spark 2.0 to access object storage, in the case that the Spark is not recompiled with Stocator.

First, after building the Stocator project and generating a jar file, make sure the jar file appears in the Spark classpath. You can do this in either of three ways:

  1. Include the package of Stocator in your Spark application using --packages, e.g. $SPARK_HOME/bin/spark-shell --packages
  2. Specify the path to the jar file as the --jars argument, for example when using spark-submit or pyspark.
  3. Specify the path to the jar file as the two parameters, spark.driver.extraClassPath and
    spark.executor.extraClassPath in the $SPARK_HOME/conf/spark-defaults.conf file.

Second, you'll need to configure several parameters for Spark 2.0. Here again, you have two options:

  1. Use the hadoopConfiguration() method of SparkContext in the application.
  2. Add the dependency to Stocator in conf/core-site.xml of Hadoop.

For example, if you're using the Bluemix Object Service and thus the SERVICE_NAME is bmv3, the parameters are...

"fs.swift2d.impl" : ""
"fs.swift2d.service.bmv3.auth.url" : ""
"fs.swift2d.service.bmv3.public" : "true"
"fs.swift2d.service.bmv3.tenant" : "projectId on Bluemix"
"fs.swift2d.service.bmv3.password" : "password on Bluemix"
"fs.swift2d.service.bmv3.username" : "userId on Bluemix"
"fs.swift2d.service.bmv3.auth.method" : "keystoneV3"
"fs.swift2d.service.bmv3.region" : "dallas"

Third, provide the target object path as swift2d://CONTAINER.SERVICE/OBJECT, for instance CONTAINER could be test and OBJECT could be data1.json. SERVICE would be bmv3 if you're using Bluemix. So the object’s path should be swift2d://test.bmv3/data1.json.

We also ran a basic comparison of object access performance between the Hadoop Openstack and the Stocator driver via Spark 2.0. As mentioned in Gil’s blog, here again we found that Stocator has a performance gain when writing data over the Hadoop Openstack driver.

For more details about the Stocator project on Git, see:

For more about IBM Bluemix Object Storage services, see:

For more about Stocator in spark-packages, see:

Spark Technology Center


Subscribe to the Spark Technology Center newsletter for the latest thought leadership in Apache Spark™, machine learning and open source.



You Might Also Enjoy