Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f7829d7b89
Fetching contributors…

Cannot retrieve contributors at this time

file 71 lines (60 sloc) 2.377 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
@author Seth Falcon <seth@userprimary.net>
@copyright 2011 Seth Falcon
@title pooler - An OTP Process Pool Application
@doc
The pooler application allows you to manage pools of OTP behaviors
such as gen_servers, gen_fsms, or supervisors, and provide consumers
with exclusive access to pool members using pooler:take_member.

See the README.org file for a good introduction to what pooler is all
about.

== Pooler Configuration ==

Pool configuration is specified in the pooler application's
environment. This can be provided in a config file using `-config' or
set at startup using `application:set_env(pooler, pools, Pools)'.
Here's an example config file that creates three pools of
Riak pb clients each talking to a different node in a local cluster:

```
% pooler.config
% Start Erlang as: erl -config pooler
% -*- mode: erlang -*-
% pooler app config
[
 {pooler, [
         {pools, [
                  [{name, "rc8081"},
                   {max_count, 5},
                   {init_count, 2},
                   {start_mfa,
                    {riakc_pb_socket, start_link, ["localhost", 8081]}}],

                  [{name, "rc8082"},
                   {max_count, 5},
                   {init_count, 2},
                   {start_mfa,
                    {riakc_pb_socket, start_link, ["localhost", 8082]}}],

                  [{name, "rc8083"},
                   {max_count, 5},
                   {init_count, 2},
                   {start_mfa,
                    {riakc_pb_socket, start_link, ["localhost", 8083]}}]
                 ]}
        ]}
].
'''

== Using pooler ==

Here's an example session:

```
application:start(pooler).
P = pooler:take_member(),
% use P
pooler:return_member(P, ok).
'''

Once started, the main interaction you will have with pooler is through
two functions, `take_member/0' and `return_member/2'.

Call `pooler:take_member()' to obtain a member from a randomly
selected pool. When you are done with it, return it to the pool using
`pooler:return_member(Pid, ok)'. If you encountered an error using
the member, you can pass `fail' as the second argument. In this case,
pooler will permanently remove that member from the pool and start a
new member to replace it. If your process is short lived, you can
omit the call to `return_member'. In this case, pooler will detect
the normal exit of the consumer and reclaim the member.
Something went wrong with that request. Please try again.