未来在单核计算机上等待执行 [英] future waits for execution on single-core machine

查看:163
本文介绍了未来在单核计算机上等待执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两台机器,它们具有相同版本的Ubuntu(16.04),R(3.4.4)和将来的软件包(1.10.0).我正在运行下面的代码,该代码实现了异步编程

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()

预期的行为是执行几乎立即结束,从而留下了待定的承诺.在一台机器上发生这种情况,执行立即发生.但是,在我拥有的另一台计算机上,执行将等待mehAsync函数执行,并在5秒钟后完成.

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.

如前所述,两台机器几乎相同.它们之间的主要区别在于,速度较慢的是单核计算机.但是根据我的理解,multisession计划不应要求多个内核.足够的资源来打开计算机具有的新R会话.

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.

这里的具体问题是:

  • 我对预期行为的理解是否错误,这对于单核计算机而言是正常的吗?
  • 我没有考虑的其他哪些因素可能会影响这种行为?
  • 由于没有错误/警告消息并且无法由我本人和其他人复制到独立计算机中,因此如何调试此问题?

注意:尝试调查此其他问题时出现此问题

推荐答案

multisession计划的默认选项在单核计算机上将workers参数设置为availableCores().这意味着如果使用plan时不覆盖参数,则内核数确实很重要.

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.

plan(multisession,workers=2)

解决了这个问题

这篇关于未来在单核计算机上等待执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