wpool_pool (worker_pool v7.0.0)
View SourceTop supervisor for a worker_pool.
This supervisor supervises wpool_process_sup (which is the worker's supervisor) together with
auxiliary servers that help keep the whole pool running and in order.
The strategy of this supervisor must be one_for_all but the intensity and period may be
changed from their defaults by the wpool:pool_sup_intensity() and
wpool:pool_sup_intensity() options respectively.
Summary
API Functions
Adds a callback module.
The module must implement the wpool_process_callbacks behaviour.
Picks the worker with the smaller queue of messages.
Calls all workers in the pool in parallel.
Casts a message to all the workers within the given pool.
Picks the first available worker and sends the call to it.. The timeout provided includes the time it takes to get a worker and for it to process the call.
Casts a message to the first available worker..
Since we can wait forever for a wpool:cast to be delivered
but we don't want the caller to be blocked, this function
just forwards the cast when it gets the worker.
Retrieves the list of worker registered names. This can be useful to manually inspect the workers or do custom work on them.
Picks a worker base on a hash result..
Note that phash2(Term, Range) returns an integer
between 0 (inclusive) and Range (non-inclusive), so 1 must be added.
Set next within the worker pool record. Useful when using. a custom strategy function.
Picks the first available worker, if any.
Picks the next worker in a round robin fashion.
Picks a random worker.
Removes a callback module.
Picks the first available worker and sends the call to it.. The timeout provided includes the time it takes to get a worker and for it to process the call.
Picks the first available worker and sends the request to it. The timeout provided considers only the time it takes to get a worker.
Starts a supervisor with several wpool_processes as its children.
Retrieves the pool stats for all pools.
Retrieves a snapshot of the pool stats.
Get values from the worker pool record. Useful when using a custom. strategy function.
Storage Functions
Use this function to get the Worker pool record in a custom worker.
Types
API Functions
-spec add_callback_module(wpool:name(), module()) -> ok | {error, term()}.
Adds a callback module.
The module must implement the wpool_process_callbacks behaviour.
-spec best_worker(wpool:name()) -> atom().
Picks the worker with the smaller queue of messages.
Throws
no_workers.
-spec broadcall(wpool:name(), term(), timeout()) -> {[Replies :: term()], [Errors :: term()]}.
Calls all workers in the pool in parallel.
Waits for responses in parallel too, and it assumes that if any response times out,
all of them did too and therefore exits with reason timeout like a regular gen_server does.
-spec broadcast(wpool:name(), term()) -> ok.
Casts a message to all the workers within the given pool.
-spec call_available_worker(wpool:name(), term(), timeout()) -> term().
Picks the first available worker and sends the call to it.. The timeout provided includes the time it takes to get a worker and for it to process the call.
Throws
no_workers | timeout.
-spec cast_to_available_worker(wpool:name(), term()) -> ok.
Casts a message to the first available worker..
Since we can wait forever for a wpool:cast to be delivered
but we don't want the caller to be blocked, this function
just forwards the cast when it gets the worker.
-spec get_workers(wpool: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 hash_worker(wpool:name(), term()) -> atom().
Picks a worker base on a hash result..
Note that phash2(Term, Range) returns an integer
between 0 (inclusive) and Range (non-inclusive), so 1 must be added.
Throws
no_workers.
-spec next(pos_integer(), wpool()) -> wpool().
Set next within the worker pool record. Useful when using. a custom strategy function.
-spec next_available_worker(wpool:name()) -> atom().
Picks the first available worker, if any.
Throws
no_workers | no_available_workers.
-spec next_worker(wpool:name()) -> atom().
Picks the next worker in a round robin fashion.
Throws
no_workers.
-spec random_worker(wpool:name()) -> atom().
Picks a random worker.
Throws
no_workers.
-spec remove_callback_module(wpool:name(), module()) -> ok | {error, term()}.
Removes a callback module.
-spec run_with_available_worker(wpool:name(), wpool:run(Result), timeout()) -> Result.
Picks the first available worker and sends the call to it.. The timeout provided includes the time it takes to get a worker and for it to process the call.
Throws
no_workers | timeout.
-spec send_request_available_worker(wpool:name(), term(), timeout()) -> noproc | timeout | gen_server:request_id().
Picks the first available worker and sends the request to it. The timeout provided considers only the time it takes to get a worker.
Throws no_workers | timeout.
-spec start_link(wpool:name(), wpool:options()) -> supervisor:startlink_ret().
Starts a supervisor with several wpool_processes as its children.
-spec stats() -> [wpool:stats()].
Retrieves the pool stats for all pools.
-spec stats(wpool:name()) -> wpool:stats().
Retrieves a snapshot of the pool stats.
Throws
no_workers.
Get values from the worker pool record. Useful when using a custom. strategy function.