I am working on ensuring our app degrades gracefully in case of a complete cache outage, which is highly unlikely, as we have minimum of at least 3 cache nodes to add to the cache pool, by way of PHP's memcached addServer
api call. However, it is possible that a single node may fail, and I need to ensure that the memcached api correctly handles this scenario.
Here is my current cache.yml config
port: 11211
<?php echo Hobis_Api_Cache::TYPE_VOLATILE; ?>:
options:
- <?php echo Memcached::OPT_CONNECT_TIMEOUT; ?>: 25<?php echo PHP_EOL; ?>
#- <?php echo Memcached::OPT_DISTRIBUTION; ?>: <?php echo Memcached::DISTRIBUTION_CONSISTENT; ?><?php echo PHP_EOL; ?>
- <?php echo Memcached::OPT_LIBKETAMA_COMPATIBLE; ?>: true<?php echo PHP_EOL; ?>
- <?php echo Memcached::OPT_NO_BLOCK; ?>: true<?php echo PHP_EOL; ?>
#- <?php echo Memcached::OPT_POLL_TIMEOUT; ?>: 100<?php echo PHP_EOL; ?>
#- <?php echo Memcached::OPT_RECV_TIMEOUT; ?>: 10000<?php echo PHP_EOL; ?>
- <?php echo Memcached::OPT_REMOVE_FAILED_SERVERS; ?>: true<?php echo PHP_EOL; ?>
- <?php echo Memcached::OPT_RETRY_TIMEOUT; ?>: 1<?php echo PHP_EOL; ?>
#- <?php echo Memcached::OPT_SEND_TIMEOUT; ?>: 10000<?php echo PHP_EOL; ?>
- <?php echo Memcached::OPT_SERIALIZER; ?>: <?php echo Memcached::SERIALIZER_IGBINARY; ?><?php echo PHP_EOL; ?>
#- <?php echo Memcached::OPT_SERVER_FAILURE_LIMIT; ?>: 1<?php echo PHP_EOL; ?>
- <?php echo Memcached::OPT_TCP_NODELAY; ?>: true<?php echo PHP_EOL; ?>
servers:
- vcache-1
- vcache-2
- vcache-3
<?php echo Hobis_Api_Cache::TYPE_PERSISTENT; ?>:
servers:
- pcache-1
Based on some research (here and here), it's possible for the memcached api to gracefully handle a single node outage, if part of a pool. However in my case, I am unable to write specific keys during testing. Instead I get an 'unable to write' error with a resultCode of 35, which according to the comments, is MEMCACHED_SERVER_MARKED_DEAD
.
Having a server marked dead is indeed what I would expect, as I stopped vcache-2/3 and only vcache-1 is running, however, with the OPT_LIBKETAMA_COMPATIBLE
option, I am under the impression that the memcached api is to write the key to another server in the pool. And that with the OPT_REMOVE_FAILED_SERVERS
option, I shouldn't be seeing the marked dead result codes, because the server should be removed from the pool.
Any suggestions?