适用于多个 membase 服务器的 Spymemcached 哈希算法
平台:spymemcached-2.7.3.jar,64位Windows 7操作系统
我们有两个membase服务器(非集群环境),我们使用spymemcached java客户端进行设置和获取来自内存缓存的数据。我们没有在两个 membase 服务器之间使用任何复制。
我们使用以下代码在内存缓存中设置数据。看起来 MemcachedClient 总是首先尝试在 server1 中放入/获取数据(如果可用)。如果 server1 关闭,则 MemcachedClient 从 server2 进行放置/获取。 pymemcached 是否使用任何哈希算法来决定需要从哪个服务器设置/获取数据?有可用的文档解释其工作原理吗?
代码
public class Main {
public static void main(String[] args) throws IOException, URISyntaxException {
MemcachedClient client;
URI server1 = new URI("http://192.168.100.111:8091/pools");
URI server2 = new URI("http://127.0.0.1:8091/pools");
ArrayList<URI> serverList = new ArrayList<URI>();
serverList.add(server1);
serverList.add(server2);
client = new MemcachedClient(serverList, "default", "");
client.set("spoon", 50, "Hello World!");
client.shutdown(10, TimeUnit.SECONDS);
System.exit(0);
}
}
Platform: spymemcached-2.7.3.jar, 64 bit Windows 7 OS
We have two membase servers (Non Clustered Environment) and we are using spymemcached java client for setting and getting data from memcache. We are not using any replication between two membase servers.
We are using following code to set data in memcache. Looks like MemcachedClient always first try to put/get data in server1 if its available. If server1 is down, then MemcachedClient put/get from server2.
Does spymemcached uses any hashing algoritham to decide from which server it needs to set/get data? Any documentation available which explains how it works?
code
public class Main {
public static void main(String[] args) throws IOException, URISyntaxException {
MemcachedClient client;
URI server1 = new URI("http://192.168.100.111:8091/pools");
URI server2 = new URI("http://127.0.0.1:8091/pools");
ArrayList<URI> serverList = new ArrayList<URI>();
serverList.add(server1);
serverList.add(server2);
client = new MemcachedClient(serverList, "default", "");
client.set("spoon", 50, "Hello World!");
client.shutdown(10, TimeUnit.SECONDS);
System.exit(0);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
构造函数 MemcachedClient(List, String, String) 将连接到列表中的第一个 URI 以获取有关整个集群的信息。这意味着,如果您的集群中有 10 台服务器,您可以指定一个 IP 地址来连接到所有这些服务器。允许 URI 列表的原因是,如果您从中获取集群信息的服务器出现故障,您可以尝试从集群中的另一台服务器获取集群信息。
本例中 Spymemcached 使用的哈希算法是在集群配置开始时由 Membase 确定的。如果您查看在配置阶段发送到 Spymemcached 的一些 json,您将看到哈希算法是 CRC。有关 CRC 的更多信息,请参阅 DefaultHashAlgorithm 类。
另外,我很好奇你为什么按照描述使用 Membase。
The constructor MemcachedClient(List, String, String) will connect to the first URI in the list to obtain information about the entire cluster. This means that if you had 10 servers in you cluster you can specify one ip address to connect to all of them. The reason a list of URI's is allowed is so that if the server you are getting cluster information from goes down you can try to get cluster information from another server in the cluster.
The hashing algorithm used by Spymemcached in this case is determined by Membase when the cluster configuration begins. If you look through some json that is sent to Spymemcached during the configuration phase you will see the hash algorithm is CRC. Look in the DefaultHashAlgorithm class for more information on CRC.
Also, I'm curious why your using Membase as described.