File: memcached_admin.xml

package info (click to toggle)
kamailio 4.2.0-2%2Bdeb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 56,276 kB
  • sloc: ansic: 552,836; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (321 lines) | stat: -rw-r--r-- 10,518 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [

<!-- Include general documentation entities -->
<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
%docentities;

]>
<!-- Module User's Guide -->

<chapter>
	
	<title>&adminguide;</title>
	
	<section>
	<title>Overview</title>
	<para>
		The module provides access to the distributed hash table <emphasis>memcached</emphasis>.
		This hash table is stored in memory and can can be accessed via a pseudo-variable:
		$mct(key). Entries are stored and retrieved from an external server application.
	</para>
	<para>
		The <quote>key</quote> can be a static string and also any existing pseudo-variable. Further
		interfaces to the functionality provided from memcached are also provided, like access to the
		atomic increment and decrement operations.
		<example>
		<title>Storing and retrieving entries</title>
			<programlisting format="linespecific">
...
$mct(test) = 1;
xlog("stored value is $mct(test)");
$mct(test) = $null; # delete it
xlog("stored value is $mct(test)"); # will return &lt;null&gt; or empty string
...
			</programlisting>
		</example>
		<example>
			<title>Using atomic operations</title>
			<programlisting format="linespecific">
...
$mct(cnt) = 1;
$mcinc(cnt) = 1; # increment by 1
xlog("counter is now $mct(cnt)");
$mcdec(cnt) = 1; # decrement by 1
xlog("counter is now $mct(cnt)");
...
			</programlisting>
		</example>
                <example>
                <title>Set custom expire time when adding an entry</title>
                        <programlisting format="linespecific">
...
$mct(test=>10) = 1;
xlog("stored value is $mct(test)");
# sleep 10 seconds
xlog("stored value is $mct(test)"); # will return &lt;null&gt;
...
                        </programlisting>
                </example>
		<example>
		<title>Modifying expire time for existing entries</title>
			<programlisting format="linespecific">
...
$mct(test) = 1;
xlog("stored value is $mct(test)");
$mctex(test) = 10; # set expire time to 10 seconds
# sleep 10 seconds
xlog("stored value is $mct(test)"); # will return &lt;null&gt;
...
			</programlisting>
		</example>
	</para>
	<para>
		This module is an addition to the existing <emphasis>htable</emphasis> functionality,
		not a replacement. In smaller architectures or installations where only one instance
		needs access to the hash table the htable module is easier to setup, as no dedicated
		server needs to be provided. But when a distributed storage facilility is necessary,
		or one want to separate the storage from the SIP server, this module could be used.
	</para>
	</section>
	<section>
	<title>Implementation notes</title>
		<para>
			Important notes about made assumptions and adaptions that were necessary for the proper
			integration of this library into &kamailio;.
		</para>
	<section>
		<title>Data safety</title>
		<para>
			Don't store data in memcached that you don't also have somewhere else. This system was
			designed as fast cache, and not for persistent storage. The memcached server can crash,
			machines can reboot or are restarted. If the memcache storage pool gets fulls, it starts
			to drop the least used items, even if they are not yet expired. So don't store any data in
			it where it would be a problem when it disappear from one moment to the other.
		</para>
	</section>
	<section>
		<title>Size restrictions</title>
		<para>
			The maximum key length that is supported from memcached is 250 characters. In order
			to support longer keys in the &kamailio; configuration script they are hashed with MD5.
			This should normally be safe against collisions, as the value space is sufficiently large enough.
		</para>
		<para>
			The maximum value size that is supported is 1MB. The reason for this is the internal memory
			manager used from memcached. But normally this restriction should be not a problem in the
			SIP environment where this module is used.
		</para>
	</section>
	</section>
	<section>
	<title>Dependencies</title>
	<section>
		<title>&kamailio; Modules</title>
		<para>
		The following modules must be loaded before this module:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>No dependencies on other &kamailio; modules</emphasis>.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	<section>
		<title>External Libraries or Applications</title>
		<para>
		The following libraries or applications must be installed before running
		&kamailio; with this module loaded:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>the <ulink url="http://libmemcached.org/">libmemcached</ulink> library</emphasis>.
			</para>
			</listitem>
			<listitem>
				<para>
					<emphasis>the <ulink url="http://danga.com/memcached/">memcached</ulink> server implementation</emphasis>.
				</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	</section>
	<section>
	<title>Parameters</title>
	<section id="memcached.p.servers">
		<title><varname>servers</varname> (str)</title>
		<para>
		The servers to connect to. At the moment only one server is supported.
