Implement Hash-Based Routing#519
Conversation
7c44bfe to
2c23efd
Compare
2c23efd to
91f5968
Compare
src/code.cloudfoundry.org/gorouter/proxy/round_tripper/proxy_round_tripper.go
Outdated
Show resolved
Hide resolved
e9cbe0c to
7b456f8
Compare
9f21f6b to
513c575
Compare
peanball
left a comment
There was a problem hiding this comment.
First set of comments. I have not looked at the implementation of maglev and the hash based instance determination.
I've focussed on the integration with the existing Gorouter code, route lookup, LB algo handling, etc.
| } | ||
|
|
||
| func (p *EndpointPool) Endpoints(logger *slog.Logger, initial string, mustBeSticky bool, azPreference string, az string) EndpointIterator { | ||
| func (p *EndpointPool) Endpoints(logger *slog.Logger, initial string, mustBeSticky bool, azPreference string, az string, globalLB string, request *http.Request) EndpointIterator { |
There was a problem hiding this comment.
you're passing in the full request to then dynamically fetch the hash based header. Why not pass an optional reference to *HashRoutingProperties? Parsing then can be done at the call site where you have the request anyway.
| logger.Debug("endpoint-iterator-with-round-robin-lb-algo") | ||
| return NewRoundRobin(logger, p, initial, mustBeSticky, azPreference == config.AZ_PREF_LOCAL, az) | ||
| } | ||
| return NewRoundRobin(logger, p, initial, mustBeSticky, azPreference == config.AZ_PREF_LOCAL, az) |
There was a problem hiding this comment.
you could also move this to the default: to make it clear in the switch. There is also no debug log for this branch.
| if e != nil { | ||
| e.RLock() | ||
| defer e.RUnlock() | ||
| return e.endpoint |
There was a problem hiding this comment.
e might not be valid anymore, as it is retrieved without lock. You then acquire a lock and should re-fetch the value to be sure that it's still there.
This commit provides the basic implementation for hash-based routing. It does not consider the balance factor yet. Co-authored-by: Clemens Hoffmann <clemens.hoffmann@sap.com> Co-authored-by: Tamara Boehm <tamara.boehm@sap.com> Co-authored-by: Soha Alboghdady <soha.alboghdady@sap.com>
5030bbc to
560f935
Compare
peanball
left a comment
There was a problem hiding this comment.
Some more comments, now on the hash_based.go
| balanceFactor := h.pool.HashRoutingProperties.BalanceFactor | ||
|
|
||
| if isEndpointOverloaded { | ||
| h.logger.Debug("hash-based-routing-endpoint-overloaded", slog.String("host", h.pool.host), slog.String("endpoint-id", endpoint.PrivateInstanceId), slog.Int64("endpoint-connections", currentInFlightRequestCount)) |
There was a problem hiding this comment.
as debug log is usually not on, for performance's sake it's better to guard it by checking if debug level is enabled at all in the logger.
something like
if !h.logger.Enabled(context.Background(), slog.LevelDebug) {
h.logger.Debug(...)
}| return nil | ||
| } | ||
|
|
||
| if !h.mustBeSticky { |
There was a problem hiding this comment.
this set of conditions could be refactored to be more readable.
The code is also almost 1:1 from leastconnection.go (Next()), maybe we can consolidate into one piece of code?
|
LGTM. Once we have the performance tests, we should move to community review. |
|
Good news - we evaluated the performance of gorouter with hash-based routing support. Our test setup constists of scaled out HAProxy (as a load balancer in front of gorouter), scaled out Diego Cells and a very simple and performant application with 30 instances. This allows us to performance test gorouter via external requests, where gorouter is the bottleneck. We compared the performance of the latest stable routing-release, and the same release including changes from this Pull-Request. Using
We also explored that requests are routed to next instances as expected, when the max. connection limit of one app instance was reached. The hash_balance factor is effective and allows distribution of requests to next instances before overloading it. Please feel free to reach out for details on the results! |
Changes were addressed. As this is still subject to change, I cannot give "final" approval yet.
21cc8b7 to
b414a38
Compare
|
During performance tests, we figured out that the Gorouter memory consumption is higher than expected if we keep the permutation table (table which is used to fill the final maglev lookup table) in memory. We want to investigate this finding further and optimize it. |
Summary
This Pull-Request implements #505.
Backward Compatibility
Breaking Change? Yes/No