-
Notifications
You must be signed in to change notification settings - Fork 86
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
Non-block batch assigns #307
Comments
Disclaimer: I haven't really looked at your code, nor have I really taken the time to understand the specifics of your problem. Maybe promises can help solving your issue. |
@nbenn I'm so sorry I didn't state the issue clearly. Is there any way to plan Basically is there any way to run the following code without blocking the main R process? # 4 cores
plan(multicore)
lapply(1:100, function(i){
future::future({
Sys.sleep(3)
return(i)
})
})
print('I am printed out!') |
Hi. No, there's no concept of queuing available in the Future API. As soon as all workers are occupied, where the number depends on your future plan set, the creation of a new future will block and wait for a worker to be freed up. Some flavor of a queuing mechanism could probably be built on top of the Future API, but I don't think it should be part of the core, minimal Future API. Orchestrating queues can be rather complicated and opens up doors for other types of feature requests such as workload balancing etc. It would also require asynchronous processing, i.e. a mechanism for automatically launching queued futures in the background. @nbenn mentioned the 'promises' package, which in turn relies on the 'later' package for async processing. Related: Issue #264 is a feature request on a simpler problem - provide a function for checking if the next future creation will block or not. Even how to implement that might not be obvious because the problem might not be well defined. Hope this helps/clarifies |
@HenrikBengtsson Thanks. I think I'll write my own "promise" function then. I notice that for the new version of
It used to work though. I guess |
I've created Issue #309 separately for this. Please note that the behavior of resetting/shutting down cluster/multisession workers is not new and was not introduced in future 1.13.0; i's been there since future 1.3.0 (2017-01-18). The difference between future 1.12.0 and future 1.13.0 is most likely due to you running RStudio and |
@HenrikBengtsson Does |
No, it'll always be available as long as R/parallel itself supports it. The latest move is just to lowering the risk of using it by mistake. It can always be re-enabled by overriding the default value of option |
I am hoping to standardize promising a Assuming the function in rstudio/promises#60 is called # 4 cores
plan(multicore)
print("start")
fps <- lapply(1:100, function(i){
promises::future_promise({
Sys.sleep(3)
return(i)
})
})
print('I am printed out! 1') # printed immediately
# Add a _then_ statement to the first promise
fps[[1]] %...>% {
print('Process 1 completed!')
}
print('I am printed out! 2') # printed immediately With output looking like:
|
Hi @schloerke this is cool. How do you handle the situation where variables within the environments get changed when future is in the queue? (I'm not the maintainer, just curious) |
|
Sorry @schloerke I wasn't making myself clear. In current implementation, What if the globals contain an environment and the environment is changed during while the future object waits to execute? plan(multisession, workers = 2)
env <- new.env()
env$a <- 1
replicate(3, { future_promise({Sys.sleep(10); env$a })); env$a <- 2 Then what's returned from the third promise? |
Good test! ... Moving conversation to rstudio/promises#60 |
Hi, I have a project which requires loading of ~30GB data (~100 segments with each 300MB) into RAM, which is super time-consuming. The application only requires 5 segment of data to start analysis. I was wondering if future package can support non-blocked batch assignment. Basically lots of
future::futureAssign
in lapply way but non-blocking.Right now if I use
multicore
plan, and set max worker number to be 8, then the 9th future will block the session. However, it could be best if this procedure is non-blocking. I implemented an ugly version usingfuture
andlater
packages, but you must have better idea of doing so.The idea:
The text was updated successfully, but these errors were encountered: