Skip to content

Commit 2d453d9

Browse files
Add explicit **batchtools** arguments scheduler.latency and fs.latency to batchtools backends, where applicable.
1 parent 1873b50 commit 2d453d9

26 files changed

+195
-62
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.2-9927
2+
Version: 0.12.2-9928
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NEWS.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@
2121
* Add `timeout <runtime> ...` to the default `batchtools_bash`
2222
template script to illustrate how to control this runtime via the
2323
backend `resources` argument.
24+
25+
* Add explicit **batchtools** arguments `scheduler.latency` and
26+
`fs.latency` to batchtools backends, where applicable.
2427

2528
## Bug Fixes
2629

27-
* Calling `value()` on a terminated batchtools job could take 65
28-
seconds to return, because it read logged output to be part of the
29-
error message. When there was no output file, **batchtools** would
30-
wait for the file up to 65 seconds to give job schedulers time to
31-
write output to file. Now **future.batchtools** will no longer wait
32-
for such files and only read their content if they exists when
33-
checked.
30+
* Calling `value()` on a terminated batchtools job could take a very
31+
long tiem before it returned with an error. This was because it
32+
read logged output to be part of the error message. When there was
33+
no output file, **batchtools** would wait for the file up to
34+
`fs.latency` seconds (default 65 seconds) to give job schedulers
35+
and any global file system time to write output to file. Now
36+
**future.batchtools** will no longer wait for such files and only
37+
read their content if they exists when checked.
3438

3539

3640
# Version 0.12.2 [2025-06-06]

