Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some useful tips/tools for monitoring/tuning memcached health?

Tags:

memcached

Yesterday, I found this cool script 'memcache-top' which nicely prints out stats of memcached live. It looks like,

memcache-top v0.6       (default port: 11211, color: on, refresh: 3 seconds)

INSTANCE                USAGE   HIT %   CONN    TIME    EVICT/s READ/s  WRITE/s
127.0.0.1:11211         88.8%   94.8%   20      0.8ms   9.0     311.3K  162.8K

AVERAGE:                88.8%   94.8%   20      0.8ms   9.0     311.3K  162.8K

TOTAL:          1.8GB/  2.0GB           20      0.8ms   9.0     311.3K  162.8K
(ctrl-c to quit.)

it even makes certain text red when you should pay attention to something!

Q. Broadly, what are some useful tools/techniques you've used to check that memcached is set up well?

like image 678
David Lam Avatar asked Apr 19 '13 17:04

David Lam


People also ask

What are the best Memcached settings to improve performance?

The most important setting influenced overall performance: number of threads -t. The default value of 4 is a good choice for almost every setup. Avoid using more than eight threads, it leads to high lock contention inside of Memcached and performance degrade. A configuration with a single thread should never be used, even on a single-core machine.

How many threads should be used in Memcached?

Avoid using more than eight threads, it leads to high lock contention inside of Memcached and performance degrade. A configuration with a single thread should never be used, even on a single-core machine. A compare-and-swap operation of Memcached requires a separate Item field to store unique CAS values.

How do I check if a Memcached server is running or not?

The number will then increase as soon as there’s data coming in through the memcached daemon. Installing the libmemcached-tools package will give you access to the memcstat command, which displays the operating status of a single or group of memcached servers. Usage is very simple.

Why Memcached takes so long to retrieve?

Memcached is designed to serve many connections simultaneously and with tens of connections you will achieve much better performance. Store Items over TCP, retrieve over UDP. As was said: the network transportation is a main source of delays. On a high data volume, TCP packet size overhead can significantly impact overall performance.


2 Answers

Good interface to accessing Memcached server instances is phpMemCacheAdmin.

I prefer access from the command line using telnet.

To make a connection to Memcached using Telnet, use the following telnet localhost 11211 command from the command line.

If at any time you wish to terminate the Telnet session, simply type quit and hit return.

You can get an overview of the important statistics of your Memcached server by running the stats command once connected.

Memory is allocated in chunks internally and constantly reused. Since memory is broken into different size slabs, you do waste memory if your items do not fit perfectly into the slab the server chooses to put it in.

So Memcached allocates your data into different "slabs" (think of these as partitions) of memory automatically, based on the size of your data, which in turn makes memory allocation more optimal.

To list the slabs in the instance you are connected to, use the stats slab command.

A more useful command is the stats items, which will give you a list of slabs which includes a count of the items store within each slab.

Now that you know how to list slabs, you can browse inside each slab to list the items contained within by using the stats cachedump [slab ID] [number of items, 0 for all items] command.

If you want to get the actual value of that item, you can use the get [key] command.

To delete an item from the cache you can use the delete [key] command.

like image 118
Jack Avatar answered Oct 12 '22 19:10

Jack


For a production systems, you should really set up active monitoring (with downtime alerts, automated restarts etc.) of Memcache using something like Monit. Here is an example config: Monitoring Memcache with Monit

like image 45
alphadevx Avatar answered Oct 12 '22 20:10

alphadevx