github上的Java-Memcached-Client 已经很久没有更新了。没多少人用了吧?可惜。。。
所以得研究一下现状。
有两个出处文章,分别做了对比,结论是这个client是不能用了。
============================================================================= ===
测试源码:
- svn co http://xmemcached.googlecode.com/svn/trunk/benchmark/
测试结果:
- svn co http://xmemcached.googlecode.com/svn/trunk/benchmark/result
总结下测试结果,为还在选择和考察java memcached client的朋友提供参考:
1、Java-Memcached-Client 2.5.1这个版本果然有很大改进,性能上有非常大的提升,从测试结果来看在小于100并发下有非常明显的优势,同时耗费资源也相对较多。但是在300并 发访问下,Java-Memcached-Client会不断地报错:
- com.schooner.MemCached.SchoonerSockIOPool Sun Oct 17 11:09:05 GMT+08:00 2010 - ++++ failed to get SockIO obj for: 10.232.36.82:12000
- com.schooner.MemCached.SchoonerSockIOPool Sun Oct 17 11:09:05 GMT+08:00 2010 - ++++ failed to get SockIO obj for: 10.232.36.82:12000
- com.schooner.MemCached.SchoonerSockIOPool Sun Oct 17 11:09:05 GMT+08:00 2010 - ++++ failed to get SockIO obj for: 10.232.36.90:12000
- com.schooner.MemCached.SchoonerSockIOPool Sun Oct 17 11:09:05 GMT+08:00 2010 - ++++ failed to get SockIO obj for: 10.232.36.82:12000
- com.schooner.MemCached.SchoonerSockIOPool Sun Oct 17 11:09:05 GMT+08:00 2010 - ++++ failed to get SockIO obj for: 10.232.36.90:12000
- com.schooner.MemCached.SchoonerSockIOPool Sun Oct 17 11:09:05 GMT+08:00 2010 - ++++ failed to get SockIO obj for: 10.232.36.82:12000
并且无法正常地存取数据,而xmc和spy却可以正常应对这一场景。因此可以看到在300并发下,Java-Memcached-Client测试的结果直接为0,因为测试无法完成。尽管我尝试将最大连接数调整到2000,仍然是无法正常完成测试。
2、Xmemcached无论在低并发还是高并发访问的情况下,都可以保持一个比较优秀的性能表现,从xmc和spy的对比来看,xmc的优势相当大。
3、从用户选择角度来说,如果你的应用对memached的访问负载并不高,Java-Memcached-Client是一个不错的选择,但是在高峰访问的时候可能命中率会有个急剧的波动;如果你的应用访问memached的负载较高,此时我推荐你选择xmemcached;如果你需要异步的批量处理(future模式),可以选择spymemcached;如果你不知道你的应用是什么状况,我推荐你用xmemcached,可以在任何情况下获得一个比较好的性能表现。
原文地址:转Java 几个memcached 连接客户端对比 选择作者:闪出光芒
=============================================================================
几个Memcached Java Client性能对比
对比spymemcached和Memcached-Java-Client性能
在http://code.google.com/p/memcached/wiki/Clients 上主要有两个Java版本的Memcached客户端,原文如下:
spymemcached
- http://code.google.com/p/spymemcached
- An improved Java API maintained by Dustin Sallings.
- Aggressively optimised, ability to run async, supports binary protocol, etc. See site for details.
Java memcached client
- http://www.whalin.com/memcached
- A Java API is maintained by Greg Whalin from Meetup.com.
在个人电脑上写了一段程序对比两个客户端的效率(单一memcached服务器),
用100个线程,分别插入后查询1000笔数据,spymemcached耗时约8s
对spymemcached测试如下:
- import java.io.IOException;
- import net.spy.memcached.AddrUtil;
- import net.spy.memcached.MemcachedClient;
- public class TestSpymemcached extends Thread{
- /**
- * @param args
- */
- private int count;
- public static void main(String[] args) throws Exception{
- // TODO Auto-generated method stub
- System.out.println("begin:"+System.currentTimeMillis());
- for(int i=0 ; i<100;i++){
- TestJavaClient test = new TestJavaClient(i);
- test.start();
- }
- System.out.println("end:"+System.currentTimeMillis());
- }
- public TestJavaClient(int i){
- count = i;
- }
- public void run(){
- System.out.println(count+"start:"+System.currentTimeMillis());
- MemcachedClient c= MemCachedManager.getInstance();
- for(int i=0 ; i<1000;i++){
- // Store a value (async) for one hour
- c.set(count+"000"+i, 3600, "Hello World "+count+"000"+i+"!");
- // Retrieve a value (synchronously).
- Object myObject=c.get("liusong"+count);
- }
- System.out.println(count+"end:"+System.currentTimeMillis());
- }
- }
- class MemCachedManager{
- private static MemcachedClient c;
- public static synchronized MemcachedClient getInstance(){
- if(c==null){
- try {
- c=new MemcachedClient(
- AddrUtil.getAddresses("10.148.11.112:11211"));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return c;
- }
- }
Java memcached client同样用100个线程,分别插入后查询1000笔数据,耗时约36s
Java memcached client代码如下:
- public class TestJavaClient extends Thread{
- private int count;
- public static void main(String[] args) throws Exception{
- // TODO Auto-generated method stub
- System.out.println("begin:"+System.currentTimeMillis());
- for(int i=0 ; i<100;i++){
- TestDangaClient test = new TestDangaClient(i);
- test.start();
- }
- System.out.println("end:"+System.currentTimeMillis());
- }
- public TestDangaClient(int i){
- count = i;
- }
- public void run(){
- System.out.println(count+"start:"+System.currentTimeMillis());
- MemCachedManage cache = MemCachedManage.getInstance();
- for(int i=0 ; i<1000;i++){
- // Store a value (async) for one hour
- cache.add(count+"000"+i, "Hello World "+count+"000"+i+"!");
- // Retrieve a value (synchronously).
- Object myObject=cache.get("liusong"+count);
- }
- System.out.println(count+"end:"+System.currentTimeMillis());
- }
- }
- import java.util.Date;
- import com.meetup.memcached.MemcachedClient;
- import com.meetup.memcached.SockIOPool;
- public class MemCachedManage {
- private static MemcachedClient mcc = new MemcachedClient();
- private static MemCachedManage memCachedManager = new MemCachedManage();
- static {
- String[] servers = { "10.148.71.215:11211" };
- Integer[] weights = { 3 };
- SockIOPool pool = SockIOPool.getInstance();
- pool.setServers(servers);
- pool.setWeights(weights);
- pool.setInitConn(100);
- pool.setMinConn(100);
- pool.setMaxConn(250);
- pool.setMaxIdle(1000 * 60 * 60 * 6);
- pool.setMaintSleep(30);
- pool.setNagle(false);
- pool.setSocketTO(3000);
- pool.setSocketConnectTO(0);
- pool.initialize();
- mcc.setCompressEnable(true);
- mcc.setCompressThreshold(64 * 1024);
- }
- protected MemCachedManage() {
- }
- public static MemCachedManage getInstance() {
- return memCachedManager;
- }
- public boolean add(String key, Object value) {
- return mcc.add(key, value);
- }
- public boolean add(String key, Object value, Date expiry) {
- return mcc.add(key, value, expiry);
- }
- public boolean replace(String key, Object value) {
- return mcc.replace(key, value);
- }
- public boolean replace(String key, Object value, Date expiry) {
- return mcc.replace(key, value, expiry);
- }
- public Object get(String key) {
- return mcc.get(key);
- }
- public static void main(String[] args) {
- MemCachedManage cache = MemCachedManage.getInstance();
- cache.add("hello", 234);
- System.out.print("get value : " + cache.get("hello"));
- }
- }
结论,spymemcached更有效率。
=
=
=
+
=
=
=