overview-summary.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>pooler - An OTP Process Pool Application</title>
  5. <link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
  6. </head>
  7. <body bgcolor="white">
  8. <div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
  9. <h1>pooler - An OTP Process Pool Application</h1>
  10. <p>Copyright © 2011 Seth Falcon</p>
  11. <p><b>Authors:</b> Seth Falcon (<a href="mailto:seth@userprimary.net"><tt>seth@userprimary.net</tt></a>).</p>
  12. <p>
  13. The pooler application allows you to manage pools of OTP behaviors
  14. such as gen_servers, gen_fsms, or supervisors, and provide consumers
  15. with exclusive access to pool members using pooler:take_member.</p>
  16. <p>See the README.org file for a good introduction to what pooler is all
  17. about.</p>
  18. <h3><a name="Pooler_Configuration">Pooler Configuration</a></h3>
  19. <p>Pool configuration is specified in the pooler application's
  20. environment. This can be provided in a config file using <code>-config</code> or
  21. set at startup using <code>application:set_env(pooler, pools, Pools)</code>.
  22. Here's an example config file that creates three pools of
  23. Riak pb clients each talking to a different node in a local cluster:</p>
  24. <pre>% pooler.config
  25. % Start Erlang as: erl -config pooler
  26. % -*- mode: erlang -*-
  27. % pooler app config
  28. [
  29. {pooler, [
  30. {pools, [
  31. [{name, "rc8081"},
  32. {max_count, 5},
  33. {init_count, 2},
  34. {start_mfa,
  35. {riakc_pb_socket, start_link, ["localhost", 8081]}}],
  36. [{name, "rc8082"},
  37. {max_count, 5},
  38. {init_count, 2},
  39. {start_mfa,
  40. {riakc_pb_socket, start_link, ["localhost", 8082]}}],
  41. [{name, "rc8083"},
  42. {max_count, 5},
  43. {init_count, 2},
  44. {start_mfa,
  45. {riakc_pb_socket, start_link, ["localhost", 8083]}}]
  46. ]}
  47. ]}
  48. ].</pre>
  49. <h3><a name="Using_pooler">Using pooler</a></h3>
  50. <p>Here's an example session:</p>
  51. <pre>application:start(pooler).
  52. P = pooler:take_member(),
  53. % use P
  54. pooler:return_member(P, ok).</pre>
  55. <p>Once started, the main interaction you will have with pooler is through
  56. two functions, <code>take_member/0</code> and <code>return_member/2</code>.</p>
  57. Call <code>pooler:take_member()</code> to obtain a member from a randomly
  58. selected pool. When you are done with it, return it to the pool using
  59. <code>pooler:return_member(Pid, ok)</code>. If you encountered an error using
  60. the member, you can pass <code>fail</code> as the second argument. In this case,
  61. pooler will permanently remove that member from the pool and start a
  62. new member to replace it. If your process is short lived, you can
  63. omit the call to <code>return_member</code>. In this case, pooler will detect
  64. the normal exit of the consumer and reclaim the member.
  65. <hr>
  66. <div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
  67. <p><i>Generated by EDoc, Apr 17 2011, 16:02:59.</i></p>
  68. </body>
  69. </html>