View Source FLAME.Pool (flame v0.5.1)
Manages a pool of FLAME.Runner
processes.
Pools support elastic growth and shrinking of the number of runners.
Examples
children = [
...,
{FLAME.Pool, name: MyRunner, min: 1, max: 10, max_concurrency: 100}
]
See start_link/1
for supported options.
TODO
[ ] interface to configure min/max at runtime
Summary
Functions
Calls a function in a remote runner for the given FLAME.Pool
.
Casts a function to a remote runner for the given FLAME.Pool
.
Returns a specification to start this module under a supervisor.
See FLAME.place_child/3
for more information.
Starts a pool of runners.
Functions
Calls a function in a remote runner for the given FLAME.Pool
.
See FLAME.call/3
for more information.
Casts a function to a remote runner for the given FLAME.Pool
.
See FLAME.cast/3
for more information.
Returns a specification to start this module under a supervisor.
See Supervisor
.
See FLAME.place_child/3
for more information.
Starts a pool of runners.
Options
:name
- The name of the pool, for example:MyApp.FFMPegRunner
:min
- The minimum number of runners to keep in the pool at all times. For "scale to zero" behavior you may pass0
. When starting as a flame child, the:min
will be forced to zero to avoid recursively starting backend resources.:max
- The maximum number of runners to elastically grow to in the pool.:max_concurrency
- The maximum number of concurrent executions per runner before booting new runners or queueing calls. Defaults to100
.:single_use
- iftrue
, runners will be terminated after each call completes. Defaultsfalse
.:backend
- The backend to use. Defaults to the configured:flame, :backend
orFLAME.LocalBackend
if not configured.:log
- The log level to use for verbose logging. Defaults tofalse
.:timeout
- The time to allow functions to execute on a remote node. Defaults to 30 seconds. This value is also used as the defaultFLAME.call/3
timeout for the caller.:boot_timeout
- The time to allow for booting and connecting to a remote node. Defaults to 30 seconds.:shutdown_timeout
- The time to allow for graceful shutdown on the remote node. Defaults to 30 seconds.:idle_shutdown_after
- The amount of time and function check to idle a remote node down after a period of inactivity. Defaults to 30 seconds. A tuple may also be passed to check a specific condition, for example:{10_000, fn -> Supervisor.which_children(MySup) == []}
:min_idle_shutdown_after
- The same behavior of:idle_shutdown_after
, but applied to the the:min
pool runners. Defaults to:infinity
.:on_grow_start
- The optional function to be called when the pool starts booting a new runner beyond the configured:min
. The function receives a map with the following metadata::name
- The name of the pool:count
- The number of runners the pool is attempting to grow to:pid
- The pid of the async process that is booting the new runner
:on_grow_end
- The optional 2-arity function to be called when the pool growth process completes. The 2-arity function receives either:ok
or{:exit, reason}
, and map with the following metadata::name
- The name of the pool:count
- The number of runners the pool is now at:pid
- The pid of the async process that attempted to boot the new runner
:on_shrink
- The optional function to be called when the pool shrinks. The function receives a map with the following metadata::name
- The name of the pool:count
- The number of runners the pool is attempting to shrink to
:track_resources
- When true, traverses the returned results from FLAME operations looking for resources that implement theFLAME.Trackable
protocol and make sure the FLAME node does not terminate until the tracked resources are removed. Defaultsfalse
.:code_sync
– The optional list of options to enable copying and syncing code paths from the parent node to the runner node. Disabled by default. The options are::start_apps
– Either a boolean or a list of specific OTP application names to start when the runner boots. Whentrue
, all applications currently running on the parent node are sent to the runner node to be started. Defaults tofalse
. When set totrue
,copy_apps
will also be set totrue
if not explicitly set tofalse
.:copy_apps
– The boolean flag to copy all the application artifacts and their beam files from the parent node to the runner node on boot. Defaultsfalse
. When passingstart_apps: true
, automatically setscopy_paths: true
.:copy_paths
– The list of arbitrary paths to copy from the parent node to the runner node on boot. Defaults to[]
.:sync_beams
– A list of specific beam code paths to sync to the runner node. Useful when you want to sync specific beam code paths from the parent after sending all code paths from:copy_apps
on initial boot. For example, withcopy_apps: true
, andsync_beams: ["/home/app/.cache/.../ebin"]
, all the code from the parent will be copied on boot, but only the specific beam files will be synced on subsequent calls. Withcopy_apps: false
, andsync_beams: ["/home/app/.cache/.../ebin"]
, only the specific beam files will be synced on boot and for subsequent calls. Defaults to[]
.:verbose
– Iftrue
, the pool will log verbose information about the code sync process. Defaults tofalse
.:compress
– Iftrue
, the copy_apps, copy_paths, and sync_beams will be compressed before sending. Provides savings in network payload size at the cost of CPU time. Defaults totrue
.
For example, in Livebook, to start a pool with code sync enabled:
Mix.install([:kino, :flame]) Kino.start_child!( {FLAME.Pool, name: :my_flame, code_sync: [ start_apps: true, sync_beams: [Path.join(System.tmp_dir!(), "livebook_runtime")] ], min: 1, max: 1, max_concurrency: 10, backend: {FLAME.FlyBackend, cpu_kind: "performance", cpus: 4, memory_mb: 8192, token: System.fetch_env!("FLY_API_TOKEN"), env: Map.take(System.get_env(), ["LIVEBOOK_COOKIE"]), }, idle_shutdown_after: :timer.minutes(5)} )