-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
overload: create scaled timers via the dispatcher (#14679)
Refactor the existing pathway for creating scaled Timer objects away from the ThreadLocalOverloadState and into the Dispatcher interface. This allows scaled timers to be created without plumbing through a bunch of extra state. Signed-off-by: Alex Konradi <akonradi@google.com>
- Loading branch information
Showing
37 changed files
with
440 additions
and
264 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#pragma once | ||
|
||
#include <chrono> | ||
|
||
#include "common/common/interval_value.h" | ||
|
||
#include "absl/container/flat_hash_map.h" | ||
#include "absl/types/variant.h" | ||
|
||
namespace Envoy { | ||
namespace Event { | ||
|
||
/** | ||
* Describes a minimum timer value that is equal to a scale factor applied to the maximum. | ||
*/ | ||
struct ScaledMinimum { | ||
explicit constexpr ScaledMinimum(UnitFloat scale_factor) : scale_factor_(scale_factor) {} | ||
inline bool operator==(const ScaledMinimum& other) const { | ||
return other.scale_factor_.value() == scale_factor_.value(); | ||
} | ||
const UnitFloat scale_factor_; | ||
}; | ||
|
||
/** | ||
* Describes a minimum timer value that is an absolute duration. | ||
*/ | ||
struct AbsoluteMinimum { | ||
explicit constexpr AbsoluteMinimum(std::chrono::milliseconds value) : value_(value) {} | ||
inline bool operator==(const AbsoluteMinimum& other) const { return other.value_ == value_; } | ||
const std::chrono::milliseconds value_; | ||
}; | ||
|
||
/** | ||
* Class that describes how to compute a minimum timeout given a maximum timeout value. It wraps | ||
* ScaledMinimum and AbsoluteMinimum and provides a single computeMinimum() method. | ||
*/ | ||
class ScaledTimerMinimum { | ||
public: | ||
// Forward arguments to impl_'s constructor. | ||
constexpr ScaledTimerMinimum(AbsoluteMinimum arg) : impl_(arg) {} | ||
constexpr ScaledTimerMinimum(ScaledMinimum arg) : impl_(arg) {} | ||
|
||
// Computes the minimum value for a given maximum timeout. If this object was constructed with a | ||
// - ScaledMinimum value: | ||
// the return value is the scale factor applied to the provided maximum. | ||
// - AbsoluteMinimum: | ||
// the return value is that minimum, and the provided maximum is ignored. | ||
std::chrono::milliseconds computeMinimum(std::chrono::milliseconds maximum) const { | ||
struct Visitor { | ||
explicit Visitor(std::chrono::milliseconds value) : value_(value) {} | ||
std::chrono::milliseconds operator()(ScaledMinimum scale_factor) { | ||
return std::chrono::duration_cast<std::chrono::milliseconds>( | ||
scale_factor.scale_factor_.value() * value_); | ||
} | ||
std::chrono::milliseconds operator()(AbsoluteMinimum absolute_value) { | ||
return absolute_value.value_; | ||
} | ||
const std::chrono::milliseconds value_; | ||
}; | ||
return absl::visit(Visitor(maximum), impl_); | ||
} | ||
|
||
inline bool operator==(const ScaledTimerMinimum& other) const { return impl_ == other.impl_; } | ||
|
||
private: | ||
absl::variant<ScaledMinimum, AbsoluteMinimum> impl_; | ||
}; | ||
|
||
enum class ScaledTimerType { | ||
// Timers created with this type will never be scaled. This should only be used for testing. | ||
UnscaledRealTimerForTest, | ||
// The amount of time an HTTP connection to a downstream client can remain idle (no streams). This | ||
// corresponds to the HTTP_DOWNSTREAM_CONNECTION_IDLE TimerType in overload.proto. | ||
HttpDownstreamIdleConnectionTimeout, | ||
// The amount of time an HTTP stream from a downstream client can remain idle. This corresponds to | ||
// the HTTP_DOWNSTREAM_STREAM_IDLE TimerType in overload.proto. | ||
HttpDownstreamIdleStreamTimeout, | ||
}; | ||
|
||
using ScaledTimerTypeMap = absl::flat_hash_map<ScaledTimerType, ScaledTimerMinimum>; | ||
using ScaledTimerTypeMapConstSharedPtr = std::shared_ptr<const ScaledTimerTypeMap>; | ||
|
||
} // namespace Event | ||
} // namespace Envoy |
This file was deleted.
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
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
Oops, something went wrong.