Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you know if memcached is doing anything?

I'm testing out using memcached to cache django views. How can I tell if memcached is actually caching anything from the Linux command line?

like image 497
MikeN Avatar asked Mar 10 '09 19:03

MikeN


People also ask

How do I monitor memcache?

Using memcstat. 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. Once again we've filtered stats out to retrieve memcached HITS only.

How do I check my memcache data?

There is no way to get memcached to report which keys it holds. I believe that this was a design choice as to do so would have a negative impact on performance. However, you can use any telnet client application to connect the memcached server and type in commands. Doing this to get or set a particular key.


2 Answers

I know this question is old, but here is another useful approach for testing memcached with django:

As @Jacob mentioned, you can start memcached in very verbose mode (not as a daemon):

memcached -vv 

To test your django cache config, you can use the low-level cache api.

  1. First, start up the python interpreter and load your django project settings:

    python manage.py shell 
  2. From the shell, you can use the low-level cache api to test your memcache server:

    from django.core.cache import cache cache.set('test', 'test value') 

If your cache configuration is correct, you should see output in memcache similar to this:

<32 set :1:test 0 300 10 >32 STORED 
like image 102
lettertwo Avatar answered Oct 08 '22 10:10

lettertwo


You could use the official perl script:

memcached-tool 127.0.0.1:11211 stats  

Or just use telnet and the stats command e.g.:

# telnet localhost [memcacheport] Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. stats STAT pid 2239 STAT uptime 10228704 STAT time 1236714928 STAT version 1.2.3 STAT pointer_size 32 STAT rusage_user 2781.185813 STAT rusage_system 2187.764726 STAT curr_items 598669 STAT total_items 31363235 STAT bytes 37540884 STAT curr_connections 131 STAT total_connections 8666 STAT connection_structures 267 STAT cmd_get 27 STAT cmd_set 30694598 STAT get_hits 16 STAT get_misses 11 STAT evictions 0 STAT bytes_read 2346004016 STAT bytes_written 388732988 STAT limit_maxbytes 268435456 STAT threads 4 END 
like image 20
Node Avatar answered Oct 08 '22 10:10

Node