diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2016-05-11 19:38:00 +0200 |
---|---|---|
committer | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-05-11 19:38:00 +0200 |
commit | e03f9e8103d7b9a8336c551d0f8ecee029f29723 (patch) | |
tree | d9008fdf402dc9992d149fe1361e3a2fc3a84e0f | |
parent | 3333c4c0b9476eb35ac6a41727b06f628c6bda2d (diff) | |
download | nextcloud-server-e03f9e8103d7b9a8336c551d0f8ecee029f29723.tar.gz nextcloud-server-e03f9e8103d7b9a8336c551d0f8ecee029f29723.zip |
allow configuration of memcached options (#23729)
* allow configuration of memcache options
Use production values for memcached as explained in http://apprize.info/php/scaling/15.html
The current implementiation uses ascii based serialization. This PR should reduce traffic to the memcached server.
cc @MorrisJobke @FelixBoehm
* add config sample
* merge config options, throw hint on config error
* fix typo
* fix config sample
-rw-r--r-- | config/config.sample.php | 24 | ||||
-rw-r--r-- | lib/private/Memcache/Memcached.php | 30 |
2 files changed, 54 insertions, 0 deletions
diff --git a/config/config.sample.php b/config/config.sample.php index 0027a533368..2290df8b52b 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -922,6 +922,30 @@ $CONFIG = array( //array('other.host.local', 11211), ), +/** + * Connection options for memcached, see http://apprize.info/php/scaling/15.html + */ +'memcached_options' => array( + // Set timeouts to 50ms + \Memcached::OPT_CONNECT_TIMEOUT => 50, + \Memcached::OPT_RETRY_TIMEOUT => 50, + \Memcached::OPT_SEND_TIMEOUT => 50, + \Memcached::OPT_RECV_TIMEOUT => 50, + \Memcached::OPT_POLL_TIMEOUT => 50, + + // Enable compression + \Memcached::OPT_COMPRESSION => true, + + // Turn on consistent hashing + \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, + + // Enable Binary Protocol + \Memcached::OPT_BINARY_PROTOCOL => true, + + // Binary serializer vill be enabled if the igbinary PECL module is available + //\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_IGBINARY, +), + /** * Location of the cache folder, defaults to ``data/$user/cache`` where diff --git a/lib/private/Memcache/Memcached.php b/lib/private/Memcache/Memcached.php index a30f9da7ed7..63ac73e9b9d 100644 --- a/lib/private/Memcache/Memcached.php +++ b/lib/private/Memcache/Memcached.php @@ -26,6 +26,7 @@ namespace OC\Memcache; +use OC\HintException; use OCP\IMemcache; class Memcached extends Cache implements IMemcache { @@ -52,6 +53,35 @@ class Memcached extends Cache implements IMemcache { } } self::$cache->addServers($servers); + + $defaultOptions = [ + \Memcached::OPT_CONNECT_TIMEOUT => 50, + \Memcached::OPT_RETRY_TIMEOUT => 50, + \Memcached::OPT_SEND_TIMEOUT => 50, + \Memcached::OPT_RECV_TIMEOUT => 50, + \Memcached::OPT_POLL_TIMEOUT => 50, + + // Enable compression + \Memcached::OPT_COMPRESSION => true, + + // Turn on consistent hashing + \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, + + // Enable Binary Protocol + \Memcached::OPT_BINARY_PROTOCOL => true, + ]; + // by default enable igbinary serializer if available + if (\Memcached::HAVE_IGBINARY) { + $defaultOptions[\Memcached::OPT_SERIALIZER] = + \Memcached::SERIALIZER_IGBINARY; + } + $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []); + if (is_array($options)) { + $options = $options + $defaultOptions; + self::$cache->setOptions($options); + } else { + throw new HintException("Expected 'memcached_options' config to be an array, got $options"); + } } } |