library(future)
plan(multisession)
ys <- xs |> furrr::future_map(slow_sum)University of California, San Francisco
R Foundation, R Consortium
@HenrikBengtsson


library(future)
plan(multisession)
ys <- xs |> furrr::future_map(slow_sum)library(future)
plan(future.p2p::cluster, cluster="alice/friends")
ys <- xs |> furrr::future_map(slow_sum)
y <- slow_sum(1:10)
➔

1 minute
➔

➔ y ← 55
y <- slow_sum(1:10)
future
➔

1 minute
➔

value
➔ y ← 55
y1 <- slow_sum( 1:10) # 1 minute
y2 <- slow_sum(11:20) # 1 minute
y3 <- slow_sum(21:30) # 1 minute
➔

1 minute
➔
➔ y1 ← 55
➔

1 minute
➔
➔ y2 ← 155
➔

1 minute
➔
➔ y3 ← 255

future #1

future #2

future #3
➔



1 minute
total
➔

value #1

value #2

value #3
➔
y1 ← 55
y2 ← 155
y3 ← 255
The {future} package provides:
|
|
|
future()
|
resolved()
|
value()
|
ys <- lapply(xs, slow_sum) # base R
ys <- xs |> map(slow_sum) # {purrr}
are functions packaging things up in boxes and sending them to R;
➔
➔ 
⋮
➔
➔ 
Fast, futurized counterparts that send the boxes to parallel R workers;
ys <- future_lapply(xs, slow_sum) # {future.apply}
ys <- xs |> future_map(slow_sum) # {furrr}
…

➔

⋮
parallel
➔

…

You can parallelize “boxes” on your current computer, e.g. one of
plan(multisession)
plan(future.callr::callr)
plan(future.mirai::mirai_multisession)You can distribute “boxes” to other computers, e.g. one of
plan(cluster, workers = c("n1", "desktop", "server.myuniv.org"))
plan(future.batchtools::batchtools_slurm)… and now you can send them to your friends too!
Message Board
Used to announce futures and offers to do work
(centralized; lightweight - only metadata)

P2P file-transfer protocol
Used to send futures to workers and receive results
(peer-to-peer; full-size data transfers)

Create a pico.sh account (1 minute)
Try with personal P2P cluster (3 minutes)
Instructions at https://future.p2p.futureverse.org/
Alice sets up P2P cluster and gives ‘bob’ and ‘carol’ access:
This is setting up a shared message board.
=> A shared P2P cluster with 6 workers.
High throughput:
any number of users and workers can join
a public P2P cluster could have thousands of P2P workers
High latency:
round-trip takes time, because p2p file transfers take time
Example: 1+2 takes 1-10 seconds to send, evaluate, and return
This will improve!
What if?
Risks can be mitigated by “sandboxing” workers, e.g.
