windows下redis和memcached的性能对比测试

在windows下测试了redis和memcached的性能,如下:

jedis get 20000次的执行时间:1265毫秒

jedis set 20000次的执行时间:1313毫秒

jedis 同时启动60个线程的执行时间:21609毫秒

xmemcached get执行20000次的时间:3219毫秒

xmemcached set 20000次的执行时间:3000毫秒

xmemcached 同时启动60个线程的执行时间:75562毫秒

可以看出redis的性能要好于memcached!


redis代码:

public class Demo {

	public static void main(String[] args) throws Exception {
		Demo demo = new Demo();
		demo.test();
	}
	
	public void test() throws Exception {
		Jedis jedis = new Jedis("localhost");
		jedis.set("key", "mykey");
		
		long begin = System.currentTimeMillis();
		for(int i=0; i<20000; i++)
			jedis.get("key");
		long end = System.currentTimeMillis();
		System.out.println("jedis get20000次的执行时间:" + (end - begin) + "毫秒");
		
		begin = System.currentTimeMillis();
		for(int i=0; i<20000; i++)
			jedis.set(String.valueOf(i), String.valueOf(i));
		end = System.currentTimeMillis();
		System.out.println("jedis set 20000次的执行时间:" + (end - begin) + "毫秒");
		
		begin = System.currentTimeMillis();
		Thread t[] = new Thread[60];
		for(int j=0; j<t.length; j++) {
			t[j] = new TestThread();
			t[j].start();
		}
		
		for(int j=0; j<t.length; j++) {
			t[j].join();
		}
		end = System.currentTimeMillis();
		System.out.println("jedis 启动"+ t.length +"个线程的执行时间:" + (end - begin) + "毫秒");
	}

	class TestThread extends Thread {

		@Override
		public void run() {
			Jedis jedis = new Jedis("localhost");
			for(int i=0; i<20000; i++)
				jedis.get(String.valueOf(i));
			jedis.disconnect();
		}
		
	}
}

测试redis的代码时,发现同时启动的线程只能到达63,超过的线程都会失败。

排查很久,发现配置文件中有一句话:it's up to the number of file descriptors the Redis process is able to open.

估计在windows xp下只能到达64,那么还有一个呢?无法得知,查了好久也没有找到和linux下文件描述符想匹配的东西。

 

xmemcache代码:

public class Demo {

	public static void main(String[] args) throws Exception {
		Demo demo = new Demo();
		demo.test();
	}
	
	public void test() throws Exception  {
		MemcachedClient mc = new XMemcachedClient("localhost", 11211);
		mc.set("key", 2000, "mykey");
		
		long begin = System.currentTimeMillis();
		for(int i=0; i<20000; i++)
			mc.get("key", 1000);
		long end = System.currentTimeMillis();
		
		System.out.println("memcached get执行20000次的时间:" + (end - begin) + "毫秒");
		
		begin = System.currentTimeMillis();
		for(int i=0; i<20000; i++)
			mc.set(String.valueOf(i), 2000 ,String.valueOf(i));
		end = System.currentTimeMillis();
		System.out.println("memcached set 20000次的执行时间:" + (end - begin) + "毫秒");		
		
		mc.shutdown();	
		
		begin = System.currentTimeMillis();
		Thread t[] = new Thread[60];
		for(int j=0; j<t.length; j++) {
			t[j] = new TestThread();
			t[j].start();
		}
		
		for(int j=0; j<t.length; j++) {
			t[j].join();
		}
		end = System.currentTimeMillis();
		System.out.println("memcached 启动"+ t.length +"个线程的执行时间:" + (end - begin) + "毫秒");		
	}

	class TestThread extends Thread {

		@Override
		public void run() {
			try {
				MemcachedClient mc = new XMemcachedClient("localhost", 11211);
				for(int i=0; i<20000; i++)
					mc.get(String.valueOf(i), 1000);
				mc.shutdown();
			}
			catch (Exception e) {
				
			}
		}
		
	}
}

转载于:https://my.oschina.net/netconst/blog/14838

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值