Module pooler

This is the main interface to the pooler application.

Copyright © 2011-2013 Seth Falcon

Behaviours: gen_server.

Authors: Seth Falcon (seth@userprimary.net).

Description

This is the main interface to the pooler application

To integrate with your application, you probably want to call application:start(pooler) after having specified appropriate configuration for the pooler application (either via a config file or appropriate calls to the application module to set the application's config).

Function Index

accept_member/2For INTERNAL use.
call_free_members/2Invokes Fun with arity 1 over all free members in pool with PoolName.
call_free_members/3Invokes Fun with arity 1 over all free members in pool with PoolName.
code_change/3
handle_call/3
handle_cast/2
handle_info/2
init/1
manual_start/0
new_pool/1Start a new pool described by the proplist PoolConfig.
pool_child_spec/1Get child spec described by the proplist PoolConfig.
pool_stats/1Obtain runtime state info for all pools.
pool_utilization/1Obtain utilization info for a pool.
return_group_member/2Return a member that was taken from the group GroupName.
return_group_member/3Return a member that was taken from the group GroupName.
return_member/2Return a member to the pool so it can be reused.
return_member/3Return a member to the pool so it can be reused.
rm_group/1Terminates the group and all pools in that group.
rm_pool/1Terminate the named pool.
start/0
start_link/1
stop/0
take_group_member/1Take a member from a randomly selected member of the group GroupName.
take_member/1Obtain exclusive access to a member from PoolName.
take_member/2Obtain exclusive access to a member of 'PoolName'.
terminate/2

Function Details

accept_member/2

accept_member(PoolName::atom() | pid(), MemberPid::pid() | {noproc, term()}) -> ok

For INTERNAL use. Adds MemberPid to the pool.

call_free_members/2

call_free_members(PoolName::atom() | pid(), Fun::fun((pid()) -> term())) -> Res

Invokes Fun with arity 1 over all free members in pool with PoolName.

call_free_members/3

call_free_members(PoolName::atom() | pid(), Fun, Timeout::timeout()) -> Res

Invokes Fun with arity 1 over all free members in pool with PoolName. Timeout sets the timeout of gen_server call.

code_change/3

code_change(OldVsn::term(), State::term(), Extra::term()) -> {ok, term()}

handle_call/3

handle_call(Request, From, Pool) -> any()

handle_cast/2

handle_cast(Msg::term(), Pool::term()) -> {noreply, term()}

handle_info/2

handle_info(Info::term(), Pool::term()) -> {noreply, term()}

init/1

init(Pool::#pool{}) -> {ok, #pool{}, 0}

manual_start/0

manual_start() -> any()

new_pool/1

new_pool(PoolConfig) -> any()

Start a new pool described by the proplist PoolConfig. The following keys are required in the proplist:

name
An atom giving the name of the pool.
init_count
Number of members to add to the pool at start. When the pool is started, init_count members will be started in parallel.
max_count
Maximum number of members in the pool.
start_mfa
A tuple of the form {Mod, Fun, Args} describing how to start new pool members.

In addition, you can specify any of the following optional configuration options:

group
An atom giving the name of the group this pool belongs to. Pools sharing a common group value can be accessed using take_group_member/1 and return_group_member/2.
cull_interval
Time between checks for stale pool members. Specified as {Time, Unit} where Time is a non-negative integer and Unit is one of min, sec, ms, or mu. The default value of {1, min} triggers a once per minute check to remove members that have not been accessed in max_age time units. Culling can be disabled by specifying a zero time vaule (e.g. {0, min}. Culling will also be disabled if init_count is the same as max_count.
max_age
Members idle longer than max_age time units are removed from the pool when stale checking is enabled via cull_interval. Culling of idle members will never reduce the pool below init_count. The value is specified as {Time, Unit}. Note that timers are not set on individual pool members and may remain in the pool beyond the configured max_age value since members are only removed on the interval configured via cull_interval. The default value is {30, sec}.
member_start_timeout
Time limit for member starts. Specified as {Time, Unit}. Defaults to {1, min}.

pool_child_spec/1

pool_child_spec(PoolConfig::[{atom(), term()}]) -> supervisor:child_spec()

Get child spec described by the proplist PoolConfig.

See pooler:new_pool/1 for info about PoolConfig.

pool_stats/1

pool_stats(PoolName::atom() | pid()) -> [tuple()]

Obtain runtime state info for all pools.

Format of the return value is subject to change.

pool_utilization/1

pool_utilization(PoolName::atom() | pid()) -> [{atom(), integer()}]

Obtain utilization info for a pool.

Format of the return value is subject to change, but for now it will be a proplist to maintain backcompat with R16.

return_group_member/2

return_group_member(GroupName::atom(), MemberPid::pid() | error_no_members) -> ok

Return a member that was taken from the group GroupName. This is a convenience function for return_group_member/3 with Status of ok.

return_group_member/3

return_group_member(GroupName::atom(), MemberPid::pid() | error_no_members, Status::ok | fail) -> ok

Return a member that was taken from the group GroupName. If Status is ok the member is returned to the pool from which is came. If Status is fail the member will be terminated and a new member added to the appropriate pool.

return_member/2

return_member(PoolName::atom() | pid(), Pid::pid() | error_no_members) -> ok

Return a member to the pool so it can be reused.

return_member/3

return_member(PoolName::atom() | pid(), Pid::pid() | error_no_members, Status::ok | fail) -> ok

Return a member to the pool so it can be reused.

If Status is 'ok', the member is returned to the pool. If Status is 'fail', the member is destroyed and a new member is added to the pool in its place.

rm_group/1

rm_group(GroupName::atom()) -> ok | {error, {failed_rm_pools, [atom()]}}

Terminates the group and all pools in that group.

If termination of any member pool fails, rm_group/1 returns {error, {failed_delete_pools, Pools}}, where Pools is a list of pools that failed to terminate.

The group is NOT terminated if any member pool did not successfully terminate.

rm_pool/1

rm_pool(PoolName) -> any()

Terminate the named pool.

start/0

start() -> ok

start_link/1

start_link(Pool) -> any()

stop/0

stop() -> ok

take_group_member/1

take_group_member(GroupName::atom()) -> pid() | error_no_members | {error_no_group, atom()}

Take a member from a randomly selected member of the group GroupName. Returns MemberPid or error_no_members. If no members are available in the randomly chosen pool, all other pools in the group are tried in order.

take_member/1

take_member(PoolName::atom() | pid()) -> pid() | error_no_members

Obtain exclusive access to a member from PoolName.

If no free members are available, 'error_no_members' is returned.

take_member/2

take_member(PoolName::atom() | pid(), Timeout::non_neg_integer() | time_spec()) -> pid() | error_no_members

Obtain exclusive access to a member of 'PoolName'.

If no members are available, wait for up to Timeout milliseconds for a member to become available. Waiting requests are served in FIFO order. If no member is available within the specified timeout, error_no_members is returned. Timeout can be either milliseconds as integer or {duration, time_unit}

terminate/2

terminate(Reason::term(), State::term()) -> ok


Generated by EDoc