|
@@ -3,34 +3,34 @@ Memcached Module
|
|
Henning Westerholt
|
|
Henning Westerholt
|
|
|
|
|
|
Copyright © 2009 Henning Westerholt
|
|
Copyright © 2009 Henning Westerholt
|
|
- __________________________________________________________
|
|
|
|
|
|
+ __________________________________________________________________
|
|
|
|
|
|
Table of Contents
|
|
Table of Contents
|
|
|
|
|
|
1. Admin Guide
|
|
1. Admin Guide
|
|
|
|
|
|
- 1.1. Overview
|
|
|
|
- 1.2. Implementation notes
|
|
|
|
|
|
+ 1. Overview
|
|
|
|
+ 2. Implementation notes
|
|
|
|
|
|
- 1.2.1. Error behaviour
|
|
|
|
- 1.2.2. Data safety
|
|
|
|
- 1.2.3. Size restrictions
|
|
|
|
|
|
+ 2.1. Error behaviour
|
|
|
|
+ 2.2. Data safety
|
|
|
|
+ 2.3. Size restrictions
|
|
|
|
|
|
- 1.3. Dependencies
|
|
|
|
|
|
+ 3. Dependencies
|
|
|
|
|
|
- 1.3.1. Kamailio Modules
|
|
|
|
- 1.3.2. External Libraries or Applications
|
|
|
|
|
|
+ 3.1. Kamailio Modules
|
|
|
|
+ 3.2. External Libraries or Applications
|
|
|
|
|
|
- 1.4. Exported Parameters
|
|
|
|
|
|
+ 4. Exported Parameters
|
|
|
|
|
|
- 1.4.1. servers (str)
|
|
|
|
- 1.4.2. expire (integer)
|
|
|
|
- 1.4.3. mode (integer)
|
|
|
|
- 1.4.4. timeout (integer)
|
|
|
|
|
|
+ 4.1. servers (str)
|
|
|
|
+ 4.2. expire (integer)
|
|
|
|
+ 4.3. mode (integer)
|
|
|
|
+ 4.4. timeout (integer)
|
|
|
|
|
|
- 1.5.
|
|
|
|
|
|
+ 5.
|
|
|
|
|
|
- 1.5.1. Exported pseudo-variables
|
|
|
|
|
|
+ 5.1. Exported pseudo-variables
|
|
|
|
|
|
List of Examples
|
|
List of Examples
|
|
|
|
|
|
@@ -43,17 +43,42 @@ Henning Westerholt
|
|
|
|
|
|
Chapter 1. Admin Guide
|
|
Chapter 1. Admin Guide
|
|
|
|
|
|
-1.1. Overview
|
|
|
|
|
|
+ Table of Contents
|
|
|
|
+
|
|
|
|
+ 1. Overview
|
|
|
|
+ 2. Implementation notes
|
|
|
|
+
|
|
|
|
+ 2.1. Error behaviour
|
|
|
|
+ 2.2. Data safety
|
|
|
|
+ 2.3. Size restrictions
|
|
|
|
+
|
|
|
|
+ 3. Dependencies
|
|
|
|
+
|
|
|
|
+ 3.1. Kamailio Modules
|
|
|
|
+ 3.2. External Libraries or Applications
|
|
|
|
+
|
|
|
|
+ 4. Exported Parameters
|
|
|
|
+
|
|
|
|
+ 4.1. servers (str)
|
|
|
|
+ 4.2. expire (integer)
|
|
|
|
+ 4.3. mode (integer)
|
|
|
|
+ 4.4. timeout (integer)
|
|
|
|
+
|
|
|
|
+ 5.
|
|
|
|
+
|
|
|
|
+ 5.1. Exported pseudo-variables
|
|
|
|
+
|
|
|
|
+1. Overview
|
|
|
|
|
|
- The module provides access to the distributed hash table
|
|
|
|
- memcached. 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.
|
|
|
|
|
|
+ The module provides access to the distributed hash table memcached.
|
|
|
|
+ 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.
|
|
|
|
|
|
- The "key" 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.
|
|
|
|
|
|
+ The "key" 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 1.1. Storing and retrieving entries
|
|
Example 1.1. Storing and retrieving entries
|
|
...
|
|
...
|
|
@@ -72,76 +97,83 @@ $mcdec(cnt) = 1; # decrement by 1
|
|
xlog("counter is now $mct(cnt)");
|
|
xlog("counter is now $mct(cnt)");
|
|
...
|
|
...
|
|
|
|
|
|
- This module is an addition to the existing htable
|
|
|
|
- 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.
|
|
|
|
|
|
+ This module is an addition to the existing htable 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.
|
|
|
|
|
|
-1.2. Implementation notes
|
|
|
|
|
|
+2. Implementation notes
|
|
|
|
+
|
|
|
|
+ 2.1. Error behaviour
|
|
|
|
+ 2.2. Data safety
|
|
|
|
+ 2.3. Size restrictions
|
|
|
|
|
|
Important notes about made assumptions and adaptions that were
|
|
Important notes about made assumptions and adaptions that were
|
|
- necessary for the proper integration of this library into
|
|
|
|
- Kamailio.
|
|
|
|
-
|
|
|
|
-1.2.1. Error behaviour
|
|
|
|
-
|
|
|
|
- The used memcache library has a rather conservative approach to
|
|
|
|
- error handling. In the default configuration each error with
|
|
|
|
- severity above "WARN" will lead to a immediately exit (or even
|
|
|
|
- an abort) of the execution, causing also a shutdown of
|
|
|
|
- Kamailio. This is of course not optimal from a availability
|
|
|
|
- point of view. Therefore in the internal error handler this is
|
|
|
|
- overriden. This means that we err a bit on the side of data
|
|
|
|
- integrity in order to get a sufficient availability. But even
|
|
|
|
- with this changes some problems in the memcache server can lead
|
|
|
|
- to problems in the library and subsequently also in the server.
|
|
|
|
-
|
|
|
|
-1.2.2. Data safety
|
|
|
|
-
|
|
|
|
- Don't store data in memcached that you 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.
|
|
|
|
-
|
|
|
|
-1.2.3. Size restrictions
|
|
|
|
|
|
+ necessary for the proper integration of this library into Kamailio.
|
|
|
|
+
|
|
|
|
+2.1. Error behaviour
|
|
|
|
+
|
|
|
|
+ The used memcache library has a rather conservative approach to error
|
|
|
|
+ handling. In the default configuration each error with severity above
|
|
|
|
+ "WARN" will lead to a immediately exit (or even an abort) of the
|
|
|
|
+ execution, causing also a shutdown of Kamailio. This is of course not
|
|
|
|
+ optimal from a availability point of view. Therefore in the internal
|
|
|
|
+ error handler this is overriden. This means that we err a bit on the
|
|
|
|
+ side of data integrity in order to get a sufficient availability. But
|
|
|
|
+ even with this changes some problems in the memcache server can lead to
|
|
|
|
+ problems in the library and subsequently also in the server.
|
|
|
|
+
|
|
|
|
+2.2. Data safety
|
|
|
|
+
|
|
|
|
+ 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.
|
|
|
|
+
|
|
|
|
+2.3. Size restrictions
|
|
|
|
|
|
The maximum key length that is supported from memcached is 250
|
|
The maximum key length that is supported from memcached is 250
|
|
characters. In order to support longer keys in the Kamailio
|
|
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
|
|
|
|
- sufficient large enough.
|
|
|
|
|
|
+ configuration script they are hashed with MD5. This should normally be
|
|
|
|
+ safe against collisions, as the value space is sufficient large enough.
|
|
|
|
+
|
|
|
|
+ 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.
|
|
|
|
|
|
- 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.
|
|
|
|
|
|
+3. Dependencies
|
|
|
|
|
|
-1.3. Dependencies
|
|
|
|
|
|
+ 3.1. Kamailio Modules
|
|
|
|
+ 3.2. External Libraries or Applications
|
|
|
|
|
|
-1.3.1. Kamailio Modules
|
|
|
|
|
|
+3.1. Kamailio Modules
|
|
|
|
|
|
The following modules must be loaded before this module:
|
|
The following modules must be loaded before this module:
|
|
* No dependencies on other Kamailio modules.
|
|
* No dependencies on other Kamailio modules.
|
|
|
|
|
|
-1.3.2. External Libraries or Applications
|
|
|
|
|
|
+3.2. External Libraries or Applications
|
|
|
|
|
|
- The following libraries or applications must be installed
|
|
|
|
- before running Kamailio with this module loaded:
|
|
|
|
|
|
+ The following libraries or applications must be installed before
|
|
|
|
+ running Kamailio with this module loaded:
|
|
* the libmemcache library.
|
|
* the libmemcache library.
|
|
* the memcached server implementation.
|
|
* the memcached server implementation.
|
|
|
|
|
|
-1.4. Exported Parameters
|
|
|
|
|
|
+4. Exported Parameters
|
|
|
|
|
|
-1.4.1. servers (str)
|
|
|
|
|
|
+ 4.1. servers (str)
|
|
|
|
+ 4.2. expire (integer)
|
|
|
|
+ 4.3. mode (integer)
|
|
|
|
+ 4.4. timeout (integer)
|
|
|
|
|
|
- The servers to connect to. At the moment only one server is
|
|
|
|
- supported.
|
|
|
|
|
|
+4.1. servers (str)
|
|
|
|
+
|
|
|
|
+ The servers to connect to. At the moment only one server is supported.
|
|
|
|
|
|
Default value is "localhost:11211".
|
|
Default value is "localhost:11211".
|
|
|
|
|
|
@@ -150,20 +182,19 @@ xlog("counter is now $mct(cnt)");
|
|
modparam("memcached", "servers", "localhost:11211")
|
|
modparam("memcached", "servers", "localhost:11211")
|
|
...
|
|
...
|
|
|
|
|
|
-1.4.2. expire (integer)
|
|
|
|
|
|
+4.2. expire (integer)
|
|
|
|
|
|
- The default expire value of all entries in memcached in
|
|
|
|
- seconds. The maximal value is 2592000 (about 30 days). You can
|
|
|
|
- also specify an arbitrary unix time stamp in the future. A
|
|
|
|
- value of zero means that no automatic expiration is done,
|
|
|
|
- memcached will then delete the least used items when the cache
|
|
|
|
- gets full.
|
|
|
|
|
|
+ The default expire value of all entries in memcached in seconds. The
|
|
|
|
+ maximal value is 2592000 (about 30 days). You can also specify an
|
|
|
|
+ arbitrary unix time stamp in the future. A value of zero means that no
|
|
|
|
+ automatic expiration is done, memcached will then delete the least used
|
|
|
|
+ items when the cache gets full.
|
|
|
|
|
|
- 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.
|
|
|
|
|
|
+ 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.
|
|
|
|
|
|
Default value is "10800"s (3h).
|
|
Default value is "10800"s (3h).
|
|
|
|
|
|
@@ -172,13 +203,13 @@ modparam("memcached", "servers", "localhost:11211")
|
|
modparam("memcached", "expire", 10800)
|
|
modparam("memcached", "expire", 10800)
|
|
...
|
|
...
|
|
|
|
|
|
-1.4.3. mode (integer)
|
|
|
|
|
|
+4.3. mode (integer)
|
|
|
|
|
|
- The used storage mode for the memcached module for write access
|
|
|
|
- to the hash table. A value of "0" means to set (overwrite) the
|
|
|
|
- old value, with a value of "1" the module will not overwrite
|
|
|
|
- it. Here every entry to the hash table could be written only
|
|
|
|
- once, subsequent inserts will fail.
|
|
|
|
|
|
+ The used storage mode for the memcached module for write access to the
|
|
|
|
+ hash table. A value of "0" means to set (overwrite) the old value, with
|
|
|
|
+ a value of "1" the module will not overwrite it. Here every entry to
|
|
|
|
+ the hash table could be written only once, subsequent inserts will
|
|
|
|
+ fail.
|
|
|
|
|
|
Default value is "0" (overwrite).
|
|
Default value is "0" (overwrite).
|
|
|
|
|
|
@@ -187,7 +218,7 @@ modparam("memcached", "expire", 10800)
|
|
modparam("memcached", "mode", 0)
|
|
modparam("memcached", "mode", 0)
|
|
...
|
|
...
|
|
|
|
|
|
-1.4.4. timeout (integer)
|
|
|
|
|
|
+4.4. timeout (integer)
|
|
|
|
|
|
The timeout for the memcache servers access in milliseconds.
|
|
The timeout for the memcache servers access in milliseconds.
|
|
|
|
|
|
@@ -198,7 +229,9 @@ modparam("memcached", "mode", 0)
|
|
modparam("memcached", "timeout", 10000)
|
|
modparam("memcached", "timeout", 10000)
|
|
...
|
|
...
|
|
|
|
|
|
-1.5.1. Exported pseudo-variables
|
|
|
|
|
|
+ 5.1. Exported pseudo-variables
|
|
|
|
+
|
|
|
|
+5.1. Exported pseudo-variables
|
|
|
|
|
|
* $mct(key)
|
|
* $mct(key)
|
|
* $mcinc(key)
|
|
* $mcinc(key)
|