redis-benchmark测试并发性能

服务器环境

SUSE Linux Enterprise Server 10 SP3 (x86_64)
MemTotal: 2097324 kB
cpu MHz : 2400.084 Hz
disk: 10G

首先安装redis2.6.0(引入了lua脚本支持,需要安装lua库与jemalloc内存分配器等依赖)

先往数据库压入数据占满内存, key(25~30bytes) val(100 bytes)

    unsigned int j;
    redisContext *c;
    redisReply *reply;
    int size = 10000 * 1500;

    clock_t start,finish;
    double jishi;
    char key[1000];
    char val[1000];
    char times[100];

    struct timeval timeout = { 1, 500000 }; // 1.5 seconds
    c = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout);
    if (c->err) {
        printf("Connection error: %s\n", c->errstr);
        exit(1);
    }

    start = clock();
    /* Set a key */

    for(j = 0;j < size;j ++){
        randalp(key, 30 + j%5);
        sprintf(times,"%d",time(0));
        strcat(key,times);
        randstr(val, 100);
        reply = redisCommand(c,"SET %s %s", key,val);
        freeReplyObject(reply);
        if(j % 100000 == 0){
                finish = clock();
                jishi = (double)(finish-start)/CLOCKS_PER_SEC;
                printf("set %d spend %f seconds\n",j/100000,jishi);
                start = finish;
        }
    }

    return 0;
650万条数据,占用717M磁盘空间,(正好用完2G内存)
	redis-benchmark -h 10.6.2.245 -p 6379 -q -d 500

	PING_INLINE: 14858.84 requests per second
	PING_BULK: 52910.05 requests per second
	SET: 55248.62 requests per second
	GET: 54347.82 requests per second
	INCR: 56179.77 requests per second
	LPUSH: 55555.55 requests per second
	LPOP: 54054.05 requests per second
	SADD: 56179.77 requests per second
	SPOP: 56497.18 requests per second
	LPUSH (needed to benchmark LRANGE): 55865.92 requests per second
	LRANGE_100 (first 100 elements): 2304.15 requests per second
	LRANGE_300 (first 300 elements): 769.76 requests per second
	LRANGE_500 (first 450 elements): 513.43 requests per second
	LRANGE_600 (first 600 elements): 385.13 requests per second
	MSET (10 keys): 21739.13 requests per second

	redis-benchmark -h 10.6.2.245 -p 6379 -q -d 100

	PING_INLINE: 55248.62 requests per second
	PING_BULK: 54644.81 requests per second
	SET: 54347.82 requests per second
	GET: 54054.05 requests per second
	INCR: 55248.62 requests per second
	LPUSH: 54347.82 requests per second
	LPOP: 53763.44 requests per second
	SADD: 54945.05 requests per second
	SPOP: 54945.05 requests per second
	LPUSH (needed to benchmark LRANGE): 51813.47 requests per second
	LRANGE_100 (first 100 elements): 10822.51 requests per second
	LRANGE_300 (first 300 elements): 3611.41 requests per second
	LRANGE_500 (first 450 elements): 2407.90 requests per second
	LRANGE_600 (first 600 elements): 1808.32 requests per second
	MSET (10 keys): 44642.86 requests per second
A,每条测试数据500字节,lrange的性能下降得比较快
B,每条测试数据100字节,lrange也是存在瓶颈,其他指令大致一样。

其他常用指令平均性能都还不错,能达到50000左右的样子,redis-benchmark的默认并发client数目为50,可以看出来redis是一个性能非常优秀的内存数据库,但是vm机制不是很好,官方文档也说明了不建议使用。而且在系统内存被耗尽时系统极不稳定,容易崩溃,所以在redis.conf配置文件中还需要限制redis的内存使用。


你可能感兴趣的:(redis-benchmark测试并发性能)