Overview

multidplyr is a backend for dplyr that partitions a data frame across multiple cores. You tell multidplyr how to split the data up with partition() and then the data stays on each node until you explicitly retrieve it with collect(). This minimises the amount of time spent moving data around, and maximises parallel performance. This idea is inspired by partools by Norm Matloff and distributedR by the Vertica Analytics team.

Due to the overhead associated with communicating between the nodes, you won’t see much performance improvement on basic dplyr verbs with less than ~10 million observations, and you may want to try dtplyr, which uses data.table instead. multidplyr’s strength is conveniently parallelising the type of more complex operation often found in do().

(Note that unlike other packages in the tidyverse, multidplyr requires R 3.5 or greater. We hope to relax this requirement in the future.)

Usage

To use multidplyr, you first create a cluster of the desired number of workers. Each one of these workers is a separate R process, and the operating system will spread their execution across multiple cores:

library(multidplyr)
library(dplyr, warn.conflicts = FALSE)

cluster <- new_cluster(4)

There are two primary ways to use multidplyr. The first, and most efficient, way is to read different files on each worker:

Alternatively, if you already have the data loaded in the main session, you can use partition() to automatically spread it across workers. Use group_by() to ensure that all of the observations belonging to a group end up on the same worker.

Now you can work with it like a regular data frame, but the computations will be spread across multiple cores. Once you’ve finished computation, use collect() to bring the data back to the host session:

Note that there is some overhead associated with copying data from the worker nodes back to the host node (and vice versa), so you’re best off using multidplyr with more complex operations. See vignette("multidplyr") for more details.