Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用wiki页面example-1, 直接core #23

Closed
yl365 opened this issue Nov 16, 2016 · 11 comments
Closed

使用wiki页面example-1, 直接core #23

yl365 opened this issue Nov 16, 2016 · 11 comments

Comments

@yl365
Copy link

yl365 commented Nov 16, 2016

#include <stdio.h>
#include <hircluster.h>
int main()
{
    char *key="key-a";
    char *field="field-1";
    char *key1="key1";
    char *value1="value-1";
    char *key2="key1";
    char *value2="value-1";
    redisClusterContext *cc = redisClusterConnect("127.0.0.1:7000,127.0.0.1:7001,127.0.0.1:7004",
        HIRCLUSTER_FLAG_NULL);
    if(cc == NULL || cc->err)
    {
        printf("connect error : %s\n", cc == NULL ? "NULL" : cc->errstr);
        return -1;
    }

    redisReply *reply = redisClusterCommand(cc, "hmget %s %s", key, field);
    if(reply == NULL)
    {
        printf("reply is null[%s]\n", cc->errstr);
        redisClusterFree(cc);
        return -1;
    }

    printf("reply->type:%d", reply->type);

    freeReplyObject(reply);

    reply = redisClusterCommand(cc, "mset %s %s %s %s", key1, value1, key2, value2);
    if(reply == NULL)
    {
        printf("reply is null[%s]\n", cc->errstr);
        redisClusterFree(cc);
        return -1;
    }

    printf("reply->str:%s", reply->str);

    freeReplyObject(reply);
    redisClusterFree(cc);
    return 0;
}

gcc example3.c -o a3 -lhiredis_vip -L/usr/local/lib -I/usr/local/include/hiredis-vip -g -ggdb

$ ./a3 
*** glibc detected *** ./a3: double free or corruption (fasttop): 0x00000000054d5040 ***
段错误 (core dumped)
(gdb) bt
#0  0x0000003a4ca6f34e in malloc_consolidate () from /lib64/libc.so.6
#1  0x0000003a4ca71a7c in _int_malloc () from /lib64/libc.so.6
#2  0x0000003a4ca73a7d in calloc () from /lib64/libc.so.6
#3  0x0000003a4c609f8b in _dl_new_object () from /lib64/ld-linux-x86-64.so.2
#4  0x0000003a4c605a9c in _dl_map_object_from_fd () from /lib64/ld-linux-x86-64.so.2
#5  0x0000003a4c607863 in _dl_map_object () from /lib64/ld-linux-x86-64.so.2
#6  0x0000003a4c610ea2 in dl_open_worker () from /lib64/ld-linux-x86-64.so.2
#7  0x0000003a4c60d136 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#8  0x0000003a4c6108bc in _dl_open () from /lib64/ld-linux-x86-64.so.2
#9  0x0000003a4cb09fc0 in do_dlopen () from /lib64/libc.so.6
#10 0x0000003a4c60d136 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#11 0x0000003a4cb0a127 in __libc_dlopen_mode () from /lib64/libc.so.6
#12 0x0000003a4cae734f in backtrace () from /lib64/libc.so.6
#13 0x0000003a4ca6995f in __libc_message () from /lib64/libc.so.6
#14 0x0000003a4ca714af in _int_free () from /lib64/libc.so.6
#15 0x0000003a4ca757ab in free () from /lib64/libc.so.6
#16 0x00002b5dceb0dbf3 in command_destroy (command=0x54d5d30) at command.c:1678
#17 0x00002b5dceb11b27 in listDelNode (list=0x54d6090, node=0x54d51e0) at adlist.c:169
#18 0x00002b5dceb13719 in command_pre_fragment (cc=0x2b5dced20010, command=0x54d5110, commands=0x54d6090)
    at hircluster.c:3191
#19 command_format_by_slot (cc=0x2b5dced20010, command=0x54d5110, commands=0x54d6090) at hircluster.c:3376
#20 0x00002b5dceb183c3 in redisClusterFormattedCommand (cc=0x2b5dced20010, 
    cmd=0x54d6180 "*5\r\n$4\r\nmset\r\n$4\r\nkey1\r\n$7\r\nvalue-1\r\n$4\r\nkey1\r\n$7\r\nvalue-1\r\n", 
    len=<value optimized out>) at hircluster.c:3432