R/BatchtoolsFutureBackend-class.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,17 +602,18 @@ loggedOutput.BatchtoolsFuture <- function(future, timeout = NULL, ...) {
602602
if (!inherits(reg, "Registry")) return(NULL)
603603
jobid <- config$jobid
604604

605-
local({
605+
out <- local({
606606
if (!is.null(timeout)) {
607607
stopifnot(length(timeout) == 1, is.numeric(timeout), !is.na(timeout), timeout >= 0.0)
608608
oldValue <- reg$cluster.functions$fs.latency
609609
on.exit(reg$cluster.functions$fs.latency <- oldValue)
610610
reg$cluster.functions$fs.latency <- timeout
611611
}
612-
out <- tryCatch(suppressWarnings({
612+
tryCatch(suppressWarnings({
613613
getLog(id = jobid, reg = reg)
614614
}), error = function(e) NULL)
615615
})
616+
616617
out
617618
} # loggedOutput()
618619

@@ -822,7 +823,7 @@ await <- function(future, cleanup = TRUE, ...) {
822823
hint <- c("The last few lines of the logged output:", hint)
823824
hint <- paste(hint, collapse = "\n")
824825
} else {
825-
hint <- "No logged output file exist"
826+
hint <- "No logged output file exist (at the moment)"
826827
}
827828

828829
if (any(c("submitted", "started") %in% stat)) {

R/BatchtoolsTemplateFutureBackend-class.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#' cluster via a job scheduler.
66
#'
77
#' @inheritParams BatchtoolsFutureBackend
8+
#' @inheritParams batchtools::makeClusterFunctions
89
#'
910
#' @param template (optional) A batchtools template file or a template string
1011
#' (in \pkg{brew} format). If not specified, it is left to the
@@ -39,7 +40,7 @@
3940
#' @importFrom batchtools makeClusterFunctionsSlurm
4041
#' @importFrom batchtools makeClusterFunctionsTORQUE
4142
#' @export
42-
BatchtoolsTemplateFutureBackend <- function(..., template = NULL, type = c("lsf", "openlava", "sge", "slurm", "torque")) {
43+
BatchtoolsTemplateFutureBackend <- function(type = c("lsf", "openlava", "sge", "slurm", "torque"), scheduler.latency = 1.0, fs.latency = 65.0, template = NULL, ...) {
4344
assert_no_positional_args_but_first()
4445
type <- match.arg(type)
4546

@@ -67,7 +68,7 @@ BatchtoolsTemplateFutureBackend <- function(..., template = NULL, type = c("lsf"
6768
template <- find_template_file(template)
6869

6970
keep <- which(names(dotdotdot) %in% names(make_cfs_formals))
70-
args <- c(list(template = template), dotdotdot[keep])
71+
args <- c(list(template = template), dotdotdot[keep], scheduler.latency = scheduler.latency, fs.latency = fs.latency)
7172
cluster.functions <- do.call(make_cfs, args = args)
7273
attr(cluster.functions, "template") <- template
7374

R/batchtools_bash.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#' @inheritParams BatchtoolsTemplateFutureBackend
2+
#' @inheritParams batchtools::makeClusterFunctions
3+
#'
24
#' @rdname BatchtoolsFutureBackend
35
#' @keywords internal
46
#'
57
#' @export
68
BatchtoolsBashFutureBackend <- function(...,
7-
cluster.functions = makeClusterFunctionsBash(template = template),
9+
cluster.functions = makeClusterFunctionsBash(template = template, fs.latency = fs.latency),
10+
fs.latency = 0.0,
811
template = "bash") {
912
assert_no_positional_args_but_first()
1013

@@ -63,13 +66,14 @@ BatchtoolsBashFutureBackend <- function(...,
6366
#'
6467
#' @export
6568
batchtools_bash <- function(
66-
cluster.functions = makeClusterFunctionsBash(template = "bash"),
69+
...,
70+
cluster.functions = makeClusterFunctionsBash(template = "bash", fs.latency = fs.latency),
71+
fs.latency = 0.0,
6772
template = "bash",
6873
registry = list(),
6974
conf.file = findConfFile(),
7075
resources = list(),
71-
finalize = getOption("future.finalize", TRUE),
72-
...) {
76+
finalize = getOption("future.finalize", TRUE)) {
7377
stop("INTERNAL ERROR: The future.batchtools::batchtools_bash() must never be called directly")
7478
}
7579
class(batchtools_bash) <- c(
@@ -94,7 +98,7 @@ attr(batchtools_bash, "factory") <- BatchtoolsBashFutureBackend
9498
#' @importFrom batchtools cfReadBrewTemplate cfBrewTemplate makeClusterFunctions makeSubmitJobResult
9599
#' @importFrom utils file_test
96100
#' @export
97-
makeClusterFunctionsBash <- function(template = "bash") {
101+
makeClusterFunctionsBash <- function(template = "bash", fs.latency = 0.0) {
98102
bin <- Sys.which("bash")
99103
stop_if_not(file_test("-f", bin), file_test("-x", bin))
100104

@@ -128,7 +132,8 @@ makeClusterFunctionsBash <- function(template = "bash") {
128132
cf <- makeClusterFunctions(
129133
name = "Bash",
130134
submitJob = submitJob,
131-
store.job.collection = TRUE
135+
store.job.collection = TRUE,
136+
fs.latency = fs.latency
132137
)
133138
attr(cf, "template") <- template
134139
attr(cf, "template_text") <- template_text

R/batchtools_interactive.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#'
44
#' @importFrom batchtools makeClusterFunctionsInteractive
55
#' @export
6-
BatchtoolsInteractiveFutureBackend <- function(...) {
6+
BatchtoolsInteractiveFutureBackend <- function(fs.latency = 0.0, ...) {
77
assert_no_positional_args_but_first()
88

99
core <- BatchtoolsUniprocessFutureBackend(
10-
cluster.functions = makeClusterFunctionsInteractive(external = FALSE),
10+
cluster.functions = makeClusterFunctionsInteractive(fs.latency = fs.latency, external = FALSE),
1111
...
1212
)
1313

@@ -48,7 +48,7 @@ BatchtoolsInteractiveFutureBackend <- function(...) {
4848
#' @inheritParams BatchtoolsInteractiveFutureBackend
4949
#'
5050
#' @export
51-
batchtools_interactive <- function(...) {
51+
batchtools_interactive <- function(..., fs.latency = 0.0) {
5252
stop("INTERNAL ERROR: The future.batchtools::batchtools_interactive() must never be called directly")
5353
}
5454
class(batchtools_interactive) <- c(

R/batchtools_local.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#' Both types of futures will block until the futures are resolved.
99
#'
1010
#' @inheritParams BatchtoolsFutureBackend
11+
#' @inheritParams batchtools::makeClusterFunctions
1112
#'
1213
#' @param \ldots Additional arguments passed to [BatchtoolsFutureBackend()].
1314
#'
@@ -34,11 +35,11 @@
3435
#' @importFrom batchtools makeClusterFunctionsInteractive
3536
#' @aliases BatchtoolsLocalFutureBackend BatchtoolsBashFutureBackend
3637
#' @export
37-
BatchtoolsLocalFutureBackend <- function(...) {
38+
BatchtoolsLocalFutureBackend <- function(fs.latency = 0.0, ...) {
3839
assert_no_positional_args_but_first()
3940

4041
core <- BatchtoolsUniprocessFutureBackend(
41-
cluster.functions = makeClusterFunctionsInteractive(external = TRUE),
42+
cluster.functions = makeClusterFunctionsInteractive(fs.latency = fs.latency, external = TRUE),
4243
...
4344
)
4445

@@ -77,7 +78,7 @@ BatchtoolsLocalFutureBackend <- function(...) {
7778
#' message("Worker process ID: ", pid)
7879
#'
7980
#' @export
80-
batchtools_local <- function(...) {
81+
batchtools_local <- function(..., fs.latency = 0.0) {
8182
stop("INTERNAL ERROR: The future.batchtools::batchtools_local() must never be called directly")
8283
}
8384
class(batchtools_local) <- c(
@@ -88,6 +89,3 @@ attr(batchtools_local, "tweakable") <- c("finalize")
8889
attr(batchtools_local, "untweakable") <- c("workers")
8990
attr(batchtools_local, "init") <- TRUE
9091
attr(batchtools_local, "factory") <- BatchtoolsLocalFutureBackend
91-
92-
93-

R/batchtools_lsf.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ BatchtoolsLsfFutureBackend <- function(...) {
4848
#' * <https://en.wikipedia.org/wiki/IBM_Spectrum_LSF>
4949
#'
5050
#' @export
51-
batchtools_lsf <- function(..., template = "lsf") {
51+
batchtools_lsf <- function(..., template = "lsf", scheduler.latency = 1.0, fs.latency = 65.0) {
5252
stop("INTERNAL ERROR: The future.batchtools::batchtools_lsf() must never be called directly")
5353
}
5454
class(batchtools_lsf) <- c(

R/batchtools_multicore.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#' multicore batchtools futures._
99
#'
1010
#' @inheritParams BatchtoolsFutureBackend
11+
#' @inheritParams batchtools::makeClusterFunctions
1112
#'
1213
#' @param workers The number of multicore processes to be
1314
#' available for concurrent batchtools multicore futures.
@@ -31,7 +32,7 @@
3132
#' @importFrom parallelly availableCores supportsMulticore
3233
#' @importFrom tools pskill
3334
#' @export
34-
BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraints = "multicore"), ...) {
35+
BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraints = "multicore"), fs.latency = 0.0, ...) {
3536
assert_no_positional_args_but_first()
3637

3738
if (is.function(workers)) workers <- workers()
@@ -46,13 +47,13 @@ BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraint
4647

4748
## Fall back to batchtools_local if multicore processing is not supported
4849
if ((workers == 1L && !inherits(workers, "AsIs")) || !supportsMulticore(warn = TRUE)) {
49-
return(BatchtoolsLocalFutureBackend(...))
50+
return(BatchtoolsLocalFutureBackend(..., fs.latency = fs.latency))
5051
}
5152

5253
oopts <- options(mc.cores = workers)
5354
on.exit(options(oopts))
5455

55-
cluster.functions <- makeClusterFunctionsMulticore(ncpus = workers)
56+
cluster.functions <- makeClusterFunctionsMulticore(ncpus = workers, fs.latency = fs.latency)
5657
cluster.functions$killJob <- function(reg, batch.id) {
5758
pid <- as.integer(batch.id)
5859
if (is.na(pid) || pid <= 0) return(FALSE)
@@ -96,7 +97,7 @@ BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraint
9697
#' message("Worker process ID: ", pid)
9798
#'
9899
#' @export
99-
batchtools_multicore <- function(..., workers = availableCores(constraints = "multicore")) {
100+
batchtools_multicore <- function(..., workers = availableCores(constraints = "multicore"), fs.latency = 0.0) {
100101
stop("INTERNAL ERROR: The future.batchtools::batchtools_multicore() must never be called directly")
101102
}
102103
class(batchtools_multicore) <- c(

R/batchtools_openlava.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ BatchtoolsOpenLavaFutureBackend <- function(...) {
4848
#' * <https://en.wikipedia.org/wiki/OpenLava>
4949
#'
5050
#' @export
51-
batchtools_openlava <- function(..., template = "openlava") {
51+
batchtools_openlava <- function(..., template = "openlava", scheduler.latency = 1.0, fs.latency = 65.0) {
5252
stop("INTERNAL ERROR: The future.batchtools::batchtools_openlava() must never be called directly")
5353
}
5454
class(batchtools_openlava) <- c(

0 commit comments

Comments
 (0)