Most Drupal website administrators are interested in quickly monitoring memcache's statistics, and the
nc command (on some systems,
netcat) is a useful command for interacting with memcache servers.
Find the servers
As a preliminary step, you'll need a list of the memcache servers that Drupal is using. As an Acquia Cloud customer, you can find your memcache servers by navigating to the Application > Environment > Servers page in the Acquia Cloud UI. Find the "web" server(s) that have "Memcache" and note their full DNS name (e.g. "web-123.prod.hosting.acquia.com").
If you have a Drupal 6 or Drupal 7 application, you can use the following Drush command to look up the
drush vget memcache_servers
The output should look something like this:
memcache_servers: Array ( [server-1234.prod.hosting.acquia.com:11211] => default [server-5678.prod.hosting.acquia.com:11211] => default )
This array is automatically populated on Acquia Cloud servers using memcache.
The format of the servers' array is
hostname:port => bin. In the sample output, the default memcache bin is split across two memcache hosts —
server-5678.prod.hosting.acquia.com, using port 11211 on each host.
View memcache statistics
The Memcached protocol provides a
stats command that can provide some insight into a few dozen server variables. Many of these server variables count the number of times a particular event occurred since the service was launched.
In this example, we echo two commands together:
stats, followed by
quit (separated by a newline). The
-q1 option tells the
nc command to not disconnect immediately. Without this option,
nc might close the connection before it delivers the output.
/bin/echo -e 'stats\nquit' | nc -q1 [memcache hostname] [port number]
Here's an example using server information from the previous example:
/bin/echo -e 'stats\nquit' | nc -q1 $(hostname -s) 11211
The output of the preceding command should look similar to the following:
STAT pid 1216 STAT uptime 2472376 STAT time 1373572082 STAT version 1.4.5 STAT pointer_size 64 STAT rusage_user 66.790000 STAT rusage_system 110.900000 STAT curr_connections 3 STAT total_connections 297279 STAT connection_structures 10 STAT cmd_get 2115470 STAT cmd_set 92126 STAT cmd_flush 0 STAT get_hits 1918776 STAT get_misses 196694 STAT delete_misses 806 STAT delete_hits 1566 STAT incr_misses 0 STAT incr_hits 19 STAT decr_misses 0 STAT decr_hits 0 STAT cas_misses 0 STAT cas_hits 0 STAT cas_badval 0 STAT auth_cmds 0 STAT auth_errors 0 STAT bytes_read 346432348 STAT bytes_written 3932785939 STAT limit_maxbytes 67108864 STAT accepting_conns 1 STAT listen_disabled_num 0 STAT threads 1 STAT conn_yields 0 STAT bytes 46704290 STAT curr_items 21955 STAT total_items 92127 STAT evictions 13531 STAT reclaimed 0 END
Monitor memcache statistics
You can use the
watch command to monitor all of these statistics in real time. For example:
watch -d -n 10 "/bin/echo -e 'stats\nquit' | nc -q1 $(hostname -s) 11211"
-d option to the watch command highlights the parts of the output that have changed since the last output. The
-n option sets a delay interval; in this example, it's set to 10 seconds.
In most cases, when a particular part of a Drupal page appears "stuck" in cache, you should use the
drush cache-clear command. This command can clear a specific cache that appears to be problematic. In extremely rare circumstances you may need to manually trigger a memcache flush. For Drupal 7 websites, you may need to trigger a registry rebuild function. (For more information, see the Registry Rebuild module on drupal.org.) If these processes fail, you can attempt a manual memcache flush. The memcache protocol
flush command allows you to immediately flag all stored values as invalid.