ItecSoftware Logo

Testing Memcached Using Telnet Commands

Written by Peter Gilg on - like this:
memcached telnet

Troubleshooting memcached is not so transparent as some other technologies, but testing memcached using telnet commands can give us quite some insight on what’s happening under the hood.

The following tutorial on testing memcached with telnet from the command line is a short list of useful commands to inspect a running memcached instance.

How to find the IP address and port to connect

ps aux | grep memcached

The above will give us the process running memcached, with listening ip address and port. If this command does not yield any results, you’re likely not running the daemon and need to start it up first.

We can now connect using this info

telnet 127.0.0.1 11211 (replace your IP address and port)

Supported Commands

The following is a list of the most important memcached commands. For a more complete list of supported commands, check out the memcached wiki document.

Command Description Example
get Reads a value get mykey
set Set a key unconditionally set mykey 0 60 5
add Add a new key add newkey 0 60 5
replace Overwrite existing key replace key 0 60 5
append Append data to existing key append key 0 60 15
prepend Prepend data to existing key prepend key 0 60 15
incr Increments numerical key value by given number incr mykey 2
decr Decrements numerical key value by given number decr mykey 5
delete Deletes an existing key delete mykey
flush_all Invalidate specific items immediately flush_all
Invalidate all items in n seconds flush_all 900
stats Prints general statistics stats
Prints memory statistics stats slabs
Prints memory statistics stats malloc
Print higher level allocation statistics stats items
stats detail
stats sizes
Resets statistics stats reset
version Prints server version. version
verbosity Increases log level verbosity
quit Terminate telnet session qui

Traffic Statistics

$ stats

will give you general info on version, traffic, hits/misses, connections and more.

Example Output:

STAT pid 14868
STAT uptime 175931
STAT time 1220540125
STAT version 1.2.2
STAT pointer_size 32
STAT rusage_user 620.299700
STAT rusage_system 1545.703017
STAT curr_items 228
STAT total_items 779
STAT bytes 15525
STAT curr_connections 92
STAT total_connections 1740
STAT connection_structures 165
STAT cmd_get 7411
STAT cmd_set 28445156
STAT get_hits 5183
STAT get_misses 2228
STAT evictions 0
STAT bytes_read 2112768087
STAT bytes_written 1000038245
STAT limit_maxbytes 52428800
STAT threads 1
END

Memory Statistics:

$ stats slabs

gives you detailed memory statistics

Example Output:

STAT 1:chunk_size 80
STAT 1:chunks_per_page 13107
STAT 1:total_pages 1
STAT 1:total_chunks 13107
STAT 1:used_chunks 13106
STAT 1:free_chunks 1
STAT 1:free_chunks_end 12886
STAT 2:chunk_size 100
STAT 2:chunks_per_page 10485
STAT 2:total_pages 1
STAT 2:total_chunks 10485
STAT 2:used_chunks 10484
STAT 2:free_chunks 1
STAT 2:free_chunks_end 10477
[...]
STAT active_slabs 3
STAT total_malloced 3145436
END

Items Statistics:

$ stats items

lets you know the item count and their age.

Example Output:

stats items
STAT items:1:number 220
STAT items:1:age 83095
STAT items:2:number 7
STAT items:2:age 1405
[...]
END

Using Telnet to get details about memcache is a nice way of looking under the hood or a running production system, where outputting variables in PHP or ASP .NET is not feasible. Zero values in hit/misses indicate that memcache in not used for some reason, connection errors may hint to a networking or permission issue. And with too many evictions you may need to increase the allocated amount of memory.

Listed in Linux, Web Development

Tags: memcache, memcached, telnet

Leave a Reply