Apache Spark Explained

Apache Spark
Author:Matei Zaharia
Developer:Apache Spark
Released:
Latest Release Version:3.5.0 (Scala 2.13)
Operating System:Microsoft Windows, macOS, Linux
Programming Language:Scala[1]
Genre:Data analytics, machine learning algorithms
License:Apache License 2.0
Language:Scala, Java, SQL, Python, R, C#, F#

Apache Spark is an open-source unified analytics engine for large-scale data processing. Spark provides an interface for programming clusters with implicit data parallelism and fault tolerance. Originally developed at the University of California, Berkeley's AMPLab, the Spark codebase was later donated to the Apache Software Foundation, which has maintained it since.

Overview

Apache Spark has its architectural foundation in the resilient distributed dataset (RDD), a read-only multiset of data items distributed over a cluster of machines, that is maintained in a fault-tolerant way.[2] The Dataframe API was released as an abstraction on top of the RDD, followed by the Dataset API. In Spark 1.x, the RDD was the primary application programming interface (API), but as of Spark 2.x use of the Dataset API is encouraged[3] even though the RDD API is not deprecated.[4] [5] The RDD technology still underlies the Dataset API.[6] [7]

Spark and its RDDs were developed in 2012 in response to limitations in the MapReduce cluster computing paradigm, which forces a particular linear dataflow structure on distributed programs: MapReduce programs read input data from disk, map a function across the data, reduce the results of the map, and store reduction results on disk. Spark's RDDs function as a working set for distributed programs that offers a (deliberately) restricted form of distributed shared memory.[8]

Inside Apache Spark the workflow is managed as a directed acyclic graph (DAG). Nodes represent RDDs while edges represent the operations on the RDDs.

Spark facilitates the implementation of both iterative algorithms, which visit their data set multiple times in a loop, and interactive/exploratory data analysis, i.e., the repeated database-style querying of data. The latency of such applications may be reduced by several orders of magnitude compared to Apache Hadoop MapReduce implementation.[9] Among the class of iterative algorithms are the training algorithms for machine learning systems, which formed the initial impetus for developing Apache Spark.[10]

Apache Spark requires a cluster manager and a distributed storage system. For cluster management, Spark supports standalone (native Spark cluster, where you can launch a cluster either manually or use the launch scripts provided by the install package. It is also possible to run these daemons on a single machine for testing), Hadoop YARN, Apache Mesos or Kubernetes.[11] For distributed storage, Spark can interface with a wide variety, including Alluxio, Hadoop Distributed File System (HDFS),[12] MapR File System (MapR-FS),[13] Cassandra,[14] OpenStack Swift, Amazon S3, Kudu, Lustre file system,[15] or a custom solution can be implemented. Spark also supports a pseudo-distributed local mode, usually used only for development or testing purposes, where distributed storage is not required and the local file system can be used instead; in such a scenario, Spark is run on a single machine with one executor per CPU core.

Spark Core

Spark Core is the foundation of the overall project. It provides distributed task dispatching, scheduling, and basic I/O functionalities, exposed through an application programming interface (for Java, Python, Scala, .NET and R) centered on the RDD abstraction (the Java API is available for other JVM languages, but is also usable for some other non-JVM languages that can connect to the JVM, such as Julia[16]). This interface mirrors a functional/higher-order model of programming: a "driver" program invokes parallel operations such as map, filter or reduce on an RDD by passing a function to Spark, which then schedules the function's execution in parallel on the cluster. These operations, and additional ones such as joins, take RDDs as input and produce new RDDs. RDDs are immutable and their operations are lazy; fault-tolerance is achieved by keeping track of the "lineage" of each RDD (the sequence of operations that produced it) so that it can be reconstructed in the case of data loss. RDDs can contain any type of Python, .NET, Java, or Scala objects.

