Chapter 2 Resilient Distributed Datasets | of Phd Thesis Matei Zaharia

2.1 Introduction

Where does Spark jump in?

Traditional data flow systems inefficient for applications that require data sharing across computations, e.g.

  • iterative algorithms
  • interactive queries
  • stream processing

"For example, iterative algorithms, such as PageRank, K-means clustering, or logistic regression, need to make multiple passes over the same dataset; interactive data mining often requires running multiple ad-hoc queries on the same subset of the data; and streaming applications need to maintain and share state across time." (9)

Only way to share data between computations is writing to disk, but this has a lot of overhead: data replication, disk I/O, serialization.

Solutions before Spark were very specialized, and "do not provide abstractions for more general reuse, e.g., to let a user load several datasets into memory and run ad-hoc queries across them." (10)

Fault tolerance without replication:

RDDs provide an interface based on coarse-grained transformations (e.g., map, filter and join) that apply the same operation to many data items. This allows them to efficiently provide fault tolerance by logging the transformations used to build a dataset (its lineage) rather than the actual data.1 If a partition of an RDD is lost, the RDD has enough information about how it was derived from other RDDs to recompute just that partition. Thus, lost data can be recovered, often quite quickly, without requiring costly replication.

This is such a good fit, because the aforementioned parallel applications also perform the same operation on multiple data items.

"We show that Spark is up to 80× faster than Hadoop for iterative applications, speeds up a real-world data analytics report by 40×, and can be used interactively to scan a 1 TB dataset with 5–7s latency."

2.2 RDD abstraction

  • read-only, partitioned collection of records
  • defined deterministically by transformations (e.g. map, filter, join) 1) data in stable storage 2) other RDDs
  • Always has a lineage and can be reconstructed
    • RDDs do thus not always need to be materialized. They can be swapped out in memory, and if they are needed, they can always be reconstructed.

User has control over:

1) Persistence * Define storage strategy, i.e. mark for keeping RDD in memory 2) Partitioning * Partition across machines based on record keys * Optimization: e.g. ensure that two datasets that will be joined are hash-partitioned in the same way so they end up on the same partition: no latency.

Spark

Transformations on stable storage: map, filter.

Action: e.g. count, returns a value for a transformation.

Persist methods: flag, strategies, priorities.

Lazy evaluations allows efficient pipelining transformations, to do them at once when and where results are needed.

E.g. get logfiles with errors, and keep in memory:

lines = spark.textFile("hdfs://...")
errors = lines.filter(_.startsWith("ERROR"))
errors.persist()
errors.count() // Action

Because errors is kept in memory, the following is faster. Errors is probably only a small subset of lines, and therefore it's smarter to try and store errors rather than lines.

// Count errors mentioning MySQL:
errors.filter(_.contains("MySQL")).count()
// Return the time fields of errors mentioning HDFS as an array, assuming
// time is field number 3 in a tab-separated format:
errors.filter(_.contains("HDFS"))
.map(_.split(’\t’)(3))
.collect()

The last three lines have this lineage:

1) lines 2) errors, via filter. Persists. 3) HDFS errors, via filter 4) time fields, via map

After computations are triggered by collect, errors will be kept in memory. Subsequent computations will then be faster.

Step 3 and 4 can be pipelined together as a set of tasks and send them to the nodes holding the cached partitions of errors.

If a partition of errors is lost, Spark recomputes it from a partition of lines.

2.2.3 advantages of RDD model

vs DSM: distributed share memory. (see p.13/14)

