将Memcached客户端从Memcached-Java-Client迁移到Xmemcached [英] Migrating Memcached client from Memcached-Java-Client to Xmemcached

查看:207
本文介绍了将Memcached客户端从Memcached-Java-Client迁移到Xmemcached的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于danga客户端的旧memcached客户端实现,但稍作修改。我认为这个客户端现在称为 Memcached-Java-Client

I have an old memcached client implementation that is based of the danga client, but was slightly modified. I think this client is now called Memcached-Java-Client.

我手头的实现是旧的,没有维护,似乎是假的。

The implementation I have at hand is old, unmaintained, and seem to be bogus.

我需要将客户端迁移到具有以下约束的较新客户端:

I need to migrate the client to a newer client with the following constraints:


  1. 我需要新的客户端哈希算法与旧的客户端哈希算法兼容。如果不满足此约束,我们将不得不使网站(至少部分)不可用几个小时。

  2. 支持各种序列化方法,并允许序列化方法的可扩展性。 / li>
  3. 改善现有客户端的效果。

  4. Moxi

  1. I need the new client hashing algorithm to be compatible with the old one. If this constraint is not met, we will have to make the site (at least partially) unavailable for a few hours.
  2. Support various serialization methods, and allow extensibility for the serialization method.
  3. Improved performance over my existing client.
  4. Be compatible with Moxi

当前实现使用一致的哈希算法,该算法似乎与 Xmemcached 使用的一致性哈希,但我无法获取由旧客户端并使用Xmemcached客户端获取。

The current implementation uses a consistent hashing algorithm which seemed to be compatible to the consistent hashing used by Xmemcached except that I can't get a cache hit for keys stored by the old client and fetched with the Xmemcached client.

我调试了代码,我得到了相同的哈希码,但我认为服务器环不同,因此整体哈希方法不同。

I debugged the code, and I get the same hashcode, but I think the servers ring is different, and thus the overall hashing method is different.

这是我用来初始化xmemcached客户端的代码:

This is the code I used for initializing the xmemcached client:

  final MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("server:11211 server:11212 server:11213 server:11214"));
  builder.setCommandFactory(new BinaryCommandFactory());
  builder.setSessionLocator(new KetamaMemcachedSessionLocator());
  builder.setTranscoder(new WhalinTranscoder());
  memcachedClient = builder.build();

我还愿意给 spymemcached 如果我不能让xmemcached工作,我会更喜欢后者。

I am willing to also give spymemcached a try if I can't get xmemcached to work, but I prefer the later.

编辑:
我也试过spymemcached,并且不能让它与我当前的客户端兼容。
这是我的spymemcached客户端初始化代码:

I tried spymemcached as well, and can't get it to be compatible with my current client. Here's my spymemcached client initialization code:

final ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
builder.setProtocol(Protocol.BINARY);
builder.setTranscoder(WhalinTranscoder());
builder.setHashAlg(HashAlgorithm.KETAMA_HASH);
builder.setLocatorType(Locator.CONSISTENT);
final MemcachedClient client = MemcachedClient(builder.build(), AddrUtil.getAddresses("server:11211 server:11212 server:11213 server:11214"));


推荐答案

好像我的旧danga客户端与Xmemcached / Spymemcached客户端由于一个简单的原因:
danga客户端哈希主机:端口字符串,而后来的客户端哈希InetSocketAddress,它实际上等于主机/ IP:端口。

It seems like my old danga client is incompatible with the Xmemcached/Spymemcached clients due to a simple reason: The danga client hashes the host:port strings while the later clients hash the InetSocketAddress which is effectively equals to host/IP:port.

由于这个事实,我无法在迁移到新客户端时保持兼容。好吧,实际上Xmemcached和Spymemcached客户端都有一定程度的可扩展性并允许一些支持来实现这一点,但这样做对我的偏好来说太hacky。​​

Due to this fact I am unable to remain compatible when migrating to a newer client. Well, actually both Xmemcached, and Spymemcached clients are somewhat extensible and do allow some support in making this happen, but doing this will be too 'hacky' to my preferences.

我决定根据基准测试结果迁移我的代码以使用Xmemcached / Spymemcached中的一个。两者都与moxi的哈希算法兼容。
我最终可能最终只使用客户端moxi - 取决于它将添加的开销。我最喜欢这个选项,因为它使应用程序配置更加简单。

What I decided to do is to migrate my code to use one of Xmemcached/Spymemcached according to benchmarks results. Both are compatible with moxi's hashing algorithm. I may eventually end up using a client side moxi only - depending on the overhead it will add. I like this option best since it makes the application configuration much simpler.

这篇关于将Memcached客户端从Memcached-Java-Client迁移到Xmemcached的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