Suggestion: mirai package #110
Replies: 2 comments 5 replies
-
|
Thanks @shikokuchuo. I'm not principally opposed if the framework is, as you say, very fast and easy to use. However, looking at the main vignette, I'm not seeing an example that I find extremely compelling that would prompt me to use it. Take the first example: library(mirai)
input <- list(x = 2, y = 5, z = double(1e8))
m <- mirai(
{
res <- rnorm(1e8, mean = mean, sd = sd)
max(res) - min(res)
},
mean = input$x,
sd = input$y
)I understand this expression gets evaluated in a different R session. But where is the parallelism? Any why do I need gives parallel execution? In any case, it should be very obvious how the package can be used to generate greater performance. A major performance bottlenecks of course is duplication of objects in memory. For example z <- rnorm(1e7)
Map(function(x, y) mirai({
res <- rnorm(1e8, mean = mean, sd = sd)
res <- res + z
max(res) - min(res)
},
mean = x,
sd = y
), 1:4, 4:7) |> lapply(`[`)Does not work it seems. So, bottom line, I need to see how this is useful to optimize common operations. Ideally with shared memory. That would be well worth featuring if its a kind of real fire and forget solution. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @shikokuchuo, I'm just trying to build something rather complex using your package and encountered some issues, so I wanted to get your opinion. Basically, my code looks like this: # Code above... defines graph and results lists
if(!is.finite(nthreads) || nthreads <= 1L) {
res$final_flows <- run_assignment_core(seq_len(N), verbose)
} else {
# Split OD matrix in equal parts
ind_list <- gsplit(g = sample.int(as.integer(nthreads), N, replace = TRUE))
daemons(n = nthreads - 1L)
# Pass current environment dynamically
everywhere({}, environment())
# Now run the map in the background
final_flows_other <- mirai_map(ind_list[-1L], function(x) run_assignment_core(x, FALSE))
# Runs the first instance in the current session
final_flows <- run_assignment_core(ind_list[[1L]], verbose)
# Collect other mirai's results
final_flows_other <- collect_mirai(final_flows_other) # [.stop, .progress]
# Deactivate Daemons
daemons(0)
# Combine Results
for (fflow in final_flows_other) final_flows %+=% fflow
res$final_flows <- final_flows
rm(final_flows_other, fflow, final_flows)
}
# Code below, precesses and returns result object, Where The other two particularities are that I have defined global results lists above the parallel section, and let So I just wanted to hear your input on which parts of this pipeline are feasible? I guess having large objects shared between multiple daemons is feasible? If so, is my setup ok? And is there a scope to do global assignment (potentially also using C/by reference)? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Sebastian, following feedback from useR!2024 I'd like to propose my own package.
I've seen your reasoning for not including parallel processing to date, and have hence held back thus far.
However I want to highlight that there are now 'fast' and 'slow' ways to do parallel processing / distributed computing itself. The gain in speed is easily over 100x from existing solutions (see https://shikokuchuo.net/user2024-conference/#/mirai---100x-faster).
This is achieved by the minimalist design of mirai, and the fact it has just one (recursive) dependency on
nanonext, which is itself a high-performance binding written almost entirely in C (including interfacing R serialization at the C API level etc.). Also to be noted is the (optional) integration with thelaterevent loop (developed in collaboration with Joe Cheng), which enables event-driven, zero-latency promise resolution for Shiny / Plumber.We are talking about taking round-trip task resolution from the millisecond to the microsecond scale - enabling R usage in contexts where it wasn't feasible before such as high frequency real-time data, or just for more responsive Shiny apps!
If you are receptive, am happy to draft or review a PR. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions