Introducing Dragonfly Cloud! Learn More

Question: How to check Memcached memory usage?

Answer

There are a few ways to check the memory usage of your running Memcached instance. Here are some options:

1. Via "stats" command

You can use the stats command to get various statistics about your Memcached server, including its current memory usage. To do so, you can connect to the server using telnet and issue the following commands:

$ telnet localhost 11211 stats

This will output a lot of information about the server, but one of the lines should look like this:

STAT limit_maxbytes 67108864

The limit_maxbytes value represents the maximum amount of memory that Memcached is allowed to use, in bytes. You can compare this with other stats such as bytes or bytes_used to see how much memory is currently being used.

2. Via "stats items" command

Another way to see the memory usage of your Memcached server is to use the stats items command. This will display statistics for each slab class (a slab class is a set of items with similar sizes). Here's an example:

$ telnet localhost 11211 stats items

This will output something like:

STAT items:1:number 4
STAT items:1:age 13636
STAT items:1:evicted 0
STAT items:1:evicted_nonzero 0
STAT items:1:evicted_time 0
STAT items:1:outofmemory 0
STAT items:1:tailrepairs 0
STAT items:1:reclaimed 32
STAT items:1:expired_unfetched 0
STAT items:2:number 12
STAT items:2:age 109726
STAT items:2:evicted 0
...

The number value for each slab class represents the number of items in that class, and the age value represents the age of the oldest item in the class. You can use this information to get an idea of how much memory is being used by each slab class.

3. Via "ps" command

Finally, you can use the ps command to see how much memory the Memcached process is using overall. Here's an example:

$ ps aux | grep memcached memcached 1764 0.0 0.1 13752 3428 ? Ssl Apr26 0:00 /usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1

In this example, the RES column shows the amount of physical memory (in kilobytes) that the Memcached process is currently using. Note that this includes both the memory used by the cache data as well as any overhead required by the Memcached process itself.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.