Package 'valve'

Title: Redirects Your Plumbing For You
Description: Scales Plumber APIs in parallel on demand. Valve is a Rust library, cli tool, and R package, that spawns plumber APIs in parallel. Valve creates a connection pool of Plumber APIs which are fetched based on availability. Unused connections are terminated. Valve is built using the powerful extendr, tokio, and deadpool libraries.
Authors: Josiah Parry [aut, cre]
Maintainer: Josiah Parry <[email protected]>
License: BSD_3_clause + file LICENSE
Version: 0.1.3
Built: 2024-09-04 04:52:31 UTC
Source: https://github.com/josiahparry/valve

Help Index


Start a valve App

Description

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 the file argument of plumber::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 than n_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 mimic n_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 by check_unused),

Examples

if (interactive()) {
  plumber_api_path <- system.file("plumber.R", package = "valve")
  valve_run(plumber_api_path)
}

Write a Dockerfile for vetiver using valve

Description

A Valve powered vetiver Dockerfile will run prediction endpoints concurrently.

Usage

valve_write_vetiver(
  vetiver_model,
  plumber_file = "plumber.R",
  path = ".",
  port = 8000,
  vetiver_args = list(),
  workers = NULL,
  n_max = NULL,
  check_unused = NULL,
  max_age = NULL
)

Arguments

vetiver_model

A deployable vetiver_model() object

plumber_file

A path for your Plumber file, created via vetiver_write_plumber(). Defaults to plumber.R in the working directory.

path

A path to write the Dockerfile and lockfile, capturing the model's package dependencies. Defaults to the working directory.

port

The server port for listening: a number such as 8080 or an expression like 'as.numeric(Sys.getenv("PORT"))' when the port is injected as an environment variable.

vetiver_args

additional arguments passed to vetiver::vetiver_write_docker() as key-value pairs in a list object.

Details

This function is a modification of vetiver::vetiver_write_docker(). It modifies the created Dockerfile to install Valve, changes the ENTRYPOINT to use the Valve executable instead of a single plumber API via an R command.

Value

The content of the Dockerfile, invisibly.