The main difference between RDDs and DSM is that RDDs can only be created (“written”) through coarse-grained transformations, while DSM allows reads and writes to each memory location.3 This restricts RDDs to applications that perform bulk writes, but allows for more efficient fault tolerance. In particular, RDDs do not need to incur the overhead of checkpointing, as they can be recovered using lineage. Furthermore, only the lost partitions of an RDD need to be recomputed upon failure, and they can be recomputed in parallel on different nodes, without having to roll back the whole program.

  • In traditional programs you need to restart the complete program upon data loss from the last checkpoint, because now this data is missing and the whole job is waiting for those results to come in. RDDs can in parallel solve this problem by tracing back the lineage only of that partition.
  • Also, backup tasks to help slow strangler nodes are hard in DSM as the tasks then work on the same memory.
  • RDDs can run backup tasks like in MapReduce. But how exactly? I guess this amounts to computing a new RDD, so no data is shared.
  • "a runtime can schedule tasks based on data locality to improve performance"
  • RDDs degrade gracefully

2.2.4 What are RDDs not suitable for

RDD are designed for doing the same operation on bulk data.

This coarseness makes lineages effective as a method for reconstruction.

If you would do many small writes to (shared) memory, reconstruction through lineage would get really complicated and require logging of huge amounts of data.

So RDDs not suitable for asynchronous fine-grained updates.

Spark Programming Interface

Users write a driver program:

"The driver defines one or more RDDs and invokes actions on them. Spark code on the driver also tracks the RDDs’ lineage. The workers are long-lived processes that can store RDD partitions in RAM across operations."

RDD operations are passed as function literals (closures) to where they are needed. Scala represents closures as Java objects, and they can thus be serialized and sent across the network.

RDDs are statically typed due to the JVM, but types can often be omitted in Scal due to type inference.

E.g. RDD[Int] is RDD of integers.

See p.19 for optimization by partitioning

Cf. "After this initial call, the join operation between links and ranks will automatically aggregate the contributions for each URL to the machine that its link lists is on, calculate its new rank there, and join it with its links. This type of consistent partitioning across iterations is one of the main optimizations in specialized frameworks like Pregel. RDDs let the user express this goal directly."

Note on iterative programs: in each iterations new RDDs are formulated.

2.4 Representing RDDs

Transformations over RDD are uniform in the sense that transformations do not require their own logic. Instead, all transformations are dealt with in the same way, which allows transformations to be composed. By composition transformation into a lineage you can represent RDDs by DAG graphs.

RDD representation has five crucial elements:

  • set of partitions
    • atomic pieces of the dataset
  • set of dependencies on parent RDDs
  • function for computing the dataset based on the parents
  • metadata about partitioning scheme and data placement

W.r.t. partitions / blocks

"For example, an RDD representing an HDFS file has a partition for each block of the file and knows which machines each block is on. Meanwhile, the result of a map on this RDD has the same partitions, but applies the map function to the parent's data when computing its elements." (14)

Per RDD, multiple partitions, which can correspond to file blocks in HDFS.

Two type of dependencies

  • Narrow, e.g. map
    • Each partition of the parent RDD is used by at most one partition of the child RDD
  • Wide, e.g. join (unless parents hash-partitioned)
    • Multiple child RDDs depend on one one parent RDD
    • Rephrased: parent has connection to multiple nodes.

W.r.t. phrasing of the dependencies, note that it's not about the amount of parents that a child node needs, but about by how many children use a given parent. That's why especially the formulation of wide dependencies seems the wrong way around for me, initially.

Example: Consider a join operation where the input RDDs were already co-partitioned. Despite being a join operation, this is a narrow dependency, because each parent is only used by one child (but note that each child depends on two parents; it's a join after all!)

Narrow dependencies allow for pipelining execution on one cluster node. So the advantages of pipelining is that all the parent RDDs can be computed on the same cluster node.

Wide dependencies require data from parent nodes to be available, shuffled and shipped to the places where they are needed, like in MapReduce.

Recovery: more efficient for pipelining.

  • Only the lost partition needs to be recomputed with a linear lineage
  • Can be done in parallel due to independence between partitions.

"In contrast, in a lineage graph with wide dependencies, a single failed node might cause the loss of some partition from all the ancestors of an RDD, requiring a complete re-execution." (21)

History · 5 changes since 2019-05-10

Full changelog