-
Notifications
You must be signed in to change notification settings - Fork 840
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
Multiple load balancing strategies#1361
Conversation
Thank you for the PR. This would be a nice step to improve the proxying capability of H2O. Regarding the design, I see two issues. I would prefer it if each balancer backend was able to define it's own structure of pooled sockets, instead of being enforced to use a linked-list of pools. In case of the round-robin selector, the issue is restraining us to using an O(N) method in I believe that locks should be defined by each balancer backend (if necessary). Or to clarify, is it possible to remove |
For the first issue, pooled sockets are divided from the old For the second issue, I was actually planning to do so. But when I considered about |
And I just realized that we also need to add an approach for balancer to get extra information per request. |
Looks like this PR has been finally completed. Some new feature has been appended:
Now value of proxy.reverse.backends:
- url: https://your.treasure.net
weight: 2
- http://local.your.treasure.net
proxy.reverse.balancer: least-conn or proxy.reverse.balancer:
- type: round-robin
other-key: other value (though currently no overall configurations for round robin) Currently we only support Integration test has been updated so weighted round robin is also been tested. For least connection, there's only a common load balancer integration test though. I cannot come up with a good solution for testing least connection. |
…lized, initialize `result` to zero to suppress compiler warning, from kazuho ab86e47
…specific to the global pool
… is a violation of C99, as well as avoiding copy of h2o_vector
…s (the value is inceremented in `h2o_socketpool_connect` and decremented when the application is notified of a connection failure
…we would wonder how _weight_ is being defined (i.e, is `H2O_SOCKETPOOL_TARGET_MAX_WEIGHT` pre-subtracted value?)
lib/handler/configurator/proxy.c
Outdated
@@ -265,11 +266,131 @@ static int on_config_ssl_session_cache(h2o_configurator_command_t *cmd, h2o_conf | |||
return 0; | |||
} | |||
|
|||
static int parse_balancer(h2o_configurator_command_t *cmd, yoml_t *node, h2o_socketpool_target_t **targets, size_t target_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.
Do we need to define this as a separate function now?
I believe that none of the balancers being defined take an argument (except the per-target weight). Therefore, the type of the balancer
attribute could be restricted to YOML_TYPE_SCALAR
. All we need to do is to call strcasecmp
to determine the correct balancer constructor.
lib/handler/configurator/proxy.c
Outdated
} | ||
|
||
if (strcmp(lb_type_node->data.scalar, "round-robin") == 0) { | ||
self->vars->conf.balancer = h2o_balancer_create_rr(); |
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.
Relating to my previous comment, I believe that the selected balancer cannot be stored as a value of the context considering the fact that it is an argument to proxy.reverse.url
, instead of being a separate configuration directive.
Consider the case where multiple mappings are made, in which only the first one has a balancer
attribute.
paths:
'/foo':
proxy.reverse.url:
backends: ...
balancer: least-conn
'/foo':
proxy.reverse.url:
backends: ...
The mapping for /foo
will incorrectly use an instance of a least-conn balancer (shouldn't it be round-robin?). That single instance will be shared with the two proxy definitions (i.e. one for /abc
and the other for /foo
). I believe that it is also a bug.
Doing my final review, I have gathered some cosmetic changes that I would like to be made in https://github.com/h2o/h2o/tree/kazuho/pr/1361. Could you please take a look at them? I believe that the only change to code is dd88f55; others are style adjustments and comments. |
Thank you! Those changes look good to me. I'll merge that branch and fix the issues mentioned. |
Configurator is fixed & added integration test for testing multiple balancers. |
Multiple load balancing strategies
Thank you for your efforts on the PR. Merged to master. |
In this PR, several optimizations are done for load balancing:
t/50reverse-proxy-round-robin.t
has been modified to prove it.h2o_socketpool_target_status_t
for recording requests on the fly & returned socket for the specific target. Addedh2o_socketpool_target_status_vector_t
as an argument for load balancing selector function so balancer can get status of each target.void *data_for_balancer
inh2o_socketpool_target_t
so proxy handler can add more information for load balancing each target.lib/common/socketpool.c
.h2o_socketpool_init_by_targets()
so proxy handler can designate the balancer when initializing socketpool now.