View Source wpool (worker_pool v6.1.0)

Worker pool main interface. Use functions provided by this module to manage your pools of workers

Link to this section Summary

Functions

Casts a message to all the workers within the given pool.
Picks a server and issues the call to it. For all strategies except available_worker, Timeout applies only to the time spent on the actual call to the worker, because time spent finding the worker in other strategies is negligible. For available_worker the time used choosing a worker is also considered
Picks a server and issues the cast to it
Default strategy
Retrieves the list of worker registered names. This can be useful to manually inspect the workers or do custom work on them.
Picks a server and issues the call to it. Timeout applies only for the time used choosing a worker in the available_worker strategy
Starts the application
Starts (and links) a pool of N wpool_processes. The result pid belongs to a supervisor (in case you want to add it to a supervisor tree)
Starts a pool of N wpool_processes supervised by wpool_sup
Retrieves a snapshot of the pool stats
Retrieves a snapshot of a given pool stats
Stops the application
Stops the pool
Stops the pool

Link to this section Types

-type custom_strategy() :: fun(([atom()]) -> Atom :: atom()).
-type debug_flag() :: trace | log | statistics | debug | {logfile, string()}.
-type gen_option() ::
    {timeout, timeout()} | {debug, [debug_flag()]} | {spawn_opt, [proc_lib:spawn_option()]}.
-type gen_options() :: [gen_option()].
-type name() :: atom().
-type option() ::
    {overrun_warning, infinity | pos_integer()} |
    {max_overrun_warnings, infinity | pos_integer()} |
    {overrun_handler, {Module :: atom(), Fun :: atom()}} |
    {workers, pos_integer()} |
    {worker_opt, gen_options()} |
    {worker, {Module :: atom(), InitArg :: term()}} |
    {strategy, supervisor_strategy()} |
    {worker_type, gen_server} |
    {pool_sup_intensity, non_neg_integer()} |
    {pool_sup_shutdown, brutal_kill | timeout()} |
    {pool_sup_period, non_neg_integer()} |
    {queue_type, wpool_queue_manager:queue_type()} |
    {enable_callbacks, boolean()} |
    {callbacks, [module()]}.
-type stats() ::
    [{pool, name()} |
     {supervisor, pid()} |
     {options, [option()]} |
     {size, non_neg_integer()} |
     {next_worker, pos_integer()} |
     {total_message_queue_len, non_neg_integer()} |
     {workers, [{pos_integer(), worker_stats()}]}].
-type strategy() ::
    best_worker | random_worker | next_worker | available_worker | next_available_worker |
    {hash_worker, term()} |
    custom_strategy().
-type supervisor_strategy() :: {supervisor:strategy(), non_neg_integer(), pos_integer()}.
-type worker_stats() :: [{messsage_queue_len, non_neg_integer()} | {memory, pos_integer()}].

Link to this section Functions

-spec broadcast(wpool:name(), term()) -> ok.
Casts a message to all the workers within the given pool.
-spec call(name(), term()) -> term().

Equivalent to call(Sup, Call, default_strategy()).

Link to this function

call(Sup, Call, Strategy)

View Source
-spec call(name(), term(), strategy()) -> term().

Equivalent to call(Sup, Call, Strategy, 5000).

Link to this function

call(Sup, Call, Fun, Timeout)

View Source
-spec call(name(), term(), strategy(), timeout()) -> term().
Picks a server and issues the call to it. For all strategies except available_worker, Timeout applies only to the time spent on the actual call to the worker, because time spent finding the worker in other strategies is negligible. For available_worker the time used choosing a worker is also considered
-spec cast(name(), term()) -> ok.

Equivalent to cast(Sup, Cast, default_strategy()).

-spec cast(name(), term(), strategy()) -> ok.
Picks a server and issues the cast to it
-spec default_strategy() -> strategy().
Default strategy
-spec get_workers(name()) -> [atom()].
Retrieves the list of worker registered names. This can be useful to manually inspect the workers or do custom work on them.
-spec send_request(name(), term()) -> noproc | timeout | gen_server:request_id().

Equivalent to send_request(Sup, Call, default_strategy(), 5000).

Link to this function

send_request(Sup, Call, Strategy)

View Source
-spec send_request(name(), term(), strategy()) -> noproc | timeout | gen_server:request_id().

Equivalent to send_request(Sup, Call, Strategy, 5000).

Link to this function

send_request(Sup, Call, Fun, Timeout)

View Source
-spec send_request(name(), term(), strategy(), timeout()) -> noproc | timeout | gen_server:request_id().
Picks a server and issues the call to it. Timeout applies only for the time used choosing a worker in the available_worker strategy
-spec start() -> ok | {error, {already_started, wpool}}.
Starts the application
-spec start_pool(name()) -> {ok, pid()}.

Equivalent to start_pool(Name, []).

Link to this function

start_pool(Name, Options)

View Source
-spec start_pool(name(), [option()]) -> {ok, pid()} | {error, {already_started, pid()} | term()}.
Starts (and links) a pool of N wpool_processes. The result pid belongs to a supervisor (in case you want to add it to a supervisor tree)
-spec start_sup_pool(name()) -> {ok, pid()} | {error, {already_started, pid()} | term()}.

Equivalent to start_sup_pool(Name, []).

Link to this function

start_sup_pool(Name, Options)

View Source
-spec start_sup_pool(name(), [option()]) -> {ok, pid()} | {error, {already_started, pid()} | term()}.
Starts a pool of N wpool_processes supervised by wpool_sup
-spec stats() -> [stats()].
Retrieves a snapshot of the pool stats
-spec stats(name()) -> stats().
Retrieves a snapshot of a given pool stats
-spec stop() -> ok.
Stops the application
-spec stop_pool(name()) -> true.
Stops the pool
-spec stop_sup_pool(name()) -> ok.
Stops the pool