From 2f03d0a84693695c3ac9a9af0a66e4818617ac93 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Wed, 23 Aug 2023 16:18:40 +0100 Subject: [PATCH] launch dispatcher --vanilla --- DESCRIPTION | 2 +- NEWS.md | 3 ++- R/mirai.R | 12 +++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 330634028..7ae501ea0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: mirai Type: Package Title: Minimalist Async Evaluation Framework for R -Version: 0.9.1.9012 +Version: 0.9.1.9013 Description: Lightweight parallel code execution and distributed computing. Designed for simplicity, a 'mirai' evaluates an R expression asynchronously, on local or network resources, resolving automatically upon completion. diff --git a/NEWS.md b/NEWS.md index 6fde01727..4a479ae29 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,9 @@ -# mirai 0.9.1.9012 (development) +# mirai 0.9.1.9013 (development) * Previously deprecated function `server()` is removed in favour of `daemon()`. * `daemons()` argument 'dispatcher' has a new option `NA`, which allows an initial sync time of up to 20s (vs. the default 5s), accommodating configurations where R startup takes longer (thanks @alexpiper). * Dispatcher enhancements and fixes: + + Runs in an R session with `--vanilla` flags for efficiency. + Straight pass through without serialization/unserialization allows higher performance and lower memory utilisation. + Fixes edge cases of `status()` occasionally failing to communicate with dispatcher. + Fixes edge cases of ending a session with unresolved mirai resulting in a crash rather than a clean exit. diff --git a/R/mirai.R b/R/mirai.R index ec39665f4..094ddd622 100644 --- a/R/mirai.R +++ b/R/mirai.R @@ -1267,18 +1267,20 @@ process_url <- function(url, .compute) { url } -write_args <- function(dots, tls = NULL) +write_args <- function(dots, tls = NULL, libpath = NULL) shQuote(switch(length(dots), sprintf("mirai::.daemon('%s')", dots[[1L]]), sprintf("mirai::daemon('%s'%s%s)", dots[[1L]], dots[[2L]], parse_tls(tls)), "", - sprintf("mirai::dispatcher('%s',n=%d,monitor='%s'%s)", dots[[1L]], dots[[3L]], dots[[4L]], dots[[2L]]), - sprintf("mirai::dispatcher('%s',c('%s'),n=%d,monitor='%s'%s%s)", dots[[1L]], paste(dots[[3L]], collapse = "','"), dots[[4L]], dots[[5L]], dots[[2L]], parse_tls(tls)))) + sprintf(".libPaths(c('%s',.libPaths()));mirai::dispatcher('%s',n=%d,monitor='%s'%s)", libpath, dots[[1L]], dots[[3L]], dots[[4L]], dots[[2L]]), + sprintf(".libPaths(c('%s',.libPaths()));mirai::dispatcher('%s',c('%s'),n=%d,monitor='%s'%s%s)", libpath, dots[[1L]], paste(dots[[3L]], collapse = "','"), dots[[4L]], dots[[5L]], dots[[2L]], parse_tls(tls)))) launch_daemon <- function(..., tls = NULL) { dots <- list(...) - output <- length(dots) > 1L && is.object(dots[[2L]]) - system2(command = .command, args = c("-e", write_args(dots, tls = tls)), stdout = if (output) "", stderr = if (output) "", wait = FALSE) + dlen <- length(dots) + output <- dlen > 1L && is.object(dots[[2L]]) + libpath <- if (dlen > 3L) file.path(attr(as.environment("package:mirai"), "path"), "..") + system2(command = .command, args = c(if (dlen > 3L) "--vanilla", "-e", write_args(dots, tls = tls, libpath = libpath)), stdout = if (output) "", stderr = if (output) "", wait = FALSE) } launch_and_sync_daemon <- function(sock, synctime, ..., tls = NULL) {