overview.edoc 2.8 KB

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