Friday, 3 April 2015

Why,What and how Spark in Real Time.

Next BigThing around Bigdata Model is SPARK???...Yes..There is No doubt around this question.

Why??

Why do we need Another Big Data Processing Engine Like Spark??

Computation of the large data across cluster of commodity machines, essentially involves a good amount of network I/O and disk I/O for each of the Map and Reduce stages and 90% of the time is being spent on I/O, rather than actual computation, thereby making it a high latency system. Hadoop is a batch processing system of very large data, often of the order of several terabytes to petabytes of data. Number of hard disks required to store 40PB data, if stacked one after another, the height will be double the height of empire state building !!
Although map-reduce is a great computing paradigm for distributed programming, it’s not easy to write program in map-reduce. So some higher level abstraction was required and that gave birth to Hive, which is a declarative language and Pig (Pig latin) which is a scripting framework, both work on top of map-reduce. Any job written on Hive or Pig essentially gets converted to a map-reduce job. That does not solve high latency problem though. Imagine cases where you need to answer within a bounded period in time, otherwise the purpose of analysis is lost, such as fraud detection, spam analysis, face detection etc. Many algorithms to do this kind of work or machine learning or computing page rank etc are inherently multipass algorithm or iterative in nature. This is again another difficulty with hadoop to perform iterative operations.
So we needed a low latency distributed system where iterative algorithms can be run with ease. Welcome to the UC Berkeley research project called SPARK that essentially solves these problems. SPARK is part of Berkeley Distributed Analytics Stack (BDAS) developed at AmpLab. Other parts of the stack are Mesos and Shark (Others are BlinkDB and MLbase – not yet released). Mesos is a cluster Manager and Shark is Hive on Spark.
 Some of the beautiful things in SPARK, are,

1.Speed. Shared in-memory immutable dataset, greatly reduces network and disk I/O.
2.Consistency is free, because of using immutable dataset.
3.local mode: where things can be tried out in a single box (even a Windows machine). Once you are comfortable, you can try this in a cluster setup. This speeds up the learning curve.
4.REPL: Ability to try things from command line in a interactive way. This is a great way to start without writing a single line of code.
5.Primary language is Scala, although it supports Java and python. Scala is a great language that combines functional programming and OOP. It’s a JVM language and can utilize existing Java libraries.
6.Fault tolerant without replication (through RDDs) and fast recovery time. Self healing – works under the hood in case of a failure.
7.Interoperability: It’s ability to talk to HDFS, S3, EC2, MPI, even local filesystem.
8.Not only map-reduce. Spark’s programming model includes mutable accumulators and broadcast variables and immutable RDDs, along with2 types of operations, lazy Transformations and Actions. Transformations, which create a new dataset from an existing one, and actions, which return a value to the driver program after running a computation on the dataset.
9.Persisting or caching a dataset in memory across operations. These significantly increases the speed of subsequent operations on the dataset.
10.Easy deployability in the Cloud like amazon web services.
  


Hadoop integration: Spark can work with files stored in HDFS, an important feature given the amount of investment in the Hadoop Ecosystem. Getting Spark to work with MapR is straightforward.

The Spark interactive Shell: Spark is written in Scala, and has it’s own version of the Scala interpreter. I find this extremely convenient for testing short snippets of code.

The Spark Analytic Suite:
Spark comes with tools for interactive query analysis (Shark), large-scale graph processing and analysis (Bagel), and real-time analysis (Spark Streaming). Rather than having to mix and match a set of tools (e.g., Hive, Hadoop, Mahout, S4/Storm), you only have to learn one programming paradigm. For SQL enthusiasts, the added bonus is that Shark tends to run faster than Hive. If you want to run Spark in the cloud, there are a set of EC2 scripts available.

Resilient Distributed Data sets (RDD’s):
RDD’s are distributed objects that can be cached in-memory, across a cluster of compute nodes. They are the fundamental data objects used in Spark. The crucial thing is that fault-tolerance is built-in: RDD’s are automatically rebuilt if something goes wrong. If you need to test something out, RDD’s can even be used interactively from the Spark interactive shell.

Distributed Operators:
Aside from Map and Reduce, there are many other operators one can use on RDD’s. Once I familiarized myself with how they work, I began converting a few basic machine-learning and data processing algorithms into this framework.

Once you get past the learning curve … iterative programs
It takes some effort to become productive in anything, Spark is no exception. I was a complete Scala newbie so I first had to get comfortable with a new language (apparently, they like underscores – see here, here, and here). Beyond Scala one can use Shark (“SQL” on Spark), and relatively new Java and Python API’s.


It’s already used in production.
Spark replaces Map Reduce:
Spark can use HDFS.
Spark can use YARN.
Spark can be deployed, but not fully monitored or Managed.
Spark enables Analytics workflows.
Spark uses memory differently and efficiently 
Spark’s results are jaw-droopingly impressive.

HOW??

When an interesting piece of big data technology gets introduced, early1 adopters tend to focus on technical features and capabilities. Applications get built as companies develop confidence that it’s reliable and that it really scales to large data volumes. That seems to be where Spark is today.

Data processing workflows: ETL and Data Wrangling
Many companies rely on a wide variety of data sources for their analytic products. That means cleaning, transforming, and fusing (unstructured) external data with internal data sources. Many companies – particularly startups – use Spark for these types of data processing workflows. There are even companies that have created simple user interfaces that open up batch data processing tasks to non-programmers.
Advanced analytics
From the outset users were attracted to Spark for its speed (compared to Hadoop) and suitability for handling the type of (iterative) computations common in advanced analytics (machine-learning, statistics). Very early on companies and users wrote their own Spark libraries for things like regression, clustering and classification. These tools and libraries have been applied to problems in online advertising and marketing (reinforcement learning), finance, fraud detection, and even scientific research (neuroscience). The good news is that these types of applications are going to get easier to build: Spark developers have responded by developing libraries for machine-learning (MLlib) and graph analytics (GraphX).
Stream Processing
By most accounts Spark and Shark are the most popular components of BDAS. Right behind them are Spark Streaming (realtime processing) andPySpark (Spark’s Python API). One of the main selling points of Spark Streaming is programmer productivity: the same code used for batch processing can, with minor tweaks, be used for realtime computations. This is turning out to be an important feature. I’m coming across many more companies who are using Spark Streaming for realtime data processing. Applications include stream mining, (near) realtime scoring2 of analytic models, recommendations and targeting, personalization, and network optimization. CloudPhysics has been using Spark and Spark Streaming to detect patterns and anomalies in massive amounts of machine data.

Business Intelligence and Visual Analytics
With performance within range of MPP databases, open source SQL-on-Hadoop solutions Shark and Impala are gaining traction3. Many companies start out by using Shark and BlinkDB for interactive SQL analysis. Some startups developed custom, interactive dashboards that are powered in realtime by Shark and Spark. Beyond static reports and query analysis, companies are beginning to use visual analysis tools like Tableau in conjunction with Shark. This opens up terabytes of data to tools that are already popular among business users. More recently, startup ClearStory built a platform that lets users quickly fuse together many data sources and collaboratively produce interactive visualizations. The ClearStory platform uses Spark, Shark, and other BDAS components.
Unified Analytic Platform
Having a single programming model that works across many sets of problems is appealing. Add to that the convenience of having a set of analytic engines (Shark, BlinkDB, MLlib, GraphX) in different stages of maturity. This has allowed some companies to use Spark for applications that cut across different workloads (offline, near realtime, and realtime analytics).


No comments:

Post a Comment