版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan
配合memcache监控程序,测试memcache分布式,文章参考了网上某位牛人的文章。
测试crc32 fnv standard consistent 组合情况下的item分布情况及添加新服务器对现有item命中率的影响。
先开memcached服务器
#!/bin/bash
##############################
# MyZ 2009-07-12
# File:memcached_12.sh
##############################
port=11212
for (( i=11212; i<11224; i++ ))
do
/usr/local/bin/memcached -u root -p $i -m 10 &
done
./memcached.sh
结论
使用memcache这种客户端下的方法保证分配均匀的基础下,存货率做高的是crc32+ consistent。
测试结果
//crc32 standard
192.168.1.101:11212 => items:9812
192.168.1.101:11213 => items:10153
192.168.1.101:11214 => items:9895
192.168.1.101:11215 => items:9985
192.168.1.101:11216 => items:10206
192.168.1.101:11217 => items:9958
192.168.1.101:11218 => items:10159
192.168.1.101:11219 => items:9941
192.168.1.101:11220 => items:9924
192.168.1.101:11221 => items:9967
192.168.1.101:11222 => items:0%
192.168.1.101:11223 => items:0%
//fnv standard
192.168.1.101:11212 => items:9911
192.168.1.101:11213 => items:9978
192.168.1.101:11214 => items:9928
192.168.1.101:11215 => items:10053
192.168.1.101:11216 => items:9952
192.168.1.101:11217 => items:10055
192.168.1.101:11218 => items:10013
192.168.1.101:11219 => items:10089
192.168.1.101:11220 => items:9947
192.168.1.101:11221 => items:10074
192.168.1.101:11222 => items:0
192.168.1.101:11223 => items:0
//crc32 consistent
192.168.1.101:11212 => items:12466
192.168.1.101:11213 => items:10175
192.168.1.101:11214 => items:8436
192.168.1.101:11215 => items:9118
192.168.1.101:11216 => items:11757
192.168.1.101:11217 => items:9208
192.168.1.101:11218 => items:10343
192.168.1.101:11219 => items:8417
192.168.1.101:11220 => items:8716
192.168.1.101:11221 => items:11364
192.168.1.101:11222 => items:0
192.168.1.101:11223 => items:0
//fnv consistent
192.168.1.101:11212 => items:9014
192.168.1.101:11213 => items:13178
192.168.1.101:11214 => items:10053
192.168.1.101:11215 => items:4302
192.168.1.101:11216 => items:10875
192.168.1.101:11217 => items:4906
192.168.1.101:11218 => items:15593
192.168.1.101:11219 => items:9993
192.168.1.101:11220 => items:8093
192.168.1.101:11221 => items:13993
192.168.1.101:11222 => items:0
192.168.1.101:11223 => items:0
用于检测memcache的程序配置部分
for ($i = 11212; $i < 11222; $i++) {
$MEMCACHE_SERVERS[] = '192.168.1.101:'.$i; // add more as an array
}
$MEMCACHE_SERVERS[] = '192.168.1.101:11222'; // add more as an array
$MEMCACHE_SERVERS[] = '192.168.1.101:11223'; // add more as an array
测试代码
- <?php
- /**
- * @name test.php
- * @date Thu Jul 12 21:18:59 CST 2009
- * @copyright 马永占(MyZ)
- * @author 马永占(MyZ)
- * @link http://blog.csdn.net/mayongzhan/
- */
- set_time_limit(0);
- //crc32 standard
- //ini_set('memcache.hash_function','crc32');
- //ini_set('memcache.hash_strategy','standard');
- //crc32 consistent
- ini_set('memcache.hash_function','crc32');
- ini_set('memcache.hash_strategy','consistent');
- //fnv standard
- //ini_set('memcache.hash_function','fnv');
- //ini_set('memcache.hash_strategy','standard');
- //fnv consistent
- //ini_set('memcache.hash_function','fnv');
- //ini_set('memcache.hash_strategy','consistent');
- $memcache_server_ip = '192.168.1.101';
- for ($i = 11212; $i < 11222; $i++) {
- $memcache_servers_ports[] = $i;
- }
- $memcache_servers_ports_add[] = 11222;
- $memcache_servers_ports_add[] = 11223;
- $mem = new Memcache;
- //add servers
- foreach ($memcache_servers_ports as $value) {
- $mem->addServer($memcache_server_ip, $value);
- }
- //set items
- for($i = 0; $i < 100000; $i++) {
- $mem->set($i, $i, 0, 3600);
- }
- //add 2 new servers
- foreach ($memcache_servers_ports_add as $value) {
- $mem->addServer($memcache_server_ip, $value);
- }
- //get items
- for($i = 0; $i < 100000; $i++) {
- $mem->get($i);
- }
- $status = $mem->getExtendedStats();
- foreach ($status as $key=>$value) {
- echo $key
- . ' => items:'
- . $value['curr_items']
- . '<br />';
- }
- $mem->close();
- ?>