overview.edoc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. @author Seth Falcon <seth@userprimary.net>
  2. @copyright 2011 Seth Falcon
  3. @title pooler - An OTP Process Pool Application
  4. @doc
  5. The pooler application allows you to manage pools of OTP behaviors
  6. such as gen_servers, gen_fsms, or supervisors, and provide consumers
  7. with exclusive access to pool members using pooler:take_member.
  8. See the README.org file for a good introduction to what pooler is all
  9. about.
  10. == Pooler Configuration ==
  11. Pool configuration is specified in the pooler application's
  12. environment. This can be provided in a config file using `-config' or
  13. set at startup using `application:set_env(pooler, pools, Pools)'.
  14. Here's an example config file that creates three pools of
  15. Riak pb clients each talking to a different node in a local cluster:
  16. ```
  17. % pooler.config
  18. % Start Erlang as: erl -config pooler
  19. % -*- mode: erlang -*-
  20. % pooler app config
  21. [
  22. {pooler, [
  23. {pools, [
  24. [{name, "rc8081"},
  25. {max_count, 5},
  26. {init_count, 2},
  27. {start_mfa,
  28. {riakc_pb_socket, start_link, ["localhost", 8081]}}],
  29. [{name, "rc8082"},
  30. {max_count, 5},
  31. {init_count, 2},
  32. {start_mfa,
  33. {riakc_pb_socket, start_link, ["localhost", 8082]}}],
  34. [{name, "rc8083"},
  35. {max_count, 5},
  36. {init_count, 2},
  37. {start_mfa,
  38. {riakc_pb_socket, start_link, ["localhost", 8083]}}]
  39. ]}
  40. ]}
  41. ].
  42. '''
  43. == Using pooler ==
  44. Here's an example session:
  45. ```
  46. application:start(pooler).
  47. P = pooler:take_member(),
  48. % use P
  49. pooler:return_member(P, ok).
  50. '''
  51. Once started, the main interaction you will have with pooler is through
  52. two functions, `take_member/0' and `return_member/2'.
  53. Call `pooler:take_member()' to obtain a member from a randomly
  54. selected pool. When you are done with it, return it to the pool using
  55. `pooler:return_member(Pid, ok)'. If you encountered an error using
  56. the member, you can pass `fail' as the second argument. In this case,
  57. pooler will permanently remove that member from the pool and start a
  58. new member to replace it. If your process is short lived, you can
  59. omit the call to `return_member'. In this case, pooler will detect
  60. the normal exit of the consumer and reclaim the member.