April 10th, 2015

Brian O’Neill, Chief Technology Officer at Health Market Science
Brian is Chief Technology Officer at Health Market Science (HMS) where he heads development of their data management and analytics platform, powered by Storm and Cassandra. Brian won InfoWorld’s Technology Leadership award in 2013 and authored, Storm: Blueprints for Realtime Computation. He has a number of patents and holds a B.S. in C.S. from Brown University.

Over a year ago, I did a post on Spark and Cassandra. At the time, Calliope was your best best. Since then, Spark has exploded in popularity.

Check out this Google Trends chart. That’s quite a hockey stick for Spark.
Also notice their github project, which has almost 500 contributors and 3000 forks!!

Datastax is riding that curve. And just in the time since my last post, Datastax developed and released their own spark-cassandra connector.

I am putting together some materials for Philly Tech Week, where I’ll be presenting on Cassandra development, so I thought I would give it a spin to see how things have evolved. Here is a follow-along preview of the Spark piece of what I’ll be presenting.

First, get Spark running:

Download Spark 1.2.1 (this is the version that works with the latest Datastax connector)

Next, unpack it and build it. (mvn install)

And that is the first thing I noticed…

Look at all these new cool toys? GraphX? SQL? Kafka? In my last post, I was using Spark 0.8.1. I took a look at the 0.8 branch on github and sure enough, all of this stuff was built just in the last year! It is crazy what momentum can do.

After you’ve built spark, go into the conf directory and copy the template environment file.

Then, edit that file and add a line to configure the master IP/bind interface:

(If you don’t set the IP, the master may bind to the wrong interface, and your application won’t be able to connect, which is what happened to me initially)

Next, launch the master: (It gives you the path to the logs, which I recommend tailing)

In the logs, you should see:

Go hit that WebUI at http://localhost:8080.

Second, get yourself some workers:

Spark has its own concept of workers. To start one, run the following command:

After a few seconds, you should see the following:

You can refresh the MasterWebUI and you should see the worker.

Third, sling some code:

This go around, I wanted to use Java instead of Scala. (Sorry, but I’m still not on the Scala bandwagon, it feels like Java 8 is giving me what I needed with respect to functions and lambdas)
I found this Datastax post:
Which lead me to this code:

Kudos to Jacek, but that gist is directed at an old version of Spark. It also rolled everything into a single class, (which means it doesn’t help you in a real-world situation where you have lots of classes and dependencies) In the end, I decided to update my quick start project so everyone can get up and running quickly.

Go clone this:

Build with maven:

Then, have a look at the run.sh. This actually submits the job to the Spark cluster (single node in our case). The contents of that script are as follows:

The –class parameter tells Spark which class to execute. The –master parameter is the url that you see at the top of MasterWebUI, and tells spark to which master it should submit the job. The jar file is the result of the build, which is a fat jar that includes the job (courtesy of the maven assembly plugin). The last two parameters are the args for the program. Spark passes those into the JavaDemo class. After you run this, you should see the job process…

I’ll go into the details of the example in my next post.
Or you can just come to my presentation at Philly Tech Week. =)