Replies: 2 comments 20 replies
-
Re throttling: I had hoped the example below would write a new file every second, but I see no files being written. library(mirai)
library(nanonext)
f <- function() {
if (!is.finite(later::next_op_secs())) {
later::later(
func = \() writeLines(as.character(Sys.time()), basename(tempfile())),
delay = 1
)
}
}
daemons(n = 2L, url = "ws://127.0.0.1:5700", ext = list(f, expression(f())))
now <- mclock()
while (mclock() - now < 3e4) {
task <- mirai("task")
msleep(10)
}
daemons(0L) From the
That's probably the reason. But maybe I can live without throttling if the launcher logic is fast enough. The original motivation was that in order to know how many new workers to launch, |
Beta Was this translation helpful? Give feedback.
-
A couple of things:
|
Beta Was this translation helpful? Give feedback.
-
@shikokuchuo, I finally had a free moment to try the extended R dispatcher you sketched in https://github.com/shikokuchuo/mirai/tree/dispatcher. Really promising stuff! Just writing in to share my initial thoughts and requests.
Data
The
crew
launcher is anR6
object. Is there a way to send this object to theext
argument along with the function and its call? I tried to ship data in the closure of the function, but in the example below,f_data
does not go along for the ride.Launching
crew
uses information about the current task backlog to decide if it should launch workers, as well as how many workers to launch. I think the extended R dispatcher is a great opportunity to simplify the logic of this. Is there a way to get the number of tasks that have not yet been dispatched? Also, the existingserverfree
vector looks useful. Is itFALSE
if the server is currently running a task andTRUE
otherwise?I ran some simple code to see my options:
Output below:
Throttling
For performance, I would like to avoid calling the
crew
launcher every time the dispatcher wakes up. I was thinking of usinglater
to implement a custom throttling mechanism:later
to schedule thecrew
launcher to run e.g. 0.25 seconds later.later
main loop run thecrew
launcher at the 0.25-second mark.I haven't experimented with this part just yet, but I was wondering if you see any pitfalls at this stage.
Beta Was this translation helpful? Give feedback.
All reactions