Besides the RDD-oriented functional style of programming, Spark provides two restricted forms of shared variables: broadcast variables reference read-only data that needs to be available on all nodes, while accumulators can be used to program reductions in an imperative style.

A typical example of RDD-centric functional programming is the following Scala program that computes the frequencies of all words occurring in a set of text files and prints the most common ones. Each, (a variant of) and takes an anonymous function that performs a simple operation on a single data item (or a pair of items), and applies its argument to transform an RDD into a new RDD.

val conf = new SparkConf.setAppName("wiki_test") // create a spark config objectval sc = new SparkContext(conf) // Create a spark contextval data = sc.textFile("/path/to/somedir") // Read files from "somedir" into an RDD of (filename, content) pairs.val tokens = data.flatMap(_.split(" ")) // Split each file into a list of tokens (words).val wordFreq = tokens.map((_, 1)).reduceByKey(_ + _) // Add a count of one to each token, then sum the counts per word type.wordFreq.sortBy(s => -s._2).map(x => (x._2, x._1)).top(10) // Get the top 10 words. Swap word and count to sort by count.

Spark SQL

Spark SQL is a component on top of Spark Core that introduced a data abstraction called DataFrames, which provides support for structured and semi-structured data. Spark SQL provides a domain-specific language (DSL) to manipulate DataFrames in Scala, Java, Python or .NET. It also provides SQL language support, with command-line interfaces and ODBC/JDBC server. Although DataFrames lack the compile-time type-checking afforded by RDDs, as of Spark 2.0, the strongly typed DataSet is fully supported by Spark SQL as well.

import org.apache.spark.sql.SparkSession

val url = "jdbc:mysql://yourIP:yourPort/test?user=yourUsername;password=yourPassword" // URL for your database server.val spark = SparkSession.builder.getOrCreate // Create a Spark session object

val df = spark .read .format("jdbc") .option("url", url) .option("dbtable", "people") .load

df.printSchema // Looks at the schema of this DataFrame.val countsByAge = df.groupBy("age").count // Counts people by age

//or alternatively via SQL://df.createOrReplaceTempView("people")//val countsByAge = spark.sql("SELECT age, count(*) FROM people GROUP BY age")

Spark Streaming

Spark Streaming uses Spark Core's fast scheduling capability to perform streaming analytics. It ingests data in mini-batches and performs RDD transformations on those mini-batches of data. This design enables the same set of application code written for batch analytics to be used in streaming analytics, thus facilitating easy implementation of lambda architecture.[17] [18] However, this convenience comes with the penalty of latency equal to the mini-batch duration. Other streaming data engines that process event by event rather than in mini-batches include Storm and the streaming component of Flink.[19] Spark Streaming has support built-in to consume from Kafka, Flume, Twitter, ZeroMQ, Kinesis, and TCP/IP sockets.[20]

In Spark 2.x, a separate technology based on Datasets, called Structured Streaming, that has a higher-level interface is also provided to support streaming.[21]

Spark can be deployed in a traditional on-premises data center as well as in the cloud.[22]

MLlib Machine Learning Library

Spark MLlib is a distributed machine-learning framework on top of Spark Core that, due in large part to the distributed memory-based Spark architecture, is as much as nine times as fast as the disk-based implementation used by Apache Mahout (according to benchmarks done by the MLlib developers against the alternating least squares (ALS) implementations, and before Mahout itself gained a Spark interface), and scales better than Vowpal Wabbit.[23] Many common machine learning and statistical algorithms have been implemented and are shipped with MLlib which simplifies large scale machine learning pipelines, including:

GraphX

GraphX is a distributed graph-processing framework on top of Apache Spark. Because it is based on RDDs, which are immutable, graphs are immutable and thus GraphX is unsuitable for graphs that need to be updated, let alone in a transactional manner like a graph database.[25] GraphX provides two separate APIs for implementation of massively parallel algorithms (such as PageRank): a Pregel abstraction, and a more general MapReduce-style API.[26] Unlike its predecessor Bagel, which was formally deprecated in Spark 1.6, GraphX has full support for property graphs (graphs where properties can be attached to edges and vertices).[27]

