注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

隐龙 为了一生的信念

今日默默沉于水,他日飞腾在九天...

 
 
 

日志

 
 

【转载】Java开发中的Memcache原理及实现(五)测试Memcached流程  

2014-04-10 14:00:19|  分类: JAVA |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
 
、            测试Memcached流程

此处以二机集群为例。


1. 启动Memcached及代理

启动两个memcached进程,端口分别为11211和11212:

memcached -m 1 -u root -d -l 127.0.0.1 -p 11211

memcached -m 1 -u root -d -l 127.0.0.1 -p 11212

再启动两个magent进程,端口分别为10000和11000:

magent -u root -n 51200 -l 127.0.0.1 -p 10000 -s 127.0.0.1:11211 -b 127.0.0.1:11212

magent -u root -n 51200 -l 127.0.0.1 -p 11000 -s 127.0.0.1:11212 -b 127.0.0.1:11211

-s 为要写入的memcached, -b 为备份用的memcached。

说明:测试环境用magent和memached的不同端口来实现,在生产环境中可以将magent和memached作为一组放到两台服务器上。也就是说通过magent能够写入两个memcached。


2. 数据读写测试

[root@odb ~]# telnet 127.0.0.1 10000

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

set key 0 0 8                       <—在10000端口设置key的值

88888888

STORED

quit

Connection closed by foreign host.

 

[root@odb ~]# telnet 127.0.0.1 11211

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

get key                     <—在11211端口获取key的值成功

VALUE key 0 8

88888888

END

quit

Connection closed by foreign host.

 

[root@odb ~]# telnet 127.0.0.1 11212

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

get key                     <—在11212端口获取key的值成功

VALUE key 0 8

88888888

END

quit

Connection closed by foreign host.


3. 高可靠性测试

[root@odb ~]# ps aux |grep -v grep |grep memcached

root     23455  0.0  0.0  5012 1796 ?        Ss   09:22   0:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11212

root     24950  0.0  0.0  4120 1800 ?        Ss   10:58   0:00 memcached -m 1 -u root -d -l 127.0.0.1 -p 11211

[root@odb ~]# ps aux |grep -v grep |grep ‘magent -u’

root     25919  0.0  0.0  2176  484 ?        Ss   12:00   0:00 magent -u root -n 51200 -l 127.0.0.1 -p 10000 -s 127.0.0.1:11211 -b 127.0.0.1:11212

root     25925  0.0  0.0  3004  484 ?        Ss   12:00   0:00 magent -u root -n 51200 -l 127.0.0.1 -p 11000 -s 127.0.0.1:11212 -b 127.0.0.1:11211

 

[root@odb ~]# telnet 127.0.0.1 10000

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

set stone 0 0 6                      <—在10000端口设置stone的值

123456

STORED

quit

Connection closed by foreign host.

 

[root@odb ~]# telnet 127.0.0.1 11000

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

set shidl 0 0 6                 <—在11000端口设置shidl的值

666666

STORED

get stone                     <—在11000端口获取stone的值成功

VALUE stone 0 6

123456

END

incr stone 2                   <—在11000端口修改stone的值成功

123458

get stone

VALUE stone 0 6               <—在11000端口验证stone的值,证明上面的修改成功

123458

END

get shidl                     <—在11000端口获取shidl的值成功

VALUE shidl 0 6

666666

END

quit                             <—退出11000端口

Connection closed by foreign host.

 

[root@odb ~]# telnet 127.0.0.1 10000

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

get stone                     <—在10000端口获取stone的值,已被修改

VALUE stone 0 6

123458

END

get shidl                      <—在10000端口获取shidl的值成功

VALUE shidl 0 6

666666

END

delete shidl                   <—在10000端口删除shidl

DELETED

get shidl                      <—在10000端口删除shidl生效

END

quit

Connection closed by foreign host.

 

[root@odb ~]# telnet 127.0.0.1 11000

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

get shidl                      <—在11000端口验证删除shidl生效

END

get stone                     <—在11000端口获取stone的值成功

VALUE stone 0 6

123458

END

quit

Connection closed by foreign host.


4. Down机模拟测试1
1)      Down掉11211端口的memcached

[root@odb ~]# kill -9 24950

[root@odb ~]# telnet 127.0.0.1 10000

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

get stone                      <—在10000依然可以获取stone的值

VALUE stone 0 6

123458

END

quit

Connection closed by foreign host.

 

[root@odb ~]# telnet 127.0.0.1 11000

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

get stone                      <—在11000依然可以获取stone的值

VALUE stone 0 6

123458

END

quit

Connection closed by foreign host.

 


5. Down机模拟测试2
1)      Down掉11000端口的magent

[root@odb ~]# kill -9 25925

[root@odb ~]# telnet 127.0.0.1 10000

Trying 127.0.0.1…

Connected to localhost.localdomain (127.0.0.1).

Escape character is ‘^]’.

get stone                      <—在10000依然可以获取stone的值

VALUE stone 0 6

123458

END

quit

Connection closed by foreign host.

 


2)      重启11000端口的magent

[root@lh-web-test memcached-1.4.5]# magent -u root -n 51200 -l 127.0.0.1 -p 11000 -s 127.0.0.1:11212 -b 127.0.0.1:11211

[root@lh-web-test memcached-1.4.5]# telnet 127.0.0.1 11000

Trying 127.0.0.1...

Connected to localhost.localdomain (127.0.0.1).

Escape character is '^]'.

get stone                                         <—在11000依然可以获取stone的值

VALUE stone 0 6

123458

END

quit

Connection closed by foreign host.

  评论这张
 
阅读(455)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017