[+/-]
To start using memcached, you must start the memcached service on one or more servers. Running memcached sets up the server, allocates the memory and starts listening for connections from clients.
You do not need to be privileged user (root)
to run memcached unless you want to listen on
one of the privileged TCP/IP ports (below 1024). You must,
however, use a user that has not had their memory limits
restricted using setrlimit or similar.
To start the server, run memcached as a non-privileged (i.e. non-root) user:
shell> memcached
If you start memcached as
root, use the -u option to
specify the user for executing memcached:
shell> memcached -u memcache
By default, memcached uses the following settings:
Memory allocation of 64MB
Listens for connections on all network interfaces, using port 11211.
Supports a maximum of 1024 simultaneous connections.
To increase the amount of memory allocated for the cache, use the
-m option to specify the amount of RAM to be
allocated (in megabytes). The more RAM you allocate, the more data
you can store and therefore the more effective your cache will be.
Do not specify a memory allocation larger than your available RAM. If you specify too large a value, then some RAM allocated for memcached will be using swap space, and not physical RAM. This may lead to delays when storing and retrieving values, because data will be swapped to disk, instead of storing the data directly in RAM.
You can use the output of the vmstat command
to get the free memory, as shown in free
column:
shell> vmstat kthr memory page disk faults cpu r b w swap free re mf pi po fr de sr s1 s2 -- -- in sy cs us sy id 0 0 0 5170504 3450392 2 7 2 0 0 0 4 0 0 0 0 296 54 199 0 0 100
For example, to allocate 3GB of RAM:
shell> memcached -m 3072
On 32-bit x86 systems where you are using PAE to access memory above the 4GB limit, you will be unable to allocate RAM beyond the maximum process size. You can get around this by running multiple instances of memcached, each listening on a different port:
shell> memcached -m 1024 -p11211 shell> memcached -m 1024 -p11212 shell> memcached -m 1024 -p11213
To specify a specific network interface, use the
-l option to specify the IP address of the
desired interface:
shell> memcached -l 192.168.0.110
To specify an alternate port to listen on, use the
-p option:
shell> memcached -p 18080
If you are running memcached on the same server
as the clients, you can disable the network interface and use a
local UNIX socket using the -s option:
shell> memcached -s /tmp/memcached
Using a UNIX socket automatically disables network support, and saves network ports (allowing more ports to be used by your web server or other process).
To specify the maximum number of simultaneous connections to the
memcached service, use the -c
option:
shell> memcached -c 2048
You should use this option, either to reduce the number of connections (to prevent overloading memcached service) or to increase the number to make more effective use of the server running memcached server.
By default, memcached is configured to use 4
concurrent threads. The threading improves the performance of
storing and retrieving data in the cache, using a locking system
to prevent different threads overwriting or updating the same
values. You may want to increase or decrease the number of
threads, use the -t option:
shell> memcached -t 8
To run memcached as a daemon (background)
process, use the -d option:
shell> memcached -d
Typically, you would specify the full combination of options that you want when starting memcached, and normally provide a startup script to handle the initialization of memcached. For example, the following line starts memcached with a maximum of 1024MB RAM for the cache, listening on port 11121 on the IP address 192.168.0.110, running has a background daemon:
shell> memcached -d -m 1024 -p 11121 -l 192.168.0.110
To ensure that memcached is started up on boot you should check the init script and configuration parameters. On OpenSolaris, memcached is controlled by SMF. You can enable it by using:
root-shell> svcadm enable memcached

User Comments
Add your own comment.