Skip to content

Commit 4ca72b4

Browse files
committed
Rename function -> capacity()
1 parent 0626281 commit 4ca72b4

9 files changed

Lines changed: 26 additions & 26 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ export(.flat)
2828
export(.progress)
2929
export(.stop)
3030
export(call_mirai)
31+
export(capacity)
3132
export(cluster_config)
3233
export(collect_mirai)
3334
export(daemon)
3435
export(daemons)
3536
export(daemons_set)
36-
export(dispatcher_capacity)
3737
export(everywhere)
3838
export(host_url)
3939
export(http_config)

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Dispatcher reimplemented as a thread for lower overhead, removing the separate dispatcher process (#581).
66
* Adds `capacity` argument to `daemons()` setting a memory budget (MB, metric) for queued task payloads at dispatcher, providing memory-based backpressure.
77
This is opt-in and `NULL` (default) is unbounded (thanks @t-kalinowski, #454).
8-
* Adds `dispatcher_capacity()` to query current and peak queued bytes (in MB) against the `capacity` budget.
8+
* Adds `capacity()` to query current and peak queued bytes (in MB) against the `capacity` budget.
99
* Adds `try_mirai()`, a non-blocking variant of `mirai()` that returns `NULL` immediately if the dispatcher's `capacity` budget is exhausted, instead of blocking.
1010
Useful in event-loop contexts (Shiny, promises) where blocking the host R thread is unacceptable.
1111

R/daemons.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#' argument caps the approximate total memory (MB, metric — 1 MB = 1,000,000
8484
#' bytes) of queued task payloads at dispatcher. New tasks block until existing
8585
#' ones are dispatched, providing memory-based backpressure to prevent host
86-
#' OOM. Current usage is surfaced via [dispatcher_capacity()].
86+
#' OOM. Current usage is surfaced via [capacity()].
8787
#' Dispatcher also enables (i) mirai cancellation using [stop_mirai()] or a
8888
#' `.timeout` argument to [mirai()], and (ii) custom serialization
8989
#' configurations.
@@ -373,7 +373,7 @@ status <- function(.compute = NULL) {
373373
list(connections = as.integer(stat(envir[["sock"]], "pipes")), daemons = envir[["url"]])
374374
}
375375

376-
#' Dispatcher Capacity
376+
#' Capacity
377377
#'
378378
#' Retrieve the approximate current and peak memory used by queued task
379379
#' payloads at dispatcher, in MB (metric, 1 MB = 1,000,000 bytes), to monitor
@@ -389,13 +389,13 @@ status <- function(.compute = NULL) {
389389
#' @examplesIf interactive()
390390
#' daemons(1, capacity = 100)
391391
#' m <- mirai(Sys.sleep(0.5))
392-
#' dispatcher_capacity()
392+
#' capacity()
393393
#' m[]
394394
#' daemons(0)
395395
#'
396396
#' @export
397397
#'
398-
dispatcher_capacity <- function(.compute = NULL) {
398+
capacity <- function(.compute = NULL) {
399399
envir <- compute_env(.compute)
400400
(is.null(envir) || is.null(envir[["dispatcher"]])) && return()
401401
.dispatcher_capacity(envir[["dispatcher"]])

dev/vignettes/_v01-reference.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ The default `dispatcher = TRUE` enables optimal FIFO scheduling.
207207
Tasks queue at the dispatcher and send to daemons as they become available.
208208
The `capacity` argument caps the approximate total memory (MB, metric — 1 MB = 1,000,000 bytes) of queued task payloads at dispatcher.
209209
New tasks block until existing ones are dispatched, providing memory-based backpressure to prevent host OOM.
210-
Current usage is surfaced via the `dispatcher_capacity()` accessor (returns MB, matching the `capacity` unit).
210+
Current usage is surfaced via the `capacity()` accessor (returns MB, matching the `capacity` unit).
211211
It also enables mirai cancellation via `stop_mirai()` or the `.timeout` argument to `mirai()`.
212212

213213
`info()` provides current statistics as an integer vector:
Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/daemons.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgdown/_pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ reference:
3939
- title: Compute Profiles
4040
contents:
4141
- info
42-
- dispatcher_capacity
42+
- capacity
4343
- daemons_set
4444
- require_daemons
4545
- with_daemons

tests/tests.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,14 @@ connection && NOT_CRAN && {
360360
}
361361
# capacity tests
362362
connection && NOT_CRAN && {
363-
# dispatcher_capacity() returns NULL when no profile / no dispatcher
364-
test_null(dispatcher_capacity())
363+
# capacity() returns NULL when no profile / no dispatcher
364+
test_null(capacity())
365365
test_true(daemons(1, dispatcher = FALSE))
366-
test_null(dispatcher_capacity())
366+
test_null(capacity())
367367
test_false(daemons(0L))
368368
# Unlimited: capacity = NULL → used/peak zero, capacity reported as NA
369369
test_true(daemons(1, capacity = NULL))
370-
qs <- dispatcher_capacity()
370+
qs <- capacity()
371371
test_type("double", qs)
372372
test_equal(length(qs), 3L)
373373
test_zero(qs[["used"]])
@@ -378,30 +378,30 @@ connection && NOT_CRAN && {
378378
for (cap in list(0, -1, NA_real_, Inf)) {
379379
test_true(daemons(1, capacity = cap))
380380
test_equal(collect_mirai(mirai(1L + 1L)), 2L)
381-
test_identical(dispatcher_capacity()[["capacity"]], NA_real_)
381+
test_identical(capacity()[["capacity"]], NA_real_)
382382
test_false(daemons(0L))
383383
}
384384
# Queue accumulates with no daemon connected; peak retained after drain.
385385
# Verifying via peak (monotonic high-watermark) after drain is robust to
386386
# cross-thread visibility latency in queue accounting.
387387
test_true(daemons(url = local_url(), capacity = 1))
388388
m1 <- mirai(Sys.sleep(0.1))
389-
while (dispatcher_capacity()[["used"]] == 0) Sys.sleep(0.05)
389+
while (capacity()[["used"]] == 0) Sys.sleep(0.05)
390390
launch_local(1L)
391391
test_null(call_mirai(m1)$data)
392-
while (dispatcher_capacity()[["used"]] > 0) Sys.sleep(0.05)
393-
qs <- dispatcher_capacity()
392+
while (capacity()[["used"]] > 0) Sys.sleep(0.05)
393+
qs <- capacity()
394394
test_zero(qs[["used"]])
395395
test_true(qs[["peak"]] > 0)
396396
test_equal(qs[["capacity"]], 1)
397397
test_false(daemons(0L))
398398
# Cancel clears used bytes; peak still reflects prior occupancy.
399399
test_true(daemons(url = local_url(), capacity = 1))
400400
m <- mirai(Sys.sleep(0.1))
401-
while (dispatcher_capacity()[["used"]] == 0) Sys.sleep(0.05)
401+
while (capacity()[["used"]] == 0) Sys.sleep(0.05)
402402
test_true(stop_mirai(m))
403-
while (dispatcher_capacity()[["used"]] > 0) Sys.sleep(0.05)
404-
qs <- dispatcher_capacity()
403+
while (capacity()[["used"]] > 0) Sys.sleep(0.05)
404+
qs <- capacity()
405405
test_zero(qs[["used"]])
406406
test_true(qs[["peak"]] > 0)
407407
test_false(daemons(0L))

vignettes/v01-reference.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ The default `dispatcher = TRUE` enables optimal FIFO scheduling.
226226
Tasks queue at the dispatcher and send to daemons as they become available.
227227
The `capacity` argument caps the approximate total memory (MB, metric — 1 MB = 1,000,000 bytes) of queued task payloads at dispatcher.
228228
New tasks block until existing ones are dispatched, providing memory-based backpressure to prevent host OOM.
229-
Current usage is surfaced via the `dispatcher_capacity()` accessor (returns MB, matching the `capacity` unit).
229+
Current usage is surfaced via the `capacity()` accessor (returns MB, matching the `capacity` unit).
230230
It also enables mirai cancellation via `stop_mirai()` or the `.timeout` argument to `mirai()`.
231231

232232
`info()` provides current statistics as an integer vector:

0 commit comments

Comments
 (0)