自己用php写的一个memache工具zgq_memcache_tools

功能有:

    memache sar  

    读和写key

    dump stats

    压力测试

    得到key列表和memcache里面的交集

    依据key列表将cache信息从一个机器保存到另一个机器

 

 

    详细见:

http://code.google.com/p/memcache-tools/

 

 

粘贴一下:

zgq_memcache_tools.php is memcache tools, include stress,stats,sar and migrate feature

function:

Name:
zgq_memcache_tools.php

SYNOPSIS:
zgq_memcache_tools.php OPTION?

DESCRIPTION:
zgq_memcache_tools.php is memcache tools, include stress,stats,sar and migrate feature

-h memcacheserver:port:weight -h memcacheserver:port:weight ...
-H get -h list from file
>head -3 memcache
c1.xx.zgq.com
c2.xxx.zgq.com
c3.xxx.zgq.com

php -d open_basedir=./ zgq_memcache_tools.php -H memcache -S 300 > xxx.memcache.sar 2>err.log &

-p 1 or 0
use persistent tcp or not
default is 1
-c process_number
fork process_number to run
default is 1
-l loop_count
how many times to loop
default is 100
-m mysql_latency(micro_seconds)
when get miss at memcached, then take a usleep act as get data from db
-g keyname
get value
-s keyname:value:expire
set value (debug, key and value cound not consist of Colon and other sepcial char)
-S N second
print stats info interval N second.
N = 0 just print once
other
:SAR: HEAD: c_c con get set hit%% mis read writ maxb used%% c_it t_i evic t/u/s/n;
:SAR: HEAD: --- --- --- --- ---- --- ---- ---- ---- ---- ---- --- ---- ------
2009-07-29 23:16:11:SAR: xx.xxx.xx: 68 0 0 0 95%% 0 20 323 512M 89%% 346K 0 0 0/0/0
2009-07-29 23:16:12:SAR: xx.xxx.xx: 150 216 1011 87 92%% 84 114K 1M 1024M 89%% 693K 87 1 0/0/0
c_c: curr_connections read: bytes_read, Total number of bytes read by this server from network
con: total_connections writ: bytes_written, Total number of bytes sent by this server to network
get: cmd_get maxb: limit_maxbytes, total memoroy
set: cmd_set used: bytes/limit_maxbytes
hit%%: get_hits/cmd_get c_it: curr_items average
mis: get_misses t_i: total_items delta
evic: evictions Number of valid items removed from cache to free memory for new items
t/u/s: everage of threads,rusage_user,rusage_system
-d debug_level
0 result
1 record error
2 record warning
3 key info
4
5 value info
default is 0
-r read/write ratio
0 all read
-1 all read

-i input filename
if with -c N , then will split infile(with split tool) to N files and each one process dealwith one subfile
file format:
valuelength expiretime key
-o output filename
if with -c N , then will split outfile to N files and each one process dealwith one subfile
file format:
valuelength expiretime key

-D dump
how many item to dump from every one slab
N: N items to dump
default: is 100 items
all: try to dump all items, but due to memcached theory, only dump a little items.
-e expiretime
default is 1day(86400)
-M memcacheserver:port:weight -h memcacheserver:port:weight ...
fetch data from -h and save to -M
filter: filter a key_list as -h memcached server
(when set key/value in -M memserver, will use -e expiretime as expire, you should set it as small as possible)
(only set key to -M memserver, when get key from -M failed)

example:
save 1M items(created by md5(rand())) into memcached and save record to lista-? file
php -d open_basedir=./ zgq_memcache_tools.php -h localhost:11211 -c 10 -l 100000 -o lista

figure out key list(filterin) when it in -h localhost and save it to file filterout
php -d open_basedir=./ zgq_memcache_tools.php -h localhost:11211 -M filter -i filterin -o filterout

fetch avail value from -h and set to -M follow all key from -i file
php zgq_memcache_tools.php -h localhost:11211 -M localhost:11212 -i cache.save-0
php zgq_memcache_tools.php -h localhost:11211 -M localhost:11212 -i cache.save-1
php zgq_memcache_tools.php -h localhost:11211 -M localhost:11212 -i cache.save-2

