Skip to content

Commit

Permalink
Merge pull request #154 from shikokuchuo/daemons
Browse files Browse the repository at this point in the history
Allow control over whether to reset daemons settings
  • Loading branch information
shikokuchuo committed Sep 16, 2024
2 parents c260d7e + a9d57ce commit 57e0bc4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 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: 1.2.0.9015
Version: 1.2.0.9016
Description: Designed for simplicity, a 'mirai' evaluates an R expression
asynchronously in a parallel process, locally or distributed over the
network, with the result automatically available upon completion. Modern
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# mirai 1.2.0.9015 (development)
# mirai 1.2.0.9016 (development)

* `daemons(dispatcher = NA)` now provides access to threaded dispatcher (experimental). This implements dispatcher using a thread rather than an external process and is faster and more efficient.
* `daemons()` behavioural changes:
- Return value is now always an integer value - either the number of daemons set if using dispatcher, or the number of daemons launched locally (zero if using a remote launcher).
- Gains argument 'force' to control whether calls to `daemons()` resets previous settings for the same compute profile.
* `mirai_map()` behavioural changes:
- Combining multiple collection options becomes easier, allowing for instance `x[.stop, .progress]`.
- Adds `mirai_map()[.progress_cli]` as an alternative progress indicator, using the 'cli' package to show % complete and ETA.
Expand Down
24 changes: 12 additions & 12 deletions R/daemons.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
#' dispatcher and \sQuote{asyncdial}, \sQuote{autoexit}, \sQuote{cleanup},
#' \sQuote{output}, \sQuote{maxtasks}, \sQuote{idletime}, \sQuote{walltime}
#' and \sQuote{timerstart} at daemon.
#' @param force [default TRUE] logical value whether to always reset and apply
#' new daemons settings, even if the compute profile is already set up. If
#' FALSE, to apply new daemons settings requires daemons to be explicitly
#' reset first using \code{daemons(0)}.
#' @param seed [default NULL] (optional) supply a random seed (single value,
#' interpreted as an integer). This is used to inititalise the L'Ecuyer-CMRG
#' RNG streams sent to each daemon. Note that reproducible results can be
Expand All @@ -64,13 +68,9 @@
#' vector comprising [i] the TLS certificate (optionally certificate chain)
#' and [ii] the associated private key.
#'
#' @return Depending on the arguments supplied:
#'
#' \itemize{
#' \item using dispatcher: integer number of daemons set.
#' \item or else launching local daemons: integer number of daemons launched.
#' \item otherwise: the character host URL.
#' }
#' @return If using dispatcher, the integer number of daemons set, or else the
#' integer number of daemons launched locally (zero if using a remote
#' launcher).
#'
#' @details Use \code{daemons(0)} to reset daemon connections:
#' \itemize{
Expand All @@ -80,8 +80,8 @@
#' \item Any unresolved \sQuote{mirai} will return an \sQuote{errorValue} 19
#' (Connection reset) after a reset.
#' \item Calling \code{daemons} with revised (or even the same) settings for
#' the same compute profile implicitly resets daemons before applying the
#' new settings.
#' the same compute profile resets daemons before applying the new settings
#' if \code{force = TRUE}.
#' }
#'
#' If the host session ends, all connected dispatcher and daemon processes
Expand Down Expand Up @@ -284,7 +284,7 @@
#'
#' @export
#'
daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ...,
daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ..., force = TRUE,
seed = NULL, tls = NULL, pass = NULL, .compute = "default") {

missing(n) && missing(url) && return(status(.compute))
Expand Down Expand Up @@ -373,7 +373,7 @@ daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ...,
`[[<-`(envir, "urls", urld)
}
`[[<-`(.., .compute, `[[<-`(`[[<-`(envir, "sock", sock), "n", n))
} else {
} else if (force) {
daemons(n = 0L, .compute = .compute)
return(daemons(n = n, url = url, remote = remote, dispatcher = dispatcher, ...,
seed = seed, tls = tls, pass = pass, .compute = .compute))
Expand All @@ -382,7 +382,7 @@ daemons <- function(n, url = NULL, remote = NULL, dispatcher = TRUE, ...,
}

is.null(envir) && return(0L)
`class<-`(if (envir[["n"]]) envir[["n"]] else envir[["urls"]], c("miraiDaemons", .compute))
`class<-`(envir[["n"]], c("miraiDaemons", .compute))

}

Expand Down
20 changes: 11 additions & 9 deletions man/daemons.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,17 @@ connection && {
# additional daemons tests
connection && .Platform[["OS.type"]] != "windows" && {
Sys.sleep(1L)
nanotest(daemons(url = value <- local_url(), dispatcher = FALSE) == value)
nanotesti(status()$daemons, nextget("urls"))
nanotestz(daemons(url = value <- local_url(), dispatcher = FALSE))
nanotesti(status()$daemons, value)
nanotesti(nextget("urls"), value)
nanotestz(daemons(0L))
Sys.sleep(1L)
nanotest(is.character(launch_remote("ws://[::1]:5555", remote = remote_config(command = "echo", args = list(c("Test out:", ".", ">/dev/null")), rscript = "/usr/lib/R/bin/Rscript"))))
nanotest(is.character(launch_remote("tcp://localhost:5555", remote = ssh_config(remotes = c("ssh://remotehost", "ssh://remotenode"), tunnel = TRUE, command = "echo"))))
nanotestn(launch_local(local_url(), .compute = "test"))
Sys.sleep(1L)
nanotest(daemons(n = 2L, url = value <- "ws://:0", dispatcher = FALSE, remote = remote_config(quote = TRUE)) != value)
nanotestz(daemons(n = 2L, url = value <- "ws://:0", dispatcher = FALSE, remote = remote_config(quote = TRUE)))
nanotest(status()$daemons != value)
nanotestz(daemons(0L))
Sys.sleep(1L)
m <- with(daemons(1, dispatcher = FALSE, .compute = "ml"), {
Expand Down

0 comments on commit 57e0bc4

Please sign in to comment.