My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
下面几行注释是启动memcache的bash脚本
#!/bin/sh
port=11211
while test $port -lt 11223
do
/usr/local/bin/memcached -p $port &
port=$(($port+1))
done
*/
$host='127.0.0.1';
$test_num=10000;
$ports=range(11211,11220);
$ports_add=range(11221,11222);
$strategies=array('consistent','standard');
$hashes=array('crc32','fnv');
echo '测试数目:',$test_num,"\n-------\n";
foreach ($strategies as $strategy) {
foreach ($hashes as $hash) {
ini_set('memcache.hash_strategy',$strategy);
ini_set('memcache.hash_function',$hash);
echo '哈希策略:',$strategy,"\n";
echo '哈希函数:',$hash,"\n";
$mc=new Memcache;
foreach ($ports as $port) {
$mc->addServer($host,$port);
}

$mc->flush();
for ($i=0;$i<$test_num;$i++) {
$mc->set($i,$i);
}

echo "分布:\n";
foreach ($ports as $port) {
$single_mc=new Memcache();
$single_mc->connect($host,$port);
$get_num=0;
for ($i=0;$i<$test_num;$i++) {
if ($single_mc->get($i)) {
$get_num++;
}
}
echo ' port:',$port,':',round($get_num/$test_num,4)*100,"%\n";
unset($single_mc);
}

foreach ($ports_add as $port) {
$mc->addServer($host,$port);
}

$get_num=0;
for ($i=0;$i<$test_num;$i++) {
if ($mc->get($i)) {
$get_num++;
}
}

echo '存活率:';
echo round($get_num/$test_num,4)*100,'%';
echo "\n-------\n";
unset($mc);
}
}

Change log

r145 by surfchen on Dec 27, 2008   Diff
mchash test里加入启动memcache的示例代码
Go to: 
Project members, sign in to write a code review

Older revisions

r144 by surfchen on Dec 27, 2008   Diff
mchash test里加入启动memcache的示例代码
r143 by surfchen on Dec 26, 2008   Diff
add memcache_hash_test
All revisions of this file

File info

Size: 1682 bytes, 65 lines
Powered by Google Project Hosting