
Question:
I have 2 machines with identical versions of Ubuntu (16.04), R (3.4.4) and the future package (1.10.0). I am running the code below, that implements asyncronous programming
tic()
library(future)
plan(multisession)
mehAsync = function(){
future::future({
Sys.sleep(5)
return('meh')
})
}
out = mehAsync()
what = then(out,function(value){(value)})
toc()
The expected behaviour is that the execution will end almost instantly, leaving what to be a pending promise. In one machine this happens, the execution happens instantly. However in another machine I have, the execution waits for the mehAsync function to execute, finishing after 5 seconds.
As stated before, both machines are almost identical. The key difference between them is that the slower one is a single core machine. However based on my understanding, the multisession
plan shouldn't require multiple cores. Just enough resources to open a new R session which the machine has.
The specific questions here are:
<ul><li>Is my understanding of the expected behaviour wrong and this is normal for a single core machine?</li> <li>What other factors that I am not taking into account could be effecting this behaviour?</li> <li>How can I debug this issue as there are no error/warning messages and can't be replicated by myself and other people in independent machines?</li> </ul>Note: this question came up when trying to investigate <a href="https://stackoverflow.com/questions/52864035/asynchronous-shiny-programming-setting-up-a-basic-example" rel="nofollow">this other question</a>
Answer1:The default options for the multisession
plan sets the workers
parameters to availableCores()
in a single core machine. Which means if one does not override the parameters when using plan
, the number of cores does matter.
Doing
plan(multisession,workers=2)
solves this issue