设为首页 加入收藏

TOP

memcache 分布式缓存(三)
2017-10-10 10:21:04 】 浏览:3619
Tags:memcache 分布式
ched($key); 112 return $m->get($key); 113 } 114 115 116 } 117 118 ?>

3)、测试

1、查看所有虚拟节点

一共64*3=132个虚拟节点(虚拟节点设置还是属于偏少的,一般都会设置在100~200)

技术分享

技术分享

2、set测试

 1 include ‘./ConsistentHashMemcache.class.php‘;
 2 header("content-type: text/html;charset=utf8;");
 3 $arr=array(
 4     ‘node1‘=>array(‘host‘=>‘192.168.95.11‘, ‘port‘=>‘11210‘),
 5     ‘node2‘=>array(‘host‘=>‘192.168.95.11‘, ‘port‘=>‘11211‘),
 6     ‘node3‘=>array(‘host‘=>‘192.168.95.11‘, ‘port‘=>‘11212‘),
 7     );
 8 
 9 $c=new ConsistentHashMemcache($arr);
10 
11 #测试set
12 $c->setKey(‘aaa‘, ‘11111‘);
13 $c->setKey(‘bbb‘, ‘22222‘);
14 $c->setKey(‘ccc‘, ‘33333‘);

 

技术分享

分别telnet连接192.168.95.11:(11210、11211、11212)

在节点node1中get(‘aaa’)、get(‘bbb’)能取到值

在节点node3中get(‘ccc’)能取到值

3、get测试

 1 include ‘./ConsistentHashMemcache.class.php‘;
 2 header("content-type: text/html;charset=utf8;");
 3 $arr=array(
 4     ‘node1‘=>array(‘host‘=>‘192.168.95.11‘, ‘port‘=>‘11210‘),
 5     ‘node2‘=>array(‘host‘=>‘192.168.95.11‘, ‘port‘=>‘11211‘),
 6     ‘node3‘=>array(‘host‘=>‘192.168.95.11‘, ‘port‘=>‘11212‘),
 7     );
 8 
 9 $c=new ConsistentHashMemcache($arr);
10 #测试get
11 echo $c->getKey(‘aaa‘).‘<br/>‘;
12 echo $c->getKey(‘bbb‘).‘<br/>‘;
13 echo $c->getKey(‘ccc‘).‘<br/>‘;

技术分享

4、优缺点

  相对于取模方式分布式,一致性哈希方式分布式的代码复杂性要高一点,但这也在可以接受的范围内,不构成任何阻碍问题。相反它的优点就非常显著,通过虚拟节点的方式实现,可以使不可控的存储节点能够尽可能的均匀分布在圆环上,从而达到数据均匀缓存在各个主机里。其次增加与删除虚拟节点对于之前缓存的整体数据影响非常小。

 

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇WAMP环境配置-Apache服务器的安装 下一篇WAMP环境配置-Apache服务器的安装

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目