-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add set_consistent_hashed_upstream #29
Add set_consistent_hashed_upstream #29
Conversation
@charliechang Thanks for sharing. @doujiang24 Will you have a quick look at this PR please? Thanks! |
for (i = 0; i < hashConf->nodeLen; i++) { | ||
hashConf->hashNodes[i].name = ul->elts[i]; | ||
hashConf->hashNodes[i].hash = ngx_hash_key_lc(hashConf->hashNodes[i].name->data, | ||
hashConf->hashNodes[i].name->len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One real node should have a number of virtual nodes, usually the number is 160, like nginx chash does: https://github.com/nginx/nginx/blob/master/src/http/modules/ngx_http_upstream_hash_module.c#L299
Otherwise, the consistent hash will have uneven distribution.
@charliechang Thanks for sharing. Yes, I think it's better to be done in Lua by lua-resty-chash. The way does in this PR can be work too, but it can be bad performance. May be we can give up this PR? Or may be my wrong? Thoughts? |
@charliechang Sorry, I mean bad performance is not so good, but in some simple case it's good enough. |
@doujiang24 |
@doujiang24 |
@charliechang Sorry, I make a stupid mistake here, the performance should not be a problem, please forgive me. Let's continue discuss. |
switch (type) { | ||
case ngx_http_set_misc_distribution_modula: | ||
return (uint32_t) hash % (uint32_t) ul->nelts; | ||
case ngx_http_set_misc_distribution_modula: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case
should left align with switch
@doujiang24 |
@@ -1,27 +1,71 @@ | |||
#ifndef DDEBUG | |||
#define DDEBUG 0 | |||
#endif | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary blank line here.
@charliechang |
@doujiang24 |
ngx_http_set_hashed_upstream_consistent_hash_node *nodes, uint32_t node_len, | ||
uint32_t target) | ||
{ | ||
uint32_t m = 0, n = node_len, l; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: nginx coding style requires each C function local variable to be defined in separate lines.
@charliechang There are so many coding style issues. Please check the existing code for the right style. Thank you for your contribution! |
|
||
if (hash_conf->hash_nodes == NULL) { | ||
return NGX_CONF_ERROR; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agentzh Could you point out where are the indent problems around here? Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charliechang Sorry, my mistake. I thought the long line breaks were indentation problems.
@agentzh I fixed the coding style issues accordingly. Please check it again. Thanks! |
@agentzh |
I this this would be a good addition. Any comments on why it stalled? Better implemented elsewhere? |
@jbergstroem Yeah, now that we have https://github.com/agentzh/lua-resty-balancer/ It's way more flexible and powerful. |
Of course. Thanks for the pointer. So much to learn! [suggesting we close this then] |
Hi
I added the support of consistent hash by reuse the directive set_hashed_upstream. I am not sure if there is any alternative for this. (Maybe can be done by Lua?)