| 1 |
:orphan: |
| 2 |
|
| 3 |
Comparison to Spark |
| 4 |
=================== |
| 5 |
|
| 6 |
`Apache Spark <https://spark.apache.org/>`_ is a popular distributed computing |
| 7 |
tool for tabular datasets that is growing to become a dominant name in Big Data |
| 8 |
analysis today. Dask has several elements that appear to intersect this space |
| 9 |
and we are often asked, "How does Dask compare with Spark?" |
| 10 |
|
| 11 |
Answering such comparison questions in an unbiased and informed way is hard, |
| 12 |
particularly when the differences can be somewhat technical. This document |
| 13 |
tries to do this; we welcome any corrections. |
| 14 |
|
| 15 |
Summary |
| 16 |
------- |
| 17 |
|
| 18 |
Generally Dask is smaller and lighter weight than Spark. This means that it |
| 19 |
has fewer features and, instead, is used in conjunction with other libraries, |
| 20 |
particularly those in the numeric Python ecosystem. It couples with libraries |
| 21 |
like Pandas or Scikit-Learn to achieve high-level functionality. |
| 22 |
Additionally, Dask is often faster and more robustly performant on `standard benchmarks <https://docs.coiled.io/blog/tpch.html?utm_source=dask-docs&utm_medium=spark-vs-dask#dask-vs-spark>`_ than Spark. |
| 23 |
|
| 24 |
Language |
| 25 |
~~~~~~~~ |
| 26 |
|
| 27 |
- Spark is written in Scala with some support for Python and R. It |
| 28 |
interoperates well with other JVM code. |
| 29 |
|
| 30 |
- Dask is written in Python and only really supports Python. It |
| 31 |
interoperates well with C/C++/Fortran/LLVM or other natively compiled |
| 32 |
code linked through Python. |
| 33 |
|
| 34 |
Ecosystem |
| 35 |
~~~~~~~~~ |
| 36 |
|
| 37 |
- Spark is an all-in-one project that has inspired its own ecosystem. It |
| 38 |
integrates well with many other Apache projects. |
| 39 |
|
| 40 |
- Dask is a component of the larger Python ecosystem. It couples with and |
| 41 |
enhances other libraries like NumPy, pandas, and Scikit-learn. |
| 42 |
|
| 43 |
|
| 44 |
Age and Trust |
| 45 |
~~~~~~~~~~~~~ |
| 46 |
|
| 47 |
- Spark is older (since 2010) and has become a dominant and |
| 48 |
well-trusted tool in the Big Data enterprise world. |
| 49 |
|
| 50 |
- Dask is younger (since 2014) and is an extension of the |
| 51 |
well trusted NumPy/pandas/Scikit-learn/Jupyter stack. |
| 52 |
|
| 53 |
Scope |
| 54 |
~~~~~ |
| 55 |
|
| 56 |
- Spark is more focused on traditional business intelligence |
| 57 |
operations like SQL and lightweight machine learning. |
| 58 |
|
| 59 |
- Dask is applied more generally both to business intelligence |
| 60 |
applications, as well as a number of scientific and custom situations. |
| 61 |
|
| 62 |
Internal Design |
| 63 |
~~~~~~~~~~~~~~~ |
| 64 |
|
| 65 |
- Spark's internal model is higher level, providing good high level |
| 66 |
optimizations on uniformly applied computations, but lacking flexibility |
| 67 |
for more complex algorithms or ad-hoc systems. It is fundamentally an |
| 68 |
extension of the Map-Shuffle-Reduce paradigm. |
| 69 |
|
| 70 |
- Dask's internal model is lower level, and so lacks high level |
| 71 |
optimizations, but is able to implement more sophisticated algorithms and |
| 72 |
build more complex bespoke systems. It is fundamentally based on generic |
| 73 |
task scheduling. |
| 74 |
|
| 75 |
Scale |
| 76 |
~~~~~ |
| 77 |
|
| 78 |
- Spark scales from a single node to thousand-node clusters. |
| 79 |
- Dask scales from a single node to thousand-node clusters. |
| 80 |
|
| 81 |
APIs |
| 82 |
~~~~ |
| 83 |
|
| 84 |
DataFrames |
| 85 |
`````````` |
| 86 |
|
| 87 |
- Spark DataFrame has its own API and memory model. It also |
| 88 |
implements a large subset of the SQL language. Spark includes a |
| 89 |
high-level query optimizer for complex queries. |
| 90 |
|
| 91 |
- Dask DataFrame reuses the Pandas API and memory model. It implements |
| 92 |
neither SQL nor a query optimizer. It is able to do random access, |
| 93 |
efficient time series operations, and other Pandas-style indexed |
| 94 |
operations. |
| 95 |
|
| 96 |
Machine Learning |
| 97 |
```````````````` |
| 98 |
|
| 99 |
- Spark MLLib is a cohesive project with support for common operations |
| 100 |
that are easy to implement with Spark's Map-Shuffle-Reduce style |
| 101 |
system. People considering MLLib might also want to consider *other* |
| 102 |
JVM-based machine learning libraries like H2O, which may have better |
| 103 |
performance. |
| 104 |
|
| 105 |
- Dask relies on and interoperates with existing libraries like |
| 106 |
Scikit-learn and XGBoost. These can be more familiar or higher |
| 107 |
performance, but generally results in a less-cohesive whole. See the |
| 108 |
`dask-ml`_ project for integrations. |
| 109 |
|
| 110 |
Arrays |
| 111 |
`````` |
| 112 |
|
| 113 |
- Spark does not include support for multi-dimensional arrays natively |
| 114 |
(this would be challenging given their computation model), although |
| 115 |
some support for two-dimensional matrices may be found in MLLib. |
| 116 |
People may also want to look at the |
| 117 |
`Thunder <https://github.com/thunder-project/thunder>`_ project, which |
| 118 |
combines Apache Spark with NumPy arrays. |
| 119 |
|
| 120 |
- Dask fully supports the NumPy model for |
| 121 |
:doc:`scalable multi-dimensional arrays <array>`. |
| 122 |
|
| 123 |
Streaming |
| 124 |
````````` |
| 125 |
|
| 126 |
- Spark's support for streaming data is first-class and integrates well |
| 127 |
into their other APIs. It follows a mini-batch approach. This |
| 128 |
provides decent performance on large uniform streaming operations. |
| 129 |
|
| 130 |
- Dask provides a :doc:`real-time futures interface <futures>` that is |
| 131 |
lower-level than Spark streaming. This enables more creative and |
| 132 |
complex use-cases, but requires more work than Spark streaming. |
| 133 |
|
| 134 |
Graphs / complex networks |
| 135 |
````````````````````````` |
| 136 |
|
| 137 |
- Spark provides GraphX, a library for graph processing. |
| 138 |
|
| 139 |
- Dask provides no such library. |
| 140 |
|
| 141 |
Custom parallelism |
| 142 |
`````````````````` |
| 143 |
|
| 144 |
- Spark generally expects users to compose computations out of their |
| 145 |
high-level primitives (map, reduce, groupby, join, ...). It is also |
| 146 |
possible to extend Spark through subclassing RDDs, although this is |
| 147 |
rarely done. |
| 148 |
|
| 149 |
- Dask allows you to specify arbitrary task graphs for more complex and |
| 150 |
custom systems that are not part of the standard set of collections. |
| 151 |
|
| 152 |
.. _dask-ml: https://ml.dask.org |
| 153 |
|
| 154 |
|
| 155 |
Reasons you might choose Spark |
| 156 |
------------------------------ |
| 157 |
|
| 158 |
- You prefer Scala or the SQL language |
| 159 |
- You have mostly JVM infrastructure and legacy systems |
| 160 |
- You want an established and trusted solution for business |
| 161 |
- You are mostly doing business analytics with some lightweight machine learning |
| 162 |
- You want an all-in-one solution |
| 163 |
|
| 164 |
|
| 165 |
Reasons you might choose Dask |
| 166 |
----------------------------- |
| 167 |
|
| 168 |
- You prefer Python or native code, or have large legacy code bases that you |
| 169 |
do not want to entirely rewrite |
| 170 |
- Your use case is complex or does not cleanly fit the Spark computing model |
| 171 |
- You want a lighter-weight transition from local computing to cluster |
| 172 |
computing |
| 173 |
- You want to interoperate with other technologies and don't mind installing |
| 174 |
multiple packages |
| 175 |
|
| 176 |
|
| 177 |
Reasons to choose both |
| 178 |
---------------------- |
| 179 |
|
| 180 |
It is easy to use both Dask and Spark on the same data and on the same cluster. |
| 181 |
|
| 182 |
They can both read and write common formats, like CSV, JSON, ORC, and Parquet, |
| 183 |
making it easy to hand results off between Dask and Spark workflows. |
| 184 |
|
| 185 |
They can both deploy on the same clusters. |
| 186 |
Most clusters are designed to support many different distributed systems at the |
| 187 |
same time, using resource managers like Kubernetes and YARN. If you already |
| 188 |
have a cluster on which you run Spark workloads, it's likely easy to also run |
| 189 |
Dask workloads on your current infrastructure and vice versa. |
| 190 |
|
| 191 |
In particular, for users coming from traditional Hadoop/Spark clusters (such as |
| 192 |
those sold by Cloudera/Hortonworks) you are using the Yarn resource |
| 193 |
manager. You can deploy Dask on these systems using the `Dask Yarn |
| 194 |
<https://yarn.dask.org>`_ project, as well as other projects, like `JupyterHub |
| 195 |
on Hadoop <https://jupyterhub-on-hadoop.readthedocs.io/en/latest/>`_. |
| 196 |
|
| 197 |
|
| 198 |
Developer-Facing Differences |
| 199 |
---------------------------- |
| 200 |
|
| 201 |
Graph Granularity |
| 202 |
~~~~~~~~~~~~~~~~~ |
| 203 |
|
| 204 |
Both Spark and Dask represent computations with directed acyclic graphs. These |
| 205 |
graphs however represent computations at very different granularities. |
| 206 |
|
| 207 |
One operation on a Spark RDD might add a node like ``Map`` and ``Filter`` to |
| 208 |
the graph. These are high-level operations that convey meaning and will |
| 209 |
eventually be turned into many little tasks to execute on individual workers. |
| 210 |
This many-little-tasks state is only available internally to the Spark |
| 211 |
scheduler. |
| 212 |
|
| 213 |
Dask graphs skip this high-level representation and go directly to the |
| 214 |
many-little-tasks stage. As such, one ``map`` operation on a Dask collection |
| 215 |
will immediately generate and add possibly thousands of tiny tasks to the Dask |
| 216 |
graph. |
| 217 |
|
| 218 |
This difference in the scale of the underlying graph has implications on the |
| 219 |
kinds of analysis and optimizations one can do and also on the generality that |
| 220 |
one exposes to users. Dask is unable to perform some optimizations that Spark |
| 221 |
can because Dask schedulers do not have a top-down picture of the computation |
| 222 |
they were asked to perform. However, Dask is able to easily represent far more |
| 223 |
`complex algorithms`_ and expose the creation of these algorithms to normal users. |
| 224 |
|
| 225 |
|
| 226 |
Conclusion |
| 227 |
---------- |
| 228 |
|
| 229 |
- Spark is mature and all-inclusive. If you want a single project that does |
| 230 |
everything and you're already on Big Data hardware, then Spark is a safe bet, |
| 231 |
especially if your use cases are typical ETL + SQL and you're already using |
| 232 |
Scala. |
| 233 |
|
| 234 |
- Dask is lighter weight and is easier to integrate into existing code and hardware. |
| 235 |
If your problems vary beyond typical ETL + SQL and you want to add flexible |
| 236 |
parallelism to existing solutions, then Dask may be a good fit, especially if |
| 237 |
you are already using Python and associated libraries like NumPy and Pandas. |
| 238 |
|
| 239 |
If you are looking to manage 100GB or less of tabular CSV or JSON data, |
| 240 |
then you should forget both Spark and Dask and use Postgres_ or MongoDB_. |
| 241 |
|
| 242 |
|
| 243 |
.. _Spark: https://spark.apache.org/ |
| 244 |
.. _PySpark: https://spark.apache.org/docs/latest/api/python/ |
| 245 |
.. _Postgres: https://www.postgresql.org/ |
| 246 |
.. _MongoDB: https://www.mongodb.org/ |
| 247 |
.. _`complex algorithms`: http://matthewrocklin.com/blog/work/2015/06/26/Complex-Graphs |