Apache Spark: Promises and Challenges
Spark isn't perfect, but what is these days? Learn about the good and the bad that Spark has to offer.
Join the DZone community and get the full member experience.Join For Free
if you’re looking for a solution for processing huge chucks of data, then there are lots of options these days. depending on your use case and the type of operations you want to perform on data, you can choose from a variety of data-processing frameworks, such as apache samza, apache storm…, and apache spark. in this article, we’ll focus on the capabilities of apache spark, as it’s the best fitted for both, batch processing and real-time stream processing of data.
apache spark is a full-fledged, data engineering toolkit that enables you to operate on large datasets without worrying about underlying infrastructure. it helps you with data ingestion, querying, processing, and machine learning, while providing an abstraction for building a distributed system.
spark is known for its speed, which is a result of improved implementation of mapreduce that focuses on keeping data in memory instead of persisting data on disk. apache spark provides libraries for three languages, i.e., scala, java, and python.
however, in addition to its great benefits, spark has its issues including complex deployment and scaling, which are also discussed in this article.
[img reference: http://spark.apache.org/ ]
the above diagram shows the different modules included in apache spark. although primarily used to process streaming data, it also includes components that help you perform various operations on data.
spark sql : apache spark comes with an sql interface, meaning you can interact with data using sql queries. the queries are processed by spark’s executor engine.
spark streaming : this module provides a set of apis for writing applications to perform operations on live streams of data. spark streaming divides incoming data streams into micro-batches and allows your application to operate on the data.
mlib : mllib provides a set of apis to run machine learning algorithms on huge datasets.
graphx : this module is particularly useful when you’re working with a dataset that has a lot of connected nodes. its primary benefit is its support for built-in, graph operation algorithms.
apart from its data processing libraries, apache spark comes bundled with a web ui. when running a spark application, a web ui starts on port 4040 where you can see details about your tasks’ executors and statistics. you can also view the time it took for a task to execute by stage. this is very useful when you’re trying get maximum performance.
analytics – spark can be very useful when building real-time analytics from a stream of incoming data. spark can effectively process massive amounts of data from various sources. it supports hdfs, kafka, flume, twitter and zeromq, and custom data sources can also be processed.
trending data – apache spark can be used to calculate trending data from a stream of incoming events. discovering trends at a specific time window becomes extremely easy with apache spark.
internet of things – iot systems generate massive amounts of data, which are pushed to the backend for processing. apache spark enables you to build data pipelines and apply transformations at regular intervals (per minute, hour, week, month, and so on. ). you can also use spark to trigger actions based on a configurable set of events.
machine learning – as spark can process offline data in batches and provides a machine learning library (mlib), machine learning algorithms can easily be applied to your dataset. in addition, you can experiment with different algorithms by applying them on large data sets.combining mlib with spark streaming, you can have a real-time machine learning system.
some spark issues
despite gaining popularity in a short time, spark does have its issues as we will see next.
once you’re done writing your app, you have to deploy it right? that’s where things get a little out of hand. although there are many options for deploying your spark app, the most simple and straightforward approach is standalone deployment. spark supports mesos and yarn, so if you’re not familiar with one of those it can become quite difficult to understand what’s going on. you might face some initial hiccups when bundling dependencies as well. if you don’t do it correctly, the spark app will work in standalone mode but you’ll encounter classpath exceptions when running in cluster mode.
as apache spark is built to process huge chunks of data, monitoring and measuring memory usage is critical. while spark works just fine for normal usage, it has got tons of configuration and should be tuned as per the use case. you’d often hit these limits if configuration is not based on your usage; running apache spark with default settings might not be the best choice. it is strongly recommended to check the documentation section that deals with tuning spark’s memory configuration.
api changes due to frequent releases
apache spark follows a three-month release cycle for 1.x.x release and a three- to four-month cycle for 2.x.x releases. although frequent releases mean developers can push out more features relatively fast, this also means lots of under the hood changes, which in some cases necessitate changes in the api. this can be problematic if you’re not anticipating changes with a new release, and can entail additional overhead to ensure that your spark application is not affected by api change.
half-baked python support
it’s great that apache spark supports scala, java, and python. having support for your favorite language is always preferable. however, python api is not always at a par with java and scala when it comes to the latest features. it takes some time for the python library to catch up with the latest api and features. if you’re planning to use the latest version of spark, you should probably go with scala or java implementation, or at least check whether the feature/api has a python implementation available.
documentation and tutorials or code walkthroughs are extremely important for bringing new users up to the speed. however, in the case of apache spark, although samples and examples are provided along with documentation, the quality and depth leave a lot to be desired. the examples covered in the documentation are too basic and might not give you that initial push to fully realize the potential of apache spark.
while spark is a great framework for building apps to process data, ensure that it’s not overkill for your scale and use case. simpler solutions may exist if you’re looking to process small chunks of data. and, as with all apache products, it’s imperative that you be well aware of the nuts and bolts of your data processing framework to fully harness its power.
Published at DZone with permission of Alon Brody. See the original article here.
Opinions expressed by DZone contributors are their own.