Run a plumber API in parallel using valve. Plumber APIs are spawned on
n_threads
asynchronous threads on random ports. Incoming requests are handled
on a single port and redirected to the plumber APIs in a
simple round-robin fashion.
Usage
valve_run(
filepath = "plumber.R",
host = "127.0.0.1",
port = 3000,
n_min = 1,
n_max = 3,
workers = n_max,
check_unused = 10,
max_age = 300
)
Arguments
- filepath
default
"plumber.R"
. The path to the Plumber API. Provided to thefile
argument ofplumber::plumb()
.- host
default
"127.0.0.1"
. Where to host the valve app and Plumber APIs.- port
default
3000
. The port to host the valve app on.- n_min
default
1
. The minimum number of Plumber APIs made available. Must be smaller thann_max
.- n_max
default
3
. The maximum number of Plumber APIs to run in parallel.- workers
default
n_max
. The number of worker threads in the valve app to execute requests. This number should typically mimicn_max
.- check_unused
default
10
. The time interval, in seconds, to check for unused connections.- max_age
default
300
(five minutes). Specifies how long a connection can go unused without being terminated. If a connection reaches this age it will be terminated in the next pool check (interval determined bycheck_unused
),
Examples
if (interactive()) {
plumber_api_path <- system.file("plumber.R", package = "valve")
valve_run(plumber_api_path)
}