future waits for execution on single-core machine

别等时光非礼了梦想. 提交于 2019-12-14 02:35:48

问题


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:

  • Is my understanding of the expected behaviour wrong and this is normal for a single core machine?
  • What other factors that I am not taking into account could be effecting this behaviour?
  • 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?

Note: this question came up when trying to investigate this other question


回答1:


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



来源:https://stackoverflow.com/questions/52865362/future-waits-for-execution-on-single-core-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!