Parallel connections using a background process pool"

AzureRMR provides the ability to parallelise communicating with Azure by utilising a pool of R processes in the background. This often leads to major speedups in scenarios like downloading large numbers of small files, or working with a cluster of virtual machines. This is intended for use by packages that extend AzureRMR (and was originally implemented as part of the AzureStor package), but can also be called directly by the end-user.

This functionality was originally implemented independently in the AzureStor and AzureVM packages, but has now been moved into AzureRMR. This removes the code duplication, and also makes it available for other packages that may benefit.

Working with the pool

A small API consisting of the following functions is currently provided for managing the pool. They pass their arguments down to the corresponding functions in the parallel package.

The pool is persistent for the session or until terminated by delete_pool. You should initialise the pool by calling init_pool before running any code on it. This restores the original state of the pool nodes by removing any objects that may be in memory, and resetting the working directory to the master working directory.

The pool is a shared resource, and so packages that make use of it should not assume that they have sole control over its state. In particular, just because the pool exists at the end of one call doesn't mean it will still exist at the time of a subsequent call.

Here is a simple example that shows how to initialise the pool, and then execute code on it.

# create the pool
# by default, it contains 10 nodes

# send some data to the nodes
x <- 42

# run some code
pool_sapply(1:10, function(y) x + y)

#> [1] 43 44 45 46 47 48 49 50 51 52

Here is a more realistic example using the AzureStor package. We create a connection to an Azure storage account, and then upload a number of files in parallel to a blob container. This is basically what the storage_multiupload function does under the hood.


endp <- storage_endpoint("", key="key")
cont <- storage_container(endp, "container")

src_files <- c("file1.txt", "file2.txt", "file3.txt")
dest_files <- src_files

    function(src, dest) AzureStor::storage_upload(cont, src, dest),

Try the AzureRMR package in your browser

Any scripts or data that you put into this service are public.

AzureRMR documentation built on Oct. 23, 2021, 9:06 a.m.