|
| 1 | +--- |
| 2 | +post_title: Fault Tolerance |
| 3 | +menu_order: 100 |
| 4 | +feature_maturity: "" |
| 5 | +enterprise: 'no' |
| 6 | +--- |
| 7 | + |
| 8 | +<!-- This source repo for this topic is https://github.com/mesosphere/dcos-commons --> |
| 9 | + |
| 10 | + |
| 11 | +Failures such as host, network, JVM, or application failures can affect the behavior of three types of Spark components: |
| 12 | + |
| 13 | +- DC/OS Apache Spark Service |
| 14 | +- Batch Jobs |
| 15 | +- Streaming Jobs |
| 16 | + |
| 17 | +# DC/OS Apache Spark Service |
| 18 | + |
| 19 | +The DC/OS Apache Spark service runs in Marathon and includes the Mesos Cluster Dispatcher and the Spark History Server. The Dispatcher manages jobs you submit via `dcos spark run`. Job data is persisted to Zookeeper. The Spark History Server reads event logs from HDFS. If the service dies, Marathon will restart it, and it will reload data from these highly available stores. |
| 20 | + |
| 21 | +# Batch Jobs |
| 22 | + |
| 23 | +Batch jobs are resilient to executor failures, but not driver failures. The Dispatcher will restart a driver if you submit with `--supervise`. |
| 24 | + |
| 25 | +## Driver |
| 26 | + |
| 27 | +When the driver fails, executors are terminated, and the entire Spark application fails. If you submitted your job with `--supervise`, then the Dispatcher will restart the job. |
| 28 | + |
| 29 | +## Executors |
| 30 | + |
| 31 | +Batch jobs are resilient to executor failure. Upon failure, cached data, shuffle files, and partially computed RDDs are lost. However, Spark RDDs are fault-tolerant, and Spark will start a new executor to recompute this data from the original data source, caches, or shuffle files. There is a performance cost as data is recomputed, but an executor failure will not cause a job to fail. |
| 32 | + |
| 33 | +# Streaming Jobs |
| 34 | + |
| 35 | +Whereas batch jobs run once and can usually be restarted upon failure, streaming jobs often need to run constantly. The application must survive driver failures, often with no data loss. |
| 36 | + |
| 37 | +In summary, to experience no data loss, you must run with the WAL enabled. The one exception is that, if you're consuming from Kafka, you can use the Direct Kafka API. |
| 38 | + |
| 39 | +For exactly once processing semantics, you must use the Direct Kafka API. All other receivers provide at least once semantics. |
| 40 | + |
| 41 | +## Failures |
| 42 | + |
| 43 | +There are two types of failures: |
| 44 | + |
| 45 | +- Driver |
| 46 | +- Executor |
| 47 | + |
| 48 | +## Job Features |
| 49 | + |
| 50 | +There are a few variables that affect the reliability of your job: |
| 51 | + |
| 52 | +- [WAL][1] |
| 53 | +- [Receiver reliability][2] |
| 54 | +- [Storage level][3] |
| 55 | + |
| 56 | +## Reliability Features |
| 57 | + |
| 58 | +The two reliability features of a job are data loss and processing semantics. Data loss occurs when the source sends data, but the job fails to process it. Processing semantics describe how many times a received message is processed by the job. It can be either "at least once" or "exactly once" |
| 59 | + |
| 60 | +### Data loss |
| 61 | + |
| 62 | +A Spark Job loses data when delivered data does not get processed. The following is a list of configurations with increasing data preservation guarantees: |
| 63 | + |
| 64 | +- Unreliable receivers |
| 65 | + |
| 66 | +Unreliable receivers do not ack data they receive from the source. This means that buffered data in the receiver will be lost upon executor failure. |
| 67 | + |
| 68 | +executor failure => **data loss** driver failure => **data loss** |
| 69 | + |
| 70 | +- Reliable receivers, unreplicated storage level |
| 71 | + |
| 72 | +This is an unusual configuration. By default, Spark Streaming receivers run with a replicated storage level. But if you happen reduce the storage level to be unreplicated, data stored on the receiver but not yet processed will not survive executor failure. |
| 73 | + |
| 74 | + executor failure => **data loss** |
| 75 | + driver failure => **data loss** |
| 76 | + |
| 77 | +- Reliable receivers, replicated storage level |
| 78 | + |
| 79 | +This is the default configuration. Data stored in the receiver is replicated, and can thus survive a single executor failure. Driver failures, however, result in all executors failing, and therefore result in data loss. |
| 80 | + |
| 81 | + (single) executor failure => **no data loss** |
| 82 | + driver failure => **data loss** |
| 83 | + |
| 84 | +- Reliable receivers, WAL |
| 85 | + |
| 86 | +With a WAL enabled, data stored in the receiver is written to a highly available store such as S3 or HDFS. This means that an app can recover from even a driver failure. |
| 87 | + |
| 88 | + executor failure => **no data loss** |
| 89 | + driver failure => **no data loss** |
| 90 | + |
| 91 | +- Direct Kafka Consumer, no checkpointing |
| 92 | + |
| 93 | +Since Spark 1.3, The Spark+Kafka integration has supported an experimental Direct Consumer, which doesn't use traditional receivers. With the direct approach, RDDs read directly from kafka, rather than buffering data in receivers. |
| 94 | + |
| 95 | +However, without checkpointing, driver restarts mean that the driver will start reading from the latest Kafka offset, rather than where the previous driver left off. |
| 96 | + |
| 97 | + executor failure => **no data loss** |
| 98 | + driver failure => **data loss** |
| 99 | + |
| 100 | +- Direct Kafka Consumer, checkpointing |
| 101 | + |
| 102 | +With checkpointing enabled, Kafka offsets are stored in a reliable store such as HDFS or S3. This means that an application can restart exactly where it left off. |
| 103 | + |
| 104 | + executor failure => **no data loss** |
| 105 | + driver failure => **no data loss** |
| 106 | + |
| 107 | +### Processing semantics |
| 108 | + |
| 109 | +Processing semantics apply to how many times received messages get processed. With Spark Streaming, this can be either "at least once" or "exactly once". |
| 110 | + |
| 111 | +The semantics below describe apply to Spark's receipt of the data. To provide an end-to-end exactly-once guarantee, you must additionally verify that your output operation provides exactly-once guarantees. More info [here][4]. |
| 112 | + |
| 113 | +- Receivers |
| 114 | + |
| 115 | + **at least once** |
| 116 | + |
| 117 | +Every Spark Streaming consumer, with the exception of the Direct Kafka Consumer described below, uses receivers. Receivers buffer blocks of data in memory, then write them according to the storage level of the job. After writing out the data, it will send an ack to the source so the source knows not to resend. However, if this ack fails, or the node fails between writing out the data and sending the ack, then an inconsistency arises. Spark believes that the data has been received, but the source does not. This results in the source resending the data, and it being processed twice. |
| 118 | + |
| 119 | +- Direct Kafka Consumer |
| 120 | + |
| 121 | + **exactly once** |
| 122 | + |
| 123 | +The Direct Kafka Consumer avoids the problem described above by reading directly from Kafka, and storing the offsets itself in the checkpoint directory. |
| 124 | + |
| 125 | + More information [here][5]. |
| 126 | + |
| 127 | + |
| 128 | +[1]: https://spark.apache.org/docs/1.6.0/streaming-programming-guide.html#requirements |
| 129 | +[2]: https://spark.apache.org/docs/1.6.0/streaming-programming-guide.html#with-receiver-based-sources |
| 130 | +[3]: http://spark.apache.org/docs/latest/programming-guide.html#which-storage-level-to-choose |
| 131 | +[4]: http://spark.apache.org/docs/latest/streaming-programming-guide.html#semantics-of-output-operations |
| 132 | +[5]: https://databricks.com/blog/2015/03/30/improvements-to-kafka-integration-of-spark-streaming.html |
0 commit comments