get stats once
php zgq_memcache_tools.php -h localhost:11212 -S 0

hostname: localhost:11212
Array
(
item begin end delta ops
--------------------- ------------ ------------ ------------
pid => 17519 17519 = 0 = 0
uptime => 523229 523233 = 4 = 1
time => 1249073748 1249073752 = 4 = 1
version => 1 1 = 0 = 0
pointer_size => 32 32 = 0 = 0
rusage_user => 3552 3552 = 0 = 0
rusage_system => 13404 13404 = 0 = 0
curr_items => 710238 710337 = 99 = 25
total_items => 36510987 36511262 = 275 = 69
bytes => 956824276 956833975 = 9699 = 2425
curr_connections => 121 121 = 0 = 0
total_connections => 120080277 120080494 = 217 = 54
connection_structures? => 1004 1004 = 0 = 0
cmd_get => 544658981 544660167 = 1186 = 297
cmd_set => 36510987 36511262 = 275 = 69
get_hits => 517650584 517651514 = 930 = 233
get_misses => 27008397 27008653 = 256 = 64
evictions => 3858945 3858945 = 0 = 0
bytes_read => 2147483647 2147483647 = 258265 = 64566
bytes_written => 2147483647 2147483647 = 1193630 = 298408
limit_maxbytes => 1073741824 1073741824 = 0 = 0
threads => 4 4 = 0 = 0
--------------------- performance -----------------------------
get_hits/cmd_get => 95% 95%
cmd_set/cmd_get => 7% 7%
get_misses/cmd_get => 5% 5%
evictions/total_items? => 11% 11%
bytes/limit_maxbytes => 89% 89%

get stats like sar per 5 seconds
php zgq_memcache_tools.php -h localhost:11212 -S 5
:SAR: HEAD: c_c con get set hit% mis read writ maxb used c_it t_i evic t/u/s
:SAR: HEAD: --- --- --- --- ---- --- ---- ---- ---- ---- ---- --- ---- ------
2009-08-01 04:56:43:SAR:xx.xxx~211: 62 0 0 0 95% 0 32 510 512M 89% 347K 0 0 2/2K/7K
2009-08-01 04:56:48:SAR:xx.xxx~211: 122 44 247 33 87% 32 47K 291K 1024M 89% 694K 33 0 4/3K/13K
2009-08-01 04:56:53:SAR:xx.xxx~211: 121 39 190 29 86% 26 40K 212K 1024M 89% 694K 29 0 4/3K/13K
2009-08-01 04:56:58:SAR:xx.xxx~211: 121 41 247 41 85% 38 57K 283K 1024M 89% 694K 41 0 4/3K/13K
2009-08-01 04:57:03:SAR:xx.xxx~211: 123 45 255 43 84% 42 59K 288K 1024M 89% 694K 43 0 4/3K/13K
2009-08-01 04:57:08:SAR:xx.xxx~211: 124 40 235 48 79% 48 70K 246K 1024M 89% 694K 48 0 4/3K/13K
2009-08-01 04:57:13:SAR:xx.xxx~211: 123 47 270 41 87% 35 54K 313K 1024M 89% 694K 41 0 4/3K/13K
2009-08-01 04:57:18:SAR:xx.xxx~211: 123 49 227 35 87% 30 45K 246K 1024M 89% 694K 35 0 4/3K/13K
2009-08-01 04:57:23:SAR:xx.xxx~211: 121 44 269 29 90% 27 41K 335K 1024M 89% 694K 29 0 4/3K/13K
2009-08-01 04:57:28:SAR:xx.xxx~211: 120 41 246 43 84% 39 59K 266K 1024M 89% 694K 43 0 4/3K/13K
:SAR: HEAD: c_c con get set hit% mis read writ maxb used c_it t_i evic t/u/s
:SAR: HEAD: --- --- --- --- ---- --- ---- ---- ---- ---- ---- --- ---- ------
2009-08-01 04:57:33:SAR:xx.xxx~211: 121 47 231 27 88% 29 38K 260K 1024M 89% 694K 27 0 4/3K/13K

)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值