forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TCP listener connection rebalancing (envoyproxy#8422)
This commit introduces optional connection rebalancing for TCP listeners, targeted as cases where there are a small number of long lived connections such as service mesh HTTP2/gRPC egress. Part of this change involved tracking connection counts at the per-listener level, which made it clear that we have quite a bit of tech debt in some of our interfaces in this area. I did various cleanups in service of this change which leave the connection handler / accept path in a cleaner state. Fixes envoyproxy#4602 Signed-off-by: Matt Klein <[email protected]>
- Loading branch information
1 parent
cc057ce
commit 587e079
Showing
52 changed files
with
874 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
|
||
#include "envoy/network/listen_socket.h" | ||
|
||
namespace Envoy { | ||
namespace Network { | ||
|
||
/** | ||
* A connection handler that is balanced. Typically implemented by individual listeners depending | ||
* on their balancing configuration. | ||
*/ | ||
class BalancedConnectionHandler { | ||
public: | ||
virtual ~BalancedConnectionHandler() = default; | ||
|
||
/** | ||
* @return the number of active connections within the handler. | ||
*/ | ||
virtual uint64_t numConnections() const PURE; | ||
|
||
/** | ||
* Increment the number of connections within the handler. This must be called by a connection | ||
* balancer implementation prior to a connection being picked via pickTargetHandler(). This makes | ||
* sure that connection counts are accurate during connection transfer (i.e., that the target | ||
* balancer accounts for the incoming connection). This is done by the balancer vs. the | ||
* connection handler to account for different locking needs inside the balancer. | ||
*/ | ||
virtual void incNumConnections() PURE; | ||
|
||
/** | ||
* Post a connected socket to this connection handler. This is used for cross-thread connection | ||
* transfer during the balancing process. | ||
*/ | ||
virtual void post(Network::ConnectionSocketPtr&& socket) PURE; | ||
}; | ||
|
||
/** | ||
* An implementation of a connection balancer. This abstracts the underlying policy (e.g., exact, | ||
* fuzzy, etc.). | ||
*/ | ||
class ConnectionBalancer { | ||
public: | ||
virtual ~ConnectionBalancer() = default; | ||
|
||
/** | ||
* Register a new handler with the balancer that is available for balancing. | ||
*/ | ||
virtual void registerHandler(BalancedConnectionHandler& handler) PURE; | ||
|
||
/** | ||
* Unregister a handler with the balancer that is no longer available for balancing. | ||
*/ | ||
virtual void unregisterHandler(BalancedConnectionHandler& handler) PURE; | ||
|
||
/** | ||
* Pick a target handler to send a connection to. | ||
* @param current_handler supplies the currently executing connection handler. | ||
* @return current_handler if the connection should stay bound to the current handler, or a | ||
* different handler if the connection should be rebalanced. | ||
* | ||
* NOTE: It is the responsibility of the balancer to call incNumConnections() on the returned | ||
* balancer. See the comments above for more explanation. | ||
*/ | ||
virtual BalancedConnectionHandler& | ||
pickTargetHandler(BalancedConnectionHandler& current_handler) PURE; | ||
}; | ||
|
||
using ConnectionBalancerPtr = std::unique_ptr<ConnectionBalancer>; | ||
|
||
} // namespace Network | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.