memcached optimizes specific high-load serving applications that are designed to take advantage of its versatile no-locking memory access system. Clients are available in several different programming languages, to suit the needs of the specific application. Traditionally this has been used in mod_perl apps to avoid storing large chunks of data in Apache memory, and to share this burden across several machines.
Memcached is a Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
You can deploy a memcached instance with
juju deploy memcached
Memcached listens to port 11211 on the internal network, it is not recommended to expose memcached directly to the open internet. If you want to check that it has deployed correctly you can ssh into the unit and then check the port by hand:
juju status memcached juju ssh memcached/3 echo "stats settings" | nc localhost 11211
The "3" in this case is an example, the
juju status memcached will show you which machine number the service is running on so you can
juju ssh to it.
The charm uses the repcached patch ( http://repcached.lab.klab.org/ ), this patch has some limitations, as
the ability to just replicate between 2 nodes.
For enabling replication create a config.yaml file with the following content:
Then deploy a maximum of 2 units of memcached:
juju deploy -n 2 config.yaml memcached
Caution : As per design limitations, If you try to add another unit of memcached, all the units will be
set as standalone you decide to disable repcached by using
juju set memcached repcached=false and re-deploy the
Or you can deploy 2 units and then enable replication by running
juju deploy -n 2 memcached
juju set memcached repcached=true
Removing a unit
Removing one of the cluster units, means remove replication, please disable replication first
and then remove the unit safely.
juju set memcached repcached=false juju remove-unit memcached/0
For turning the replication support off on memcached, you need to run the following command:
juju set memcached repcached=false
This charm can be used with other charms, in particular make note of these possible relations
To use memcached with the Rails charm follow these instructions
Scale out Usage
juju add-unit memcached
To add more units. Memcached doesn't share load, it's very simple and the clients have the intelligence to know which server to pick.
To use this charm with nrpe-external-master:
juju deploy memcached juju deploy local:trusty/nrpe-external-master juju add-relation memcached nrpe-external-master
For more details see the nrpe-external-master charm. Until there is a version of nrpe-external-master in trusty, you will need to use a local copy of the precise charm branched into an appropriate trusty directory.
Known Limitations and Issues
Standard configuration options are provided, we recommend scanning the Memcached documentation before tweaking the default configuration.
- (int) limit of requests a single client can make at one time (memcached option -R) -1 takes memcached default (20)
- (int) Override the size of each slab page in bytes. In mundane words, it adjusts the maximum item size that memcached will accept. You can use the suffixes K and M to specify the size as well, so use 2000000 or 2000K or 2M if you want a maximum size of 2 MB per object. It is not recommended to raise this limit above 1 MB due just to performance reasons. The default value is 1 MB. (memcached option -I) -1 takes the memcached default.
- (boolean) Enable memcached replication
- (boolean) When this option is set to True the charm will disable the IPv6 support in ufw in case ip6tables couldn't be activated, situations where this could happen is in a LXC container running on top of a host that doesn't have loaded the ip6_tables. If this option is False (the default) and ip6_tables module couldn't be loaded, the charm will fail to install.
- (int) number of threads to use. default is 4. (memcached option -t)
- (string) Used by the nrpe-external-master subordinate charm. A string that will be prepended to instance name to set the host name in nagios. So for instance the hostname would be something like: juju-memcached-0 If you're running multiple environments with the same services in them this allows you to differentiate between them.
- (boolean) The charm will will try to use large pages if given more than 2GB of RAM. You may want to disable this behavior. (memcached option -L)
- (boolean) disable use of CAS (and reduce the per-item size by 8 bytes)
- (string) TCP port number for replication (default: 11212)
- (int) maximum simultaneous connections (memcached option -c)
- (int) UDP port to listen on (memcached option -U)
- (int) Allocate a minimum of <size> bytes for the item key, value, and flags. The default is 48. If you have a lot of small keys and values, you can get a significant memory efficiency gain with a lower value. If you use a high chunk growth factor (-f option), on the other hand, you may want to increase the size to allow a bigger percentage of your items to fit in the most densely packed (smallest) chunks. (memcached option -n)
- (string) Memcached + Repcached package location
- (boolean) do not remove things automatically from the cache on OOM (memcached option -M)
- (float) Use <factor> as the multiplier for computing the sizes of memory chunks that items are stored in. A lower value may result in less wasted memory depending on the total amount of memory available and the distribution of item sizes. The default is 1.25.
- (int) TCP port to listen on. (memcached option -p)
- (string) memcached has many other options documented in its man page. You may pass them here as a string which
- (int) Size of memcache pool in MiB (memcached option -m)