Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run asynchronously #23

Open
slowkow opened this issue Mar 17, 2017 · 6 comments
Open

run asynchronously #23

slowkow opened this issue Mar 17, 2017 · 6 comments
Milestone

Comments

@slowkow
Copy link

slowkow commented Mar 17, 2017

Thanks for this package! It's very easy to use.

I'd like to ask if it's possible to run a job asynchronously, without waiting for the results.

For example, when I run:

job <- Q(fx, x=1:3, n_jobs=1)

I get:

Submitting 1 worker jobs for 3 function calls (ID: 6642) ...
  |======================================================================| 100%
Running calculations (1 calls/chunk) ...
  |                                                                      |   0%
  |======================================================================| 100%
Master: [19.0s 0.0% CPU]; Worker average: [11.7% CPU]

While this message is being printed, I'm unable to continue executing commands. I have to wait for the submitted job to complete before I can continue working.

Is it possible to let R wait in the background, so I can continue working?

@mschubert
Copy link
Owner

Thank you! Always good to hear that my utility code is useful 👍

I'm currently not planning to add this to the package because I think asynchronous computation is a separate problem that is outside of the scope of functionality.

However, you could easily do something like:

fx = function(n) {
    Sys.sleep(n)
    n * 2
}
p = parallel::mcparallel(clustermq::Q(fx, n=1:5, n_jobs=1))
# do your other work ...
parallel::mccollect(p)[[1]]

You may additionally want to suppress the progress bar.

@wlandau
Copy link
Contributor

wlandau commented Jun 28, 2018

Despite the discussions in #86 and futureverse/future#204, I am still interested in an asynchronous Q(). Yes, asynchronicity is a separate problem, and I understand the need to set clear boundaries for the package's scope. But speaking generally, I think the need for asynchronicity arises frequently enough that the major alternatives to clustermq support it:

I am also curious about what it would take. Do we need different socket types? How much would we accomplish if we

  1. Set dont.wait to TRUE in worker(), and
  2. Expose a non-blocking collector in the QSys class?

@wlandau
Copy link
Contributor

wlandau commented Jun 28, 2018

And while a potential clustermq backend for future may give us asynchronicity, I really like the API you have designed natively, both for Q() and the R6 wrapper around reusable workers.

@wlandau
Copy link
Contributor

wlandau commented Aug 27, 2018

I think this is fixed on the develop branch via #86. (But maybe it needs documentation.) Example: https://github.com/ropensci/drake/blob/master/R/clustermq.R#L32-L48.

@mschubert
Copy link
Owner

No, these are unrelated: here is to run Q in the background, there to interface with workers directly

@mschubert
Copy link
Owner

Note: an option would be to create a promise object that will wait for results only explicitly if it is accessed; this could even be result[1:5] waiting only for the first 5

@mschubert mschubert added this to the v0.9.0 milestone Apr 7, 2019
@mschubert mschubert modified the milestones: v0.9.0, v1.0 Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants