试验环境和IP
服务器:10.10.64.83
客户端:10.10.64.82
配置
2颗Intel(R) Xeon(R) CPU E5620 @ 2.40GHz
服务器启动参数
./memcached -d -m 1024 -p 11211 -P /tmp/memcached.pid -c 1024 -f 1.25 -n 80 -t 16
客户端代码
单线程循环一万次,然后计算每次的时间
package com.home.phl;
import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.utils.AddrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Xmemcached(基于java nio)
* @author piaohailin
*
*/
public class Test {
private static Logger logger = LoggerFactory.getLogger(Test.class);
public static void main(String[] args) throws Exception {
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("10.10.66.83:11211"));
MemcachedClient memcachedClient = builder.build();
Object o = memcachedClient.set("key",0,123);
memcachedClient.get("1");
logger.info("start");
for (int i = 0; i < 10000; i++) {
memcachedClient.get("key");
}
logger.info("end");
memcachedClient.shutdown();
}
}
启动
java -cp my.jar:lib/* com.home.phl.Test
输出
2014-01-12 01:26:31:913[WARN]: XMemcachedClient use Text protocol
2014-01-12 01:26:31:949[INFO]: Creating 32 reactors...
2014-01-12 01:26:31:993[WARN]: The Controller started at localhost/127.0.0.1:0 ...
2014-01-12 01:26:32:019[WARN]: Add a session: 10.10.66.83:11211
2014-01-12 01:26:32:029[INFO]: start
2014-01-12 01:26:34:433[INFO]: end
2014-01-12 01:26:34:437[INFO]: Controller has been stopped.
2014-01-12 01:26:34:437[WARN]: Remove a session: 10.10.66.83:11211
硬件设备缓存访问速度
摘自网络,仅供参考
结论
经过多次试验,同网段的服务器间访问,平均1次请求在0.2毫秒左右,性能优越。