Skip to content
PAN, Myautsai edited this page Feb 4, 2016 · 3 revisions

Server aliases support

The original problem can be found at https://github.com/twitter/twemproxy/issues/25 .

If you're using libmc in production. It's advised to add alias for each memcached instance, this will make it easier for you to maintain/migrate/monitor a memcached cluster.

A sample of using server alias:

libmc.Client([
    "dis1.prod.douban.com:11211 mc-server111",
    "dis2.prod.douban.com:11211 mc-server112",
])

Why starting with 111?

  1. The range 111 ~ 999 is usually large enough for a memcached cluster.
  2. All memcached instance will have a 3 digit id.
  3. Either by numerical or alphabetical, they're sorted in the same order.

Lazy-connecting

The libmc client may be initialized but never used, for example, in a background daemon process. If we establish the TCP connections immediately after the client is initialized, there will be a lot of idle TCP connection to memcached server, which is not friendly. So, the internal TCP connections in libmc will not be established until the first command(mc.get, mc.set, ...) is called.

gevent compatibility

If you're using libmc under gevent, you can use greenify to patch the libmc to make sure it will not block.

import greenify
greenify.greenify()
import libmc
for so_path in libmc.DYNAMIC_LIBRARIES:
    assert greenify.patch_lib(so_path)

There's also a test case for gevent.

Large values

Memcached server will refuse to store value if size >= 1MB, if do_split is enabled, large value (< 10 MB) will be splitted into several blocks. If the value is too large (>= 10 MB), it will not be stored. This feature is enabled by default.

This feature is deprecated since retrieving a large value may raise high network bandwidth.

Auto failover

If failover is enabled, when a connection is broken, it will be mark as dead and ejected out of the consistent hash ring for a few seconds(5s by default, controlled by libmc.MC_RETRY_TIMEOUT). If failover is disabled, when a connection is broken,it will be mark as dead for a few seconds, but it will not be ejected out of the consistent hash ring. During the dead period, requesting keys routed to that connection(memcached server) will return failures.

Auto failover is disabled by default. If you're using libmc in a distributed environment, it's also not recommended to enable this feature. If one of the libmc clients failed-over but others don't, consistency issue will raise. It's recommended to implement failover in higher level.