proxygen
|
#include <ConnectionManager.h>
Classes | |
class | Callback |
class | DrainHelper |
Public Types | |
typedef std::unique_ptr< ConnectionManager, Destructor > | UniquePtr |
typedef folly::CountedIntrusiveList< ManagedConnection,&ManagedConnection::listHook_ >::iterator | ConnectionIterator |
Public Member Functions | |
ConnectionManager (folly::EventBase *eventBase, std::chrono::milliseconds timeout, Callback *callback=nullptr) | |
void | addConnection (ManagedConnection *connection, bool timeout=false) |
void | scheduleTimeout (ManagedConnection *const connection, std::chrono::milliseconds timeout) |
void | scheduleTimeout (folly::HHWheelTimer::Callback *callback, std::chrono::milliseconds timeout) |
void | removeConnection (ManagedConnection *connection) |
void | initiateGracefulShutdown (std::chrono::milliseconds idleGrace) |
void | drainConnections (double pct, std::chrono::milliseconds idleGrace) |
void | dropAllConnections () |
void | dropConnections (double pct) |
size_t | getNumConnections () const |
template<typename F > | |
void | iterateConns (F func) |
std::chrono::milliseconds | getDefaultTimeout () const |
void | setLoweredIdleTimeout (std::chrono::milliseconds timeout) |
size_t | dropIdleConnections (size_t num) |
void | onActivated (ManagedConnection &conn) override |
void | onDeactivated (ManagedConnection &conn) override |
Public Member Functions inherited from folly::DelayedDestruction | |
virtual void | destroy () |
bool | getDestroyPending () const |
Public Member Functions inherited from folly::DelayedDestructionBase | |
virtual | ~DelayedDestructionBase ()=default |
Static Public Member Functions | |
template<typename... Args> | |
static UniquePtr | makeUnique (Args &&...args) |
Private Types | |
enum | ShutdownState : uint8_t { ShutdownState::NONE = 0, ShutdownState::NOTIFY_PENDING_SHUTDOWN = 1, ShutdownState::NOTIFY_PENDING_SHUTDOWN_COMPLETE = 2, ShutdownState::CLOSE_WHEN_IDLE = 3, ShutdownState::CLOSE_WHEN_IDLE_COMPLETE = 4 } |
Private Member Functions | |
~ConnectionManager () override=default | |
ConnectionManager (const ConnectionManager &)=delete | |
ConnectionManager & | operator= (ConnectionManager &)=delete |
void | drainAllConnections () |
void | stopDrainingForShutdown () |
void | idleGracefulTimeoutExpired () |
Private Member Functions inherited from wangle::ManagedConnection::Callback | |
virtual | ~Callback ()=default |
Private Attributes | |
folly::CountedIntrusiveList< ManagedConnection,&ManagedConnection::listHook_ > | conns_ |
Callback * | callback_ |
folly::EventBase * | eventBase_ |
ConnectionIterator | drainIterator_ |
ConnectionIterator | idleIterator_ |
DrainHelper | drainHelper_ |
bool | notifyPendingShutdown_ {true} |
std::chrono::milliseconds | timeout_ |
std::chrono::milliseconds | idleConnEarlyDropThreshold_ |
Additional Inherited Members | |
Protected Member Functions inherited from folly::DelayedDestruction | |
~DelayedDestruction () override=default | |
DelayedDestruction () | |
Protected Member Functions inherited from folly::DelayedDestructionBase | |
DelayedDestructionBase () | |
uint32_t | getDestructorGuardCount () const |
A ConnectionManager keeps track of ManagedConnections.
Definition at line 34 of file ConnectionManager.h.
typedef folly::CountedIntrusiveList< ManagedConnection, &ManagedConnection::listHook_>::iterator wangle::ConnectionManager::ConnectionIterator |
Definition at line 66 of file ConnectionManager.h.
typedef std::unique_ptr<ConnectionManager, Destructor> wangle::ConnectionManager::UniquePtr |
Definition at line 63 of file ConnectionManager.h.
|
strongprivate |
Enumerator | |
---|---|
NONE | |
NOTIFY_PENDING_SHUTDOWN | |
NOTIFY_PENDING_SHUTDOWN_COMPLETE | |
CLOSE_WHEN_IDLE | |
CLOSE_WHEN_IDLE_COMPLETE |
Definition at line 174 of file ConnectionManager.h.
wangle::ConnectionManager::ConnectionManager | ( | folly::EventBase * | eventBase, |
std::chrono::milliseconds | timeout, | ||
Callback * | callback = nullptr |
||
) |
Constructor not to be used by itself.
Referenced by makeUnique().
|
overrideprivatedefault |
|
privatedelete |
void wangle::ConnectionManager::addConnection | ( | ManagedConnection * | connection, |
bool | timeout = false |
||
) |
Add a connection to the set of connections managed by this ConnectionManager.
connection | The connection to add. |
timeout | Whether to immediately register this connection for an idle timeout callback. |
Definition at line 40 of file ConnectionManager.cpp.
References callback_, wangle::ManagedConnection::fireCloseWhenIdle(), wangle::ManagedConnection::fireNotifyPendingShutdown(), wangle::ManagedConnection::getConnectionManager(), wangle::ManagedConnection::listHook_, removeConnection(), and wangle::ManagedConnection::setConnectionManager().
Referenced by makeUnique().
|
private |
Destroy all connections managed by this ConnectionManager that are currently idle, as determined by a call to each ManagedConnection's isBusy() method.
void wangle::ConnectionManager::drainConnections | ( | double | pct, |
std::chrono::milliseconds | idleGrace | ||
) |
Gracefully shutdown certain percentage of persistent client connections and leave the rest intact.
Definition at line 141 of file ConnectionManager.cpp.
References wangle::NONE.
Referenced by makeUnique(), wangle::ConnectionManager::DrainHelper::runLoopCallback(), and wangle::ConnectionManager::DrainHelper::timeoutExpired().
void wangle::ConnectionManager::dropAllConnections | ( | ) |
Destroy all connections Managed by this ConnectionManager, even the ones that are busy.
Definition at line 255 of file ConnectionManager.cpp.
References callback_, folly::HHWheelTimer::Callback::cancelTimeout(), wangle::ManagedConnection::dropConnection(), wangle::ManagedConnection::dumpConnectionState(), g(), i, and wangle::ManagedConnection::setConnectionManager().
Referenced by makeUnique().
void wangle::ConnectionManager::dropConnections | ( | double | pct | ) |
Force-stop "pct" (0.0 to 1.0) of remaining client connections, regardless of whether they are busy or idle.
Definition at line 289 of file ConnectionManager.cpp.
References wangle::ManagedConnection::dropConnection(), g(), and i.
Referenced by makeUnique().
size_t wangle::ConnectionManager::dropIdleConnections | ( | size_t | num | ) |
try to drop num idle connections to release system resources. Return the actual number of dropped idle connections
Definition at line 333 of file ConnectionManager.cpp.
References count, and wangle::ManagedConnection::dropConnection().
Referenced by setLoweredIdleTimeout().
|
inline |
Definition at line 149 of file ConnectionManager.h.
References timeout_.
Referenced by wangle::ManagedConnection::resetTimeout().
|
inline |
Definition at line 138 of file ConnectionManager.h.
References conns_.
|
private |
Referenced by wangle::ConnectionManager::DrainHelper::timeoutExpired().
void wangle::ConnectionManager::initiateGracefulShutdown | ( | std::chrono::milliseconds | idleGrace | ) |
Definition at line 131 of file ConnectionManager.cpp.
References wangle::NONE.
Referenced by makeUnique().
|
inline |
Definition at line 141 of file ConnectionManager.h.
References conns_.
|
inlinestatic |
Returns a new instance of ConnectionManager wrapped in a unique_ptr
Definition at line 71 of file ConnectionManager.h.
References addConnection(), ConnectionManager(), drainConnections(), dropAllConnections(), dropConnections(), initiateGracefulShutdown(), removeConnection(), scheduleTimeout(), and folly::detail::timeout.
Referenced by wangle::Acceptor::initDownstreamConnectionManager(), and TEST_F().
|
overridevirtual |
ManagedConnection::Callbacks
Implements wangle::ManagedConnection::Callback.
Definition at line 305 of file ConnectionManager.cpp.
Referenced by proxygen::HTTPSession::createTransaction(), and setLoweredIdleTimeout().
|
overridevirtual |
Implements wangle::ManagedConnection::Callback.
Definition at line 315 of file ConnectionManager.cpp.
Referenced by proxygen::HTTPSession::detach(), and setLoweredIdleTimeout().
|
privatedelete |
void wangle::ConnectionManager::removeConnection | ( | ManagedConnection * | connection | ) |
Remove a connection from this ConnectionManager and, if applicable, cancel the pending timeout callback that the ConnectionManager has scheduled for the connection.
Definition at line 105 of file ConnectionManager.cpp.
References callback_, folly::HHWheelTimer::Callback::cancelTimeout(), wangle::ManagedConnection::getConnectionManager(), wangle::SimpleConnectionCounter::getNumConnections(), and wangle::ManagedConnection::setConnectionManager().
Referenced by addConnection(), makeUnique(), and wangle::ManagedConnection::~ManagedConnection().
void wangle::ConnectionManager::scheduleTimeout | ( | ManagedConnection *const | connection, |
std::chrono::milliseconds | timeout | ||
) |
Schedule a timeout callback for a connection.
Definition at line 91 of file ConnectionManager.cpp.
Referenced by makeUnique(), wangle::ManagedConnection::resetTimeoutTo(), wangle::ManagedConnection::scheduleTimeout(), and wangle::AcceptorHandshakeManager::startHandshakeTimeout().
void wangle::ConnectionManager::scheduleTimeout | ( | folly::HHWheelTimer::Callback * | callback, |
std::chrono::milliseconds | timeout | ||
) |
Definition at line 98 of file ConnectionManager.cpp.
|
inline |
Definition at line 153 of file ConnectionManager.h.
References dropIdleConnections(), idleConnEarlyDropThreshold_, onActivated(), onDeactivated(), and timeout_.
|
private |
Signal the drain helper that we are about to start dropping connections.
Definition at line 249 of file ConnectionManager.cpp.
|
private |
Optional callback to notify of state changes
Definition at line 272 of file ConnectionManager.h.
|
private |
All the managed connections. idleIterator_ seperates them into two parts: idle and busy ones. [conns_.begin(), idleIterator_) are the busy ones, while [idleIterator_, conns_.end()) are the idle one. Moreover, the idle ones are organized in the decreasing idle time order.
Definition at line 269 of file ConnectionManager.h.
Referenced by getNumConnections(), and iterateConns().
|
private |
Definition at line 280 of file ConnectionManager.h.
|
private |
Iterator to the next connection to shed; used by drainAllConnections()
Definition at line 278 of file ConnectionManager.h.
|
private |
Event base in which we run
Definition at line 275 of file ConnectionManager.h.
|
private |
The idle connections can be closed earlier that their idle timeout when any system resource limit is reached. This feature can be considerred as a pre load shedding stage for the system, and can be easily disabled by setting idleConnEarlyDropThreshold_ to defaultIdleTimeout_. Also, idleConnEarlyDropThreshold_ can be used to bottom the idle timeout. That is, connection manager will not early drop the idle connections whose idle time is less than idleConnEarlyDropThreshold_.
Definition at line 298 of file ConnectionManager.h.
Referenced by setLoweredIdleTimeout().
|
private |
Definition at line 279 of file ConnectionManager.h.
|
private |
Definition at line 281 of file ConnectionManager.h.
|
private |
the default idle timeout for downstream sessions when no system resource limit is reached
Definition at line 287 of file ConnectionManager.h.
Referenced by getDefaultTimeout(), and setLoweredIdleTimeout().