<!-- If more then one server is used they must be specified in the exact same order, otherwise
     the hashing algorithm and the data access will not work. -->
		</para>
		<para>
			<emphasis>
				Default value is <quote>localhost:11211</quote>.
			</emphasis>
		</para>
		<example>
			<title>Set <varname>servers</varname> parameter</title>
			<programlisting format="linespecific">
...
modparam("memcached", "servers", "localhost:11211")
...
			</programlisting>
		</example>
	</section>
	<section id="memcached.p.expire">
		<title><varname>expire</varname> (integer)</title>
		<para>
			The default expire value of entries in memcached in seconds. The maximal
			value is 2592000 (about 30 days). A value of zero means that no automatic expiration is done,
			memcached will then delete the least used items when the cache gets full.
		</para>
		<para>
			Please note that memcached implements lazy caching, that means items are only
			deleted when they requested (they are of course not delivered to the client),
			or on insertion of new entries when the cache is full. Items can also be deleted
			before there expire time when the available space in memory is exhausted.
		</para>
		<para>
			It is possible to override this default value when adding a key with the
			<emphasis>mct</emphasis> psuedo-variable, or later on by setting a different
			timeout for an existing key with the <emphasis>mctex</emphasis> pseudo-variable.
		</para>
		<para>
		<emphasis>
			Default value is <quote>10800</quote>s (3h).
		</emphasis>
		</para>
		<example>
		<title>Set <varname>expire</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("memcached", "expire", 10800)
...
</programlisting>
		</example>
	</section>
	<section id="memcached.p.mode">
		<title><varname>mode</varname> (integer)</title>
		<para>
			The used storage mode for the memcached module for write access
			to the hash table. A value of <quote>0</quote> means to set
			(overwrite) the old value, with a value of <quote>1</quote> the
			module will not overwrite it. Here every entry to the hash table could
			be written only once, subsequent inserts will fail.
		</para>
		<para>
			<emphasis>
				Default value is <quote>0</quote> (overwrite).
			</emphasis>
		</para>
		<example>
		<title>Set <varname>mode</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("memcached", "mode", 0)
...
</programlisting>
		</example>
	</section>
	<section id="memcached.p.timeout">
		<title><varname>timeout</varname> (integer)</title>
		<para>
			The timeout for the memcache servers access in milliseconds.
		</para>
		<para>
			<emphasis>
				Default value is <quote>5000</quote> (5s).
			</emphasis>
		</para>
		<example>
			<title>Set <varname>timeout</varname> parameter</title>
			<programlisting format="linespecific">
...
modparam("memcached", "timeout", 10000)
...
			</programlisting>
		</example>
	</section>
	<section id="memcached.p.memory">
		<title><varname>memory</varname> (integer)</title>
		<para>
			The memory mode for the memcached client library. The library can
			use the system memory manager or the internal memory manager from
			&kamailio;. The system memory manager configuration is the default,
			most implementations (like other projects) probably use this
			approach as well. The internal memory configuration should be
			faster and protects better against memory leaks that could bring
			down your server, as the available memory pool is limited by the
			&kamailio; configuration.
		</para>
		<para>
			<emphasis>
				Default value is <quote>0</quote> (use system memory manager).
			</emphasis>
		</para>
		<example>
			<title>Set <varname>memory</varname> parameter</title>
			<programlisting format="linespecific">
...
modparam("memcached", "memory", 1)
...
			</programlisting>
		</example>
	</section>
	<section id="memcached.p.stringify">
		<title><varname>stringify</varname> (integer)</title>
		<para>
			The string mode for the memcached module. By default the module
			checks the flags for each returned value from the memcached library
			to decide to evaluate it as string or numerical value. If you need
			interoperability with existing applications that are not able to
			set this flag, you can force the module to evaluate all values as
			strings.
		</para>
		<para>
			<emphasis>
				Default value is <quote>0</quote> (don't force string values).
			</emphasis>
		</para>
		<example>
			<title>Set <varname>stringify</varname> parameter</title>
			<programlisting format="linespecific">
...
modparam("memcached", "stringify", 1)
...
			</programlisting>
		</example>
	</section>
	</section>
	<section>
		<section>
		<title>Exported pseudo-variables</title>
		<itemizedlist>
			<listitem><para>
				<emphasis>$mct(key)</emphasis>
			</para></listitem>
                        <listitem><para>
                                <emphasis>$mct(key=>expiry)</emphasis>
                        </para></listitem>
			<listitem><para>
				<emphasis>$mcinc(key)</emphasis>
			</para></listitem>
			<listitem><para>
				<emphasis>$mcdec(key)</emphasis>
			</para></listitem>
			<listitem><para>
				<emphasis>$mctex(key)</emphasis>
			</para></listitem>
		</itemizedlist>
		<para>
		Exported pseudo-variables are documented at &kamwikilink;.
		</para>
	</section>
	</section>
</chapter>