Skip to content

Commit ced1bff

Browse files
nbrOfFreeWorkers() attempts to free up one parallel worker, if possible none are available [#774]
1 parent 2029705 commit ced1bff

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future
2-
Version: 1.58.0-9016
2+
Version: 1.58.0-9017
33
Title: Unified Parallel and Distributed Processing in R for Everyone
44
Depends:
55
R (>= 3.2.0)

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
large number of CPU cores (e.g. 192 and 256 cores) while leaving 16
99
connection slots available for other needs.
1010

11+
## New Features
12+
13+
* `nbrOfFreeWorkers()` attempts to free up one parallel worker in a
14+
non-blocking way, if possible and if none are available.
15+
1116
## Performance
1217

1318
* The pre-validation of the cluster worker allotted to a future when

R/utils_api-nbrOfWorkers.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ nbrOfFreeWorkers.NULL <- function(evaluator, background = FALSE, ...) {
146146
backend <- plan("backend")
147147
if (!inherits(backend, "FutureBackend")) backend <- plan("next")
148148
res <- nbrOfFreeWorkers(backend, background = background, ...)
149+
150+
## Attempt to free up a working, if none are left and possible
151+
if (res == 0L) {
152+
reg <- backend[["reg"]]
153+
if (!is.null(reg)) {
154+
FutureRegistry(reg, action = "collect-first", earlySignal = FALSE)
155+
res0 <- res
156+
res <- nbrOfFreeWorkers(backend, background = background, ...)
157+
if (debug) mdebugf("Freed up %d workers", res - res0)
158+
}
159+
}
160+
149161
res
150162
}
151163

0 commit comments

Comments
 (0)