future icon indicating copy to clipboard operation
future copied to clipboard

setTimeLimit(): varying results in multicore with failing job

Open r2evans opened this issue 1 year ago • 7 comments

In a multicore plan, if the expression fails (e.g., due to timeout here) then the return from value(.) might be either the error itself (expected) or one of two other failures ("Unexpected result" or "major/minor"). I do not see a pattern in how it varies. Further, when "Unexpected", the worker is not freed.

Other than the preamble, the expression is unchanged, and I tend to reset workers between (but I tried without resetting, does not appear to influence the results).

library(future)
plan(multicore, workers = 3)

nbrOfFreeWorkers()
# [1] 3
thisfut <- future({
  setTimeLimit(elapsed = 2, transient = TRUE)
  Sys.sleep(3)
  1L
})
value(thisfut)
# Error: Unexpected result (of class ‘NULL’ != ‘FutureResult’) retrieved for MulticoreFuture future (label = ‘<none>’, expression = ‘{; setTimeLimit(elapsed = 2, transient = TRUE); Sys.sleep(3); 1L; }’):
nbrOfFreeWorkers()
# [1] 2

nbrOfFreeWorkers()
# [1] 3
thisfut <- future({
  setTimeLimit(elapsed = 2, transient = TRUE)
  Sys.sleep(3)
  1L
})
value(thisfut)
# Error in future::FutureResult(value = ...future.value$value, visible = ...future.value$visible,  :
#   reached elapsed time limit
nbrOfFreeWorkers()
# [1] 3

nbrOfFreeWorkers()
# [1] 3
thisfut <- future({
  setTimeLimit(elapsed = 2, transient = TRUE)
  Sys.sleep(3)
  1L
})
value(thisfut)
# Error in c("major", "minor") %in% names(x) : reached elapsed time limit
nbrOfFreeWorkers()
# [1] 3

It takes several tries to get all three returns. This is in a fresh R instance, nothing else loaded or done between calls.

The first ("Unexpected error") does not automatically free the worker, I must explicitly resetWorkers(plan()) to get it back.

I know there are cautions against using R.utils::withTimeout when coordinating with other processes, which I will infer to be similar-enough to setTimeLimit but not applicable since the timeout is completely within the other process.

sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] future_1.31.0

loaded via a namespace (and not attached):
[1] compiler_4.2.2    parallelly_1.34.0 tools_4.2.2       parallel_4.2.2
[5] listenv_0.9.0     codetools_0.2-18  digest_0.6.31     globals_0.16.2

r2evans avatar Feb 08 '23 15:02 r2evans