多个内存缓存服务器问题 [英] Multiple memcached servers question

查看:123
本文介绍了多个内存缓存服务器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设-如果我有多个这样的内存缓存服务器:

//PHP 
$MEMCACHE_SERVERS = array(
    "10.1.1.1", //web1
    "10.1.1.2", //web2
    "10.1.1.3", //web3 
); 
$memcache = new Memcache();
foreach($MEMCACHE_SERVERS as $server){
    $memcache->addServer ( $server ); 
}

然后我像这样设置数据:

$huge_data_for_frong_page = 'some data blah blah blah';
$memcache->set("huge_data_for_frong_page", $huge_data_for_frong_page);

然后我像这样检索数据:

$huge_data_for_frong_page = $memcache->get("huge_data_for_frong_page");

当我要从memcached服务器检索此数据时- php memcached客户端如何知道要查询该数据的服务器?还是memcached客户端要查询所有memcached服务器?

When i would to retrieve this data from memcached servers - how would php memcached client know which server to query for this data? Or is memcached client going to query all memcached servers?

推荐答案

您可以写有关这本书的书,但基本原理是有一些不同的方法.

Well you could write books about that but the baseic principle is that there are some different approaches.

最常见且有意义的缓存方法是分片.这意味着仅在一台服务器上存储数据,并且使用某种方法来确定这是哪台服务器.因此可以从这台服务器上获取它,而只涉及一台服务器.

The most common and senseful approach for caching is sharding. Which means the data is sotred only on one server and some method is used to determining which server this is. So it can be fetched from this very server and only one server is involved.

这显然在像memcached这样的键/值环境中很好用.

This obviously works well in key/value environments as memcached.

一种常见的做法是对密钥进行加密哈希处理.计算此哈希MOD服务器数,结果就是您将存储并获取数据的服务器.

A common practice is to take a cryptographical hash of the key. Calculate this hash MOD number of servers and the result is the server you will store and fetch the data.

此过程产生或多或少相等的平衡.

This procedure produces more or less equal balancing.

我确实不知道如何在memcached中完成它,但是肯定要进行某种哈希处理.

How its exactly done in memcached i dunno but some sort of hash for sure.

但是请注意,这种技巧不是高度可用的.因此,如果一台服务器发生故障,则条目将消失.因此,您显然只能将其用于缓存.

But beware that this teqnique is not highly available. So if one server fails the entries are gone. So you obviously can only use this for caching purposes.

其他需要大量资源才能使用的技术,这些技术需要花费很长时间才能计算出来,并且会在背景中自动进行预热,包括复制.

Other teqniques, where for example high availability of resources is necessary, that take long to calculate and are automatiaclly warmed up int he background, involve replication.

在缓存环境中最常见的形式是具有最新时间戳冲突解决功能的主-主复制.从根本上讲,这意味着每台服务器都从尚未在本地服务器上的每台服务器获取数据(这是使用复制日志和字节偏移量完成的).如果发生冲突,则使用最新版本(忽略服务器之间的微小时间偏移).

The most common form in caching environments is master-master replication with latest-timestamp conflict resolving. Which bascically means every server gets the data from everyserver that is not yet on the local server (this is done using replication logs and byte offsets). If there is a conflict the latest version is used (the slight time offset between servers is ignored).

但是在其他情况下,例如只写很少的东西却读很多东西的环境中,通常会发生级联,其中只涉及一个或几个主服务器,而其余的只是纯读复制.

But in other environments where for examply only very little is written but a lot is read there is often a cascade where only one or few master servers are involved and the rest is just pure read replication.

但是这些设置非常罕见,因为上述分片可提供最佳性能,并且在缓存环境中,数据丢失几乎可以容忍.因此它也是memcached的默认设置.

But theese setups are very rare because sharding as describeda bove gives the best performance and in caching environments data loss is mostly tolerable. so its also default for memcached.

这篇关于多个内存缓存服务器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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