Like Apache Spark, GraphX initially started as a research project at UC Berkeley's AMPLab and Databricks, and was later donated to the Apache Software Foundation and the Spark project.[28]

Language support

Apache Spark has built-in support for Scala, Java, SQL, R, and Python with 3rd party support for the .NET CLR,[29] Julia,[30] and more.

History

Spark was initially started by Matei Zaharia at UC Berkeley's AMPLab in 2009, and open sourced in 2010 under a BSD license.[31]

In 2013, the project was donated to the Apache Software Foundation and switched its license to Apache 2.0. In February 2014, Spark became a Top-Level Apache Project.[32]

In November 2014, Spark founder M. Zaharia's company Databricks set a new world record in large scale sorting using Spark.[33]

Spark had in excess of 1000 contributors in 2015,[34] making it one of the most active projects in the Apache Software Foundation[35] and one of the most active open source big data projects.

VersionOriginal release dateLatest versionRelease date
2012-06-120.5.22012-11-22
2012-10-150.6.22013-02-07
2013-02-270.7.32013-07-16
2013-09-250.8.12013-12-19
2014-02-020.9.22014-07-23
2014-05-261.0.22014-08-05
2014-09-111.1.12014-11-26
2014-12-181.2.22015-04-17
2015-03-131.3.12015-04-17
2015-06-111.4.12015-07-15
2015-09-091.5.22015-11-09
2016-01-041.6.32016-11-07
2016-07-262.0.22016-11-14
2016-12-282.1.32018-06-26
2017-07-112.2.32019-01-11
2018-02-282.3.42019-09-09
2018-11-022.4.82021-05-17[36]
2020-06-183.0.32021-06-01[37]
2021-03-023.1.32022-02-18[38]
2021-10-133.2.42023-04-13[39]
2022-06-163.3.32023-08-21[40]
2023-04-133.4.32024-04-18[41]
2023-09-093.5.12024-02-23[42]

Scala Version

Spark 3.5.0 is based on Scala 2.13 (and thus works with Scala 2.12 and 2.13 out-of-the-box), but it can also be made to work with Scala 3.[43]

Developers

Apache Spark is developed by a community. The project is managed by a group called the "Project Management Committee" (PMC).[44]

Maintenance releases and EOL

Feature release branches will, generally, be maintained with bug fix releases for a period of 18 months. For example, branch 2.3.x is no longer considered maintained as of September 2019, 18 months after the release of 2.3.0 in February 2018. No more 2.3.x releases should be expected after that point, even for bug fixes.

The last minor release within a major a release will typically be maintained for longer as an “LTS” release. For example, 2.4.0 was released on November 2, 2018, and had been maintained for 31 months until 2.4.8 was released in May 2021. 2.4.8 is the last release and no more 2.4.x releases should be expected even for bug fixes.[45]

See also

