memcached_admin.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section>
  12. <title>Overview</title>
  13. <para>
  14. The module provides access to the distributed hash table <emphasis>memcached</emphasis>.
  15. This hash table is stored in memory and can can be accessed via a pseudo-variable:
  16. $mct(key). Entries are stored and retrieved from an external server application.
  17. </para>
  18. <para>
  19. The <quote>key</quote> can be a static string and also any existing pseudo-variable. Further
  20. interfaces to the functionality provided from memcached are also provided, like access to the
  21. atomic increment and decrement operations.
  22. <example>
  23. <title>Storing and retrieving entries</title>
  24. <programlisting format="linespecific">
  25. ...
  26. $mct(test) = 1;
  27. xlog("stored value is $mct(test)");
  28. $mct(test) = $null; # delete it
  29. xlog("stored value is $mct(test)"); # will return &lt;null&gt; or empty string
  30. ...
  31. </programlisting>
  32. </example>
  33. <example>
  34. <title>Using atomic operations</title>
  35. <programlisting format="linespecific">
  36. ...
  37. $mct(cnt) = 1;
  38. $mcinc(cnt) = 1; # increment by 1
  39. xlog("counter is now $mct(cnt)");
  40. $mcdec(cnt) = 1; # decrement by 1
  41. xlog("counter is now $mct(cnt)");
  42. ...
  43. </programlisting>
  44. </example>
  45. <example>
  46. <title>Set custom expire time when adding an entry</title>
  47. <programlisting format="linespecific">
  48. ...
  49. $mct(test=>10) = 1;
  50. xlog("stored value is $mct(test)");
  51. # sleep 10 seconds
  52. xlog("stored value is $mct(test)"); # will return &lt;null&gt;
  53. ...
  54. </programlisting>
  55. </example>
  56. <example>
  57. <title>Modifying expire time for existing entries</title>
  58. <programlisting format="linespecific">
  59. ...
  60. $mct(test) = 1;
  61. xlog("stored value is $mct(test)");
  62. $mctex(test) = 10; # set expire time to 10 seconds
  63. # sleep 10 seconds
  64. xlog("stored value is $mct(test)"); # will return &lt;null&gt;
  65. ...
  66. </programlisting>
  67. </example>
  68. </para>
  69. <para>
  70. This module is an addition to the existing <emphasis>htable</emphasis> functionality,
  71. not a replacement. In smaller architectures or installations where only one instance
  72. needs access to the hash table the htable module is easier to setup, as no dedicated
  73. server needs to be provided. But when a distributed storage facilility is necessary,
  74. or one want to separate the storage from the SIP server, this module could be used.
  75. </para>
  76. </section>
  77. <section>
  78. <title>Implementation notes</title>
  79. <para>
  80. Important notes about made assumptions and adaptions that were necessary for the proper
  81. integration of this library into &kamailio;.
  82. </para>
  83. <section>
  84. <title>Data safety</title>
  85. <para>
  86. Don't store data in memcached that you don't also have somewhere else. This system was
  87. designed as fast cache, and not for persistent storage. The memcached server can crash,
  88. machines can reboot or are restarted. If the memcache storage pool gets fulls, it starts
  89. to drop the least used items, even if they are not yet expired. So don't store any data in
  90. it where it would be a problem when it disappear from one moment to the other.
  91. </para>
  92. </section>
  93. <section>
  94. <title>Size restrictions</title>
  95. <para>
  96. The maximum key length that is supported from memcached is 250 characters. In order
  97. to support longer keys in the &kamailio; configuration script they are hashed with MD5.
  98. This should normally be safe against collisions, as the value space is sufficiently large enough.
  99. </para>
  100. <para>
  101. The maximum value size that is supported is 1MB. The reason for this is the internal memory
  102. manager used from memcached. But normally this restriction should be not a problem in the
  103. SIP environment where this module is used.
  104. </para>
  105. </section>
  106. </section>
  107. <section>
  108. <title>Dependencies</title>
  109. <section>
  110. <title>&kamailio; Modules</title>
  111. <para>
  112. The following modules must be loaded before this module:
  113. <itemizedlist>
  114. <listitem>
  115. <para>
  116. <emphasis>No dependencies on other &kamailio; modules</emphasis>.
  117. </para>
  118. </listitem>
  119. </itemizedlist>
  120. </para>
  121. </section>
  122. <section>
  123. <title>External Libraries or Applications</title>
  124. <para>
  125. The following libraries or applications must be installed before running
  126. &kamailio; with this module loaded:
  127. <itemizedlist>
  128. <listitem>
  129. <para>
  130. <emphasis>the <ulink url="http://libmemcached.org/">libmemcached</ulink> library</emphasis>.
  131. </para>
  132. </listitem>
  133. <listitem>
  134. <para>
  135. <emphasis>the <ulink url="http://danga.com/memcached/">memcached</ulink> server implementation</emphasis>.
  136. </para>
  137. </listitem>
  138. </itemizedlist>
  139. </para>
  140. </section>
  141. </section>
  142. <section>
  143. <title>Parameters</title>
  144. <section id="memcached.p.servers">
  145. <title><varname>servers</varname> (str)</title>
  146. <para>
  147. The servers to connect to. At the moment only one server is supported.
  148. <!-- If more then one server is used they must be specified in the exact same order, otherwise
  149. the hashing algorithm and the data access will not work. -->
  150. </para>
  151. <para>
  152. <emphasis>
  153. Default value is <quote>localhost:11211</quote>.
  154. </emphasis>
  155. </para>
  156. <example>
  157. <title>Set <varname>servers</varname> parameter</title>
  158. <programlisting format="linespecific">
  159. ...
  160. modparam("memcached", "servers", "localhost:11211")
  161. ...
  162. </programlisting>
  163. </example>
  164. </section>
  165. <section id="memcached.p.expire">
  166. <title><varname>expire</varname> (integer)</title>
  167. <para>
  168. The default expire value of entries in memcached in seconds. The maximal
  169. value is 2592000 (about 30 days). A value of zero means that no automatic expiration is done,
  170. memcached will then delete the least used items when the cache gets full.
  171. </para>
  172. <para>
  173. Please note that memcached implements lazy caching, that means items are only
  174. deleted when they requested (they are of course not delivered to the client),
  175. or on insertion of new entries when the cache is full. Items can also be deleted
  176. before there expire time when the available space in memory is exhausted.
  177. </para>
  178. <para>
  179. It is possible to override this default value when adding a key with the
  180. <emphasis>mct</emphasis> psuedo-variable, or later on by setting a different
  181. timeout for an existing key with the <emphasis>mctex</emphasis> pseudo-variable.
  182. </para>
  183. <para>
  184. <emphasis>
  185. Default value is <quote>10800</quote>s (3h).
  186. </emphasis>
  187. </para>
  188. <example>
  189. <title>Set <varname>expire</varname> parameter</title>
  190. <programlisting format="linespecific">
  191. ...
  192. modparam("memcached", "expire", 10800)
  193. ...
  194. </programlisting>
  195. </example>
  196. </section>
  197. <section id="memcached.p.mode">
  198. <title><varname>mode</varname> (integer)</title>
  199. <para>
  200. The used storage mode for the memcached module for write access
  201. to the hash table. A value of <quote>0</quote> means to set
  202. (overwrite) the old value, with a value of <quote>1</quote> the
  203. module will not overwrite it. Here every entry to the hash table could
  204. be written only once, subsequent inserts will fail.
  205. </para>
  206. <para>
  207. <emphasis>
  208. Default value is <quote>0</quote> (overwrite).
  209. </emphasis>
  210. </para>
  211. <example>
  212. <title>Set <varname>mode</varname> parameter</title>
  213. <programlisting format="linespecific">
  214. ...
  215. modparam("memcached", "mode", 0)
  216. ...
  217. </programlisting>
  218. </example>
  219. </section>
  220. <section id="memcached.p.timeout">
  221. <title><varname>timeout</varname> (integer)</title>
  222. <para>
  223. The timeout for the memcache servers access in milliseconds.
  224. </para>
  225. <para>
  226. <emphasis>
  227. Default value is <quote>5000</quote> (5s).
  228. </emphasis>
  229. </para>
  230. <example>
  231. <title>Set <varname>timeout</varname> parameter</title>
  232. <programlisting format="linespecific">
  233. ...
  234. modparam("memcached", "timeout", 10000)
  235. ...
  236. </programlisting>
  237. </example>
  238. </section>
  239. <section id="memcached.p.memory">
  240. <title><varname>memory</varname> (integer)</title>
  241. <para>
  242. The memory mode for the memcached client library. The library can
  243. use the system memory manager or the internal memory manager from
  244. &kamailio;. The system memory manager configuration is the default,
  245. most implementations (like other projects) probably use this
  246. approach as well. The internal memory configuration should be
  247. faster and protects better against memory leaks that could bring
  248. down your server, as the available memory pool is limited by the
  249. &kamailio; configuration.
  250. </para>
  251. <para>
  252. <emphasis>
  253. Default value is <quote>0</quote> (use system memory manager).
  254. </emphasis>
  255. </para>
  256. <example>
  257. <title>Set <varname>memory</varname> parameter</title>
  258. <programlisting format="linespecific">
  259. ...
  260. modparam("memcached", "memory", 1)
  261. ...
  262. </programlisting>
  263. </example>
  264. </section>
  265. <section id="memcached.p.stringify">
  266. <title><varname>stringify</varname> (integer)</title>
  267. <para>
  268. The string mode for the memcached module. By default the module
  269. checks the flags for each returned value from the memcached library
  270. to decide to evaluate it as string or numerical value. If you need
  271. interoperability with existing applications that are not able to
  272. set this flag, you can force the module to evaluate all values as
  273. strings.
  274. </para>
  275. <para>
  276. <emphasis>
  277. Default value is <quote>0</quote> (don't force string values).
  278. </emphasis>
  279. </para>
  280. <example>
  281. <title>Set <varname>stringify</varname> parameter</title>
  282. <programlisting format="linespecific">
  283. ...
  284. modparam("memcached", "stringify", 1)
  285. ...
  286. </programlisting>
  287. </example>
  288. </section>
  289. </section>
  290. <section>
  291. <section>
  292. <title>Exported pseudo-variables</title>
  293. <itemizedlist>
  294. <listitem><para>
  295. <emphasis>$mct(key)</emphasis>
  296. </para></listitem>
  297. <listitem><para>
  298. <emphasis>$mct(key=>expiry)</emphasis>
  299. </para></listitem>
  300. <listitem><para>
  301. <emphasis>$mcinc(key)</emphasis>
  302. </para></listitem>
  303. <listitem><para>
  304. <emphasis>$mcdec(key)</emphasis>
  305. </para></listitem>
  306. <listitem><para>
  307. <emphasis>$mctex(key)</emphasis>
  308. </para></listitem>
  309. </itemizedlist>
  310. <para>
  311. Exported pseudo-variables are documented at &kamwikilink;.
  312. </para>
  313. </section>
  314. </section>
  315. </chapter>