#21 0x00002b5dceb192a2 in redisClustervCommand (cc=0x2b5dced20010, format=<value optimized out>, 
    ap=<value optimized out>) at hircluster.c:3535
#22 0x00002b5dceb19388 in redisClusterCommand (cc=0x3a4cd549e0, format=0x496 <Address 0x496 out of bounds>)
    at hircluster.c:3547
#23 0x000000000040081c in main () at example3.c:31

请问我这是什么原因? 万分感谢

@yl365
Copy link
Author

yl365 commented Nov 16, 2016

$ gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55)
Copyright (C) 2006 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。

lsb_release -a
LSB Version:    :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 5.8 (Final)
Release:    5.8
Codename:   Final

@deep011
Copy link
Contributor

deep011 commented Nov 16, 2016

问题已修复,你下载最新代码试试。

@deep011 deep011 closed this as completed Nov 16, 2016
@yl365
Copy link
Author

yl365 commented Nov 16, 2016

测试已经修复. 感谢!

请问该项目是否已经用在生产项目中?

请问有没有相关说明文档?

比如我想知道:

  • 是不是主写从读? 或者有没有相关配置可以实现? 或者有没有这个计划?
  • 如果集群中的主从切换后, 是否能自动重连新的主继续工作? 这个时间大约是多久? 对于集群的状态检测, 是采用定时检测还是订阅通知方式?

万分感谢!

@deep011
Copy link
Contributor

deep011 commented Nov 16, 2016

生产中在用
文档参见readme

  • 读写分离,需要建立连接的时候使用flag:HIRCLUSTER_FLAG_ADD_SLAVE,并且要用户做些额外工作,目前还hiredis-vip还不能主动进行读写分离
  • 主从切换后,hiredis-vip会修复路由继续正常工作,集群路由表发生变更,hiredis-vip都可以自动修复的。修复时间取决于集群node-timeout参数,如果是manual failover,会即时修复。

@xielm12
Copy link

xielm12 commented Nov 21, 2016

我仔细比较了一下MGet多个Keys和多次Get这些Keys,并没有体现出多少优越的性能。而采用pipeline可以比他们快一倍!

@deep011
Copy link
Contributor

deep011 commented Nov 21, 2016

@xielm12 你mget一次多少个key?你的集群是几个master?

mget后跟100万个key,hiredis-vip需要4秒,而100万次get,4秒是肯定做不到的。

@xielm12
Copy link

xielm12 commented Nov 21, 2016

我的集群是3主3从。 我是结合我的业务测试的。同样的数据,就只把MGet的地方换成 Get,跑完我的业务数据,需要32分钟。 而采用pipeline 只要17分钟。只是pipeline偶尔会出现Server closed the connection这个问题,导致出现假死。

@deep011
Copy link
Contributor

deep011 commented Nov 21, 2016

你业务里MGet后面大概跟什么数量级的key?几个?十几个?几百个?
另外,你的redis Cluster前面有用proxy吗?

@xielm12
Copy link

xielm12 commented Nov 21, 2016

平均每次MGet 200多个key。 我是直接连接到redis Cluster上,没用使用proxy

@deep011
Copy link
Contributor

deep011 commented Nov 21, 2016

hiredis-vip的mget是按slot拆分的,Cluster是有16384个slot,可能你这200个key真好分散在200个slot上,那效率确实跟get相差无几。后续我会再优化下,属于同一个master的mget命令,批量发送,应该会有很大效率提升。

@sherwinl1u
Copy link

生产中在用
文档参见readme

  • 读写分离,需要建立连接的时候使用flag:HIRCLUSTER_FLAG_ADD_SLAVE,并且要用户做些额外工作,目前还hiredis-vip还不能主动进行读写分离
  • 主从切换后,hiredis-vip会修复路由继续正常工作,集群路由表发生变更,hiredis-vip都可以自动修复的。修复时间取决于集群node-timeout参数,如果是manual failover,会即时修复。

请问要做哪些额外的工作才能进行读写分离呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants