2 wq8987 wq8987 于 2015.06.03 15:51 提问

jedit2.7.1对redis3.0性能简单测试

针对redis3.0作了一个简单的测试,用例如下:
1、单机单连接测试1000条写
2、单机利用连接池测试1000条写
3、3主3从单连接测试1000条写
4、3主3从连接池测试1000条写

1-3的耗时都在6秒左右徘徊,但是4所消耗的时间却有2倍,不知道什么原因,忘高手指点

图片说明

 package com.mdf.redis;

import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

import org.junit.Test;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Protocol;

public class TestRedisCluster extends TestCase {

    @Test
    public void testSingle() {
        Jedis jedis = new Jedis("182.92.157.199");
        jedis.auth("mdf_master");
        for (int i = 0; i < 1000; i++) {
            jedis.set("testSingle" + i, String.valueOf(i));
        }
        jedis.close();
    }

    @Test
    public void testSinglePool() {
        JedisPoolConfig redisPoolConf = new JedisPoolConfig();
        redisPoolConf.setMaxTotal(1024);
        redisPoolConf.setMaxIdle(200);
        redisPoolConf.setMaxWaitMillis(1000);
        redisPoolConf.setTestOnBorrow(true);
        JedisPool pool = new JedisPool(redisPoolConf, "182.92.157.199", 6379,Protocol.DEFAULT_DATABASE,"mdf_master");
        Jedis jedis = pool.getResource();
        for (int i = 0; i < 1000; i++) {
            jedis.set("testSinglePool" + i, String.valueOf(i));
        }
        pool.returnResourceObject(jedis);
        pool.close();
    }

    @Test
    public void testCluster() {
        Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        jedisClusterNodes.add(new HostAndPort("182.92.157.199", 7000));
        JedisCluster jc = new JedisCluster(jedisClusterNodes);
        for (int i = 0; i < 1000; i++) {
            jc.set("testCluster" + i, String.valueOf(i));
        }
        jc.close();
    }

    @Test
    public void testPoolCluster() {
        JedisPoolConfig redisPoolConf = new JedisPoolConfig();
        redisPoolConf.setMaxTotal(1024);
        redisPoolConf.setMaxIdle(200);
        redisPoolConf.setMaxWaitMillis(1000);
        redisPoolConf.setTestOnBorrow(true);
        Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
        jedisClusterNodes.add(new HostAndPort("182.92.157.199", 7000));
        JedisCluster jc = new JedisCluster(jedisClusterNodes, redisPoolConf);
        for (int i = 0; i < 1000; i++) {
            jc.set("testPoolCluster" + i, String.valueOf(i));
        }
        jc.close();
    }
}

2个回答

KUAILEIT
KUAILEIT   2015.12.09 14:32

我的更糟,我用的是公司服务器,考虑是不是网络延迟的问题图片说明

KUAILEIT
KUAILEIT   2015.12.09 14:52

用本机的虚拟机,效果就不一样了图片说明

Csdn user default icon
上传中...
上传图片
插入图片