overview.edoc 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. @author Ulf Wiger <ulf.wiger@erlang-solutions.com>
  2. @author Joseph Wayne Norton <norton@geminimobile.com>
  3. @doc Extended process dictionary
  4. [![Build Status](https://travis-ci.org/uwiger/gproc.png?branch=master)](https://travis-ci.org/uwiger/gproc)
  5. <h2>Note</h2>
  6. Gproc has two dependencies: `gen_leader' and `edown'. Since most people don't
  7. actively use either, they are no longer fetched by default.
  8. <ul>
  9. <li>To enable fetching of `gen_leader', export the OS environment variable
  10. `GPROC_DIST=true' (this can be done e.g. from a GNU Makefile)</li>
  11. <li>`edown' is fetched on-demand whenver `rebar get-deps doc' is called (which
  12. happens when you call `make doc')</li>
  13. </ul>
  14. <h2>Introduction</h2>
  15. Gproc is a process dictionary for Erlang, which provides a number of useful features beyond what the built-in dictionary has:
  16. <ul>
  17. <li>Use any term as a process alias</li>
  18. <li>Register a process under several aliases</li>
  19. <li>Non-unique properties can be registered simultaneously by many processes</li>
  20. <li>QLC and match specification interface for efficient queries on the
  21. dictionary</li>
  22. <li>Await registration, let's you wait until a process registers itself</li>
  23. <li>Atomically give away registered names and properties to another process</li>
  24. <li>Counters, and aggregated counters, which automatically maintain the
  25. total of all counters with a given name</li>
  26. <li>Global registry, with all the above functions applied to a network of nodes</li>
  27. </ul>
  28. <h3>Use case: System inspection</h3>
  29. Gproc was designed to work as a central index for "process metadata", i.e.
  30. properties that describe the role and characteristics of each process. Having
  31. a single registry that is flexible enough to hold important types of property
  32. makes it easier to (a) find processes of a certain type, and (b) query and
  33. browse key data in a running system.
  34. <h3>Use case: Pub/Sub patterns</h3>
  35. An interesting application of gproc is building publish/subscribe patterns.
  36. Example:
  37. <pre lang="erlang">
  38. subscribe(EventType) ->
  39. %% Gproc notation: {p, l, Name} means {(p)roperty, (l)ocal, Name}
  40. gproc:reg({p, l, {?MODULE, EventType}}).
  41. notify(EventType, Msg) ->
  42. Key = {?MODULE, EventType},
  43. gproc:send({p, l, Key}, {self(), Key, Msg}).
  44. </pre>
  45. <h3>Use case: Environment handling</h3>
  46. Gproc provides a set of functions to read environment variables, possibly from
  47. alternative sources, and cache them for efficient lookup. Caching also provides
  48. a way to see which processes rely on certain configuration values, as well as
  49. which values they actually ended up using.
  50. See {@link gproc:get_env/4}, {@link gproc:get_set_env/4} and
  51. {@link gproc:set_env/5} for details.
  52. <h2>Testing</h2>
  53. Gproc has a QuickCheck test suite, covering a fairly large part of the local
  54. gproc functionality, although none of the global registry. It requires a
  55. commercial EQC license, but rebar is smart enough to detect whether EQC is
  56. available, and if it isn't, the code in gproc_eqc.erl will be "defined away".
  57. There is also an eunit suite, covering the basic operations for local and
  58. global gproc.
  59. <h2>Building Edoc</h2>
  60. By default, `./rebar doc` generates Github-flavored Markdown files.
  61. If you want to change this, remove the `edoc_opts' line from `rebar.config'.
  62. Gproc was first introduced at the ACM SIGPLAN Erlang Workshop in
  63. Freiburg 2007 (<a href="erlang07-wiger.pdf">Paper available here</a>).
  64. @end