Notes and References

  1. Web site: Spark Release 2.0.0 . MLlib in R: SparkR now offers MLlib APIs [..] Python: PySpark now offers many more MLlib algorithms".
  2. Matei . Zaharia . Mosharaf . Chowdhury . Michael J. . Franklin . Scott . Shenker . Ion . Stoica . Spark: Cluster Computing with Working Sets . USENIX Workshop on Hot Topics in Cloud Computing (HotCloud) .
  3. Web site: Spark 2.2.0 Quick Start . . 2017-07-11 . apache.org . 2017-10-19 . we highly recommend you to switch to use Dataset, which has better performance than RDD.
  4. Web site: Spark 2.2.0 deprecation list . . 2017-07-11 . apache.org . 2017-10-10.
  5. Web site: A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets: When to use them and why . Damji . Jules . 2016-07-14 . databricks.com . 2017-10-19.
  6. Book: Chambers, Bill . 2017-08-10 . Spark: The Definitive Guide . http://techbus.safaribooksonline.com/book/operating-systems-and-server-administration/apache/9781491912201/12dot-resilient-distributed-datasets-rdds/about_rdds_html . . 12 . virtually all Spark code you run, where DataFrames or Datasets, compiles down to an RDD .
  7. Web site: What is Apache Spark? Spark Tutorial Guide for Beginner . janbasktraining.com . 2018-04-13. 2018-04-13 .
  8. Matei . Zaharia . Mosharaf . Chowdhury . Tathagata . Das . Ankur . Dave . Justin . Ma . Murphy . McCauley . Michael . J. . Scott . Shenker . Ion . Stoica . 2010 . Resilient Distributed Datasets: A Fault-Tolerant Abstraction for In-Memory Cluster Computing . USENIX Symp. Networked Systems Design and Implementation.
  9. Reynold. Xin. Josh . Rosen. Matei. Zaharia. Michael. Franklin. Scott. Shenker. Ion. Stoica. Shark: SQL and Rich Analytics at Scale. SIGMOD 2013. June 2013. 2012arXiv1211.6176X. 1211.6176.
  10. Web site: 4 reasons why Spark could jolt Hadoop into hyperdrive . Derrick . Harris . 28 June 2014 . . 25 February 2016 . 24 October 2017 . https://web.archive.org/web/20171024090226/https://gigaom.com/2014/06/28/4-reasons-why-spark-could-jolt-hadoop-into-hyperdrive/ . dead .
  11. Web site: Cluster Mode Overview - Spark 2.4.0 Documentation - Cluster Manager Types. . 2019-07-09. apache.org. Apache Foundation. 2019-07-09.
  12. https://amplab.cs.berkeley.edu/software/ Figure showing Spark in relation to other open-source Software projects including Hadoop
  13. http://doc.mapr.com/display/MapR/Ecosystem+Support+Matrix MapR ecosystem support matrix
  14. Re: cassandra + spark / pyspark . 2014-09-10 . 2014-11-21 . Cassandra User . Doan . DuyHai .
  15. Book: Characterization and Optimization of Memory-Resident MapReduce on HPC Systems. IEEE. May 2014. 10.1109/IPDPS.2014.87. 978-1-4799-3800-1. 2014 IEEE 28th International Parallel and Distributed Processing Symposium. Wang. Yandong. Goldstone. Robin. Yu. Weikuan. Wang. Teng. 799–808. 11157612.
  16. Web site: GitHub - DFDX/Spark.jl: Julia binding for Apache Spark.. GitHub. 2019-05-24.
  17. Web site: Applying the Lambda Architecture with Spark, Kafka, and Cassandra Pluralsight. www.pluralsight.com. 2016-11-20.
  18. Web site: Building Lambda Architecture with Spark Streaming . Shapira . Gwen . 29 August 2014 . cloudera.com . Cloudera . 17 June 2016 . re-use the same aggregates we wrote for our batch application on a real-time data stream . https://web.archive.org/web/20160614022751/http://blog.cloudera.com/blog/2014/08/building-lambda-architecture-with-spark-streaming/ . 14 June 2016 . dead .
  19. Book: Benchmarking Streaming Computation Engines: Storm, Flink and Spark Streaming . May 2016 . IEEE . 10.1109/IPDPSW.2016.138 . 2016 IEEE International Parallel and Distributed Processing Symposium Workshops (IPDPSW) . 1789–1792 . Chintapalli . Sanket . Dagit . Derek . Evans . Bobby . Farivar . Reza . Graves . Thomas . Holderbaugh . Mark . Liu . Zhuo . Nusbaum . Kyle . Patil . Kishorkumar . Peng . Boyang Jerry . Poulosky . Paul . 978-1-5090-3682-0 . 2180634 .
  20. Web site: Getting Data into Spark Streaming . Kharbanda . Arush . 17 March 2015 . sigmoid.com . Sigmoid (Sunnyvale, California IT product company) . 7 July 2016 . https://web.archive.org/web/20160815025917/https://www.sigmoid.com/getting-data-into-spark-streaming/ . 15 August 2016 . dead .
  21. Web site: Structured Streaming In Apache Spark: A new high-level API for streaming . Zaharia . Matei . 2016-07-28 . databricks.com . 2017-10-19.
  22. Web site: On-Premises vs. Cloud Data Warehouses: Pros and Cons . 2022-10-16 . SearchDataManagement . en.
  23. Web site: Spark Meetup: MLbase, Distributed Machine Learning with Spark . Sparks . Evan . Talwalkar . Ameet . 2013-08-06 . slideshare.net . Spark User Meetup, San Francisco, California . 10 February 2014.
  24. Web site: MLlib Apache Spark. spark.apache.org. 2016-01-18.
  25. Web site: Finding Graph Isomorphisms In GraphX And GraphFrames: Graph Processing vs. Graph Database . Malak . Michael . 14 June 2016 . slideshare.net . sparksummit.org . 11 July 2016.
  26. Book: Malak, Michael . 1 July 2016 . Spark GraphX in Action . Manning . 89 . 9781617292521 . Pregel and its little sibling aggregateMessages are the cornerstones of graph processing in GraphX. ... algorithms that require more flexibility for the terminating condition have to be implemented using aggregateMessages.
  27. Web site: Finding Graph Isomorphisms In GraphX And GraphFrames: Graph Processing vs. Graph Database . Malak . Michael . 14 June 2016 . slideshare.net . sparksummit.org . 11 July 2016.
  28. Joseph. Gonzalez. Reynold . Xin. Ankur. Dave. Daniel. Crankshaw. Michael. Franklin. Ion. Stoica. GraphX: Graph Processing in a Distributed Dataflow Framework. OSDI 2014. Oct 2014.
  29. Web site: .NET for Apache Spark Big data analytics. 15 October 2019 .
  30. Web site: Spark.jl. . 14 October 2021.
  31. News: Apache Spark speeds up big data decision-making. Clark. Lindsay. ComputerWeekly.com. 2018-05-16. en-GB.
  32. Web site: The Apache Software Foundation Announces Apache&#8482 Spark&#8482 as a Top-Level Project . . 27 February 2014 . apache.org . Apache Software Foundation . 4 March 2014.
  33. http://databricks.com/blog/2014/11/05/spark-officially-sets-a-new-record-in-large-scale-sorting.html Spark officially sets a new record in large-scale sorting
  34. https://www.openhub.net/p/apache-spark Open HUB Spark development activity
  35. Web site: The Apache Software Foundation Announces Apache&#8482 Spark&#8482 as a Top-Level Project . . 27 February 2014 . apache.org . Apache Software Foundation . 4 March 2014.
  36. Web site: . Spark 2.4.8 released . live . https://web.archive.org/web/20210825155614/https://spark.apache.org/news/spark-2-4-8-released.html . 2021-08-25 . spark.apache.org .
  37. Web site: . Spark 3.0.3 released . spark.apache.org .
  38. Web site: . Spark 3.1.3 released . live . https://web.archive.org/web/20220618140827/https://spark.apache.org/news/3-1-3-released.html . 2022-06-18 . spark.apache.org .
  39. Web site: . Spark 3.2.4 released . spark.apache.org .
  40. Web site: . Spark 3.3.3 released . spark.apache.org .
  41. Web site: . Spark 3.4.3 released . spark.apache.org.
  42. Web site: . Spark 3.5.1 released . spark.apache.org.
  43. Web site: Using Scala 3 with Spark . 47 Degrees . 29 July 2022 . en.
  44. Web site: Apache Committee Information.
  45. Web site: Versioning policy . spark.apache.org .