Memcached is great and everyone loves it. It’s relatively simple to install and configure and then everything runs much faster. But what if you need to debug it? Can you hook into your Memcached and see what is currently stored in it ? The answer is NO. Memcached is completely blind to its content. Moreover, if you want to see which web/app server writes what object to which Memcached node, there is no simple way to do it. You have to select between the following nontrivial alternatives:
- Install and operate Wireshark (or another sniffing tool) on each of your Memcached nodes or web/app servers and then somehow try to sync between all the recorded files. This is a frustrating task; moreover, when you activate the sniffer your application performance is significantly degraded so you may not be able to emulate your real use case.
- Somehow debug your app code, which again is very complex in a distributed application environment. You need to track each of your web/app servers separately and understand “who writes what” to each of your Memcached nodes.
We are happy to announce that all this is no longer necessary. The new release of our Memcached Cloud Service supports two simple commands that change the way devops debug and analyze their Memcached datasets, as explained below:
Format keys pattern Description
- keys returns all keys matching a pattern, similar to Redis’ KEYS command
- keys supports glob-style pattern matching, e.g.:
- h?llo matches hello, hallo and hxllo
- h*llo matches hllo and heeeello
- h[ae]llo matches hello and hallo, but not hillo
- keys is available via telnet.
The keys command is intended for debugging and for special operations such as changing your keyspace layout. Don’t use keys in your regular application code. In production environment and especially with large datasets, keys should be used with extreme care as it may degrade your application performance.
monitor is a debugging command that streams back all commands processed by your Memcached bucket, similar to the Redis’ MONITOR command. It helps understanding your Memcached dataset and spot bugs in an application. The fact that only one DNS is used to access your resources in our Memcached Cloud service significantly reduces the complexity associated with understanding “who does what” in your environment. Furthermore, although there are some performance implications while running the monitor command, you can still monitor over 10K req/sec with less than 1msec latency, which is good enough for most applications in a debug mode. The monitor command is available via telnet. Manually issue a Memcached quit command via telnet to stop the monitor stream.
Note Each line in the monitor output has the following format:
<unix timstamp> <command name> <key> <flags> <exptime> [<bytes>] [<value>].
- unix timestamp is provided in microsecond granularity
- bytes and value are presented in case of Memcached storage command.
bytes might be zero in which case it’s followed by an empty data block
Want to try it? Register and create your free Memcached bucket in our Memcached Cloud service.