Skip to content

Commit

Permalink
launch dispatcher --vanilla
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Aug 23, 2023
1 parent 23c4cf8 commit 2f03d0a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 7 additions & 5 deletions R/mirai.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2f03d0a

Please sign in to comment.