-
Notifications
You must be signed in to change notification settings - Fork 14
Description
@shikokuchuo , thank you so much for the wonderful contribution to the R community. Bravo!
I'm not sure this is really an issue. I pose a question at the bottom and provide a short reprex with code & commands at the end.
Please forgive the verbosity, but let me set up the context first. I noticed you'd recently added support for make_cluster()
, and so I'd hoped that this could be a drop-in replacement for my persistent parallelly
PSOCK clusters I've been using for a very involved high-performance R endpoint solution I've written. Due to very specific requirements and heavy initialization, the cluster must be persistent (i.e., future::plan(cluster, workers = cl, persistent = TRUE)
. To be clear, calling that line with a mirai cluster has no issues. I'll also mention that I've used daemons()
with the promises::future_promise()
wrappers rather extensively without any issue at all (and with remarkable speed improvements). Unfortunately, when I swap out the clusters in my solution, I get various errors and warnings with the most relevant being: Warning: resolved() is not yet implemented for workers of class ‘miraiNode’. Will use value() instead and return TRUE
.
I realize this is not coming from your package; however, it seems you and Henrik have been working together very closely. My question is: Am I trying to use the mirai cluster feature inappropriately? (i.e., inappropriate with respect to your design and plans for the feature). If so, then my apologies and absolutely no worries. You've done us all a tremendously good service already. mirai
provides very low latency in all of the places I've used it. Thank you
reprex
plumber.R - swap comments on lines 2 and 3 to toggle PSOCK and mirai cluster
core.cnt <- parallelly::availableCores(logical = FALSE)
# cl <- mirai::make_cluster(n = core.cnt)
cl <- parallelly::makeClusterPSOCK(workers = core.cnt, autoStop = TRUE)
future::plan(cluster, workers = cl, persistent = TRUE)
#* @post /lollygag
lollygag <- function(req, res) {
result <- promises::future_promise({
if (jsonlite::fromJSON(req$postBody)$speed == "fast") {
Sys.sleep(0.1)
} else {
Sys.sleep(10)
}
return(list(status = 200L, body = list(thread_id = Sys.getpid())))
}, seed = TRUE, stdout = FALSE, globals = c("req", "res")) %...>% (function(result) {
res$status <- result$status
res$body <- result$body
})
}
launch it
router <- plumber::plumb("plumber.R")
plumber::pr_run(router, port = 8080)
test with curl
or tool of choice
seq 1 8 | xargs -I $ -n1 -P4 curl -w"\n" -X POST "http://127.0.0.1:8080/lollygag" -H "accept: application/json" -d '{"speed": "slow"}'