userver: userver/congestion_control/controllers/linear.hpp Source File
Loading...
Searching...
No Matches
linear.hpp
1#pragma once
2
3#include <optional>
4
5#include <userver/congestion_control/controllers/linear_config.hpp>
6#include <userver/congestion_control/controllers/v2.hpp>
7#include <userver/congestion_control/limiter.hpp>
8#include <userver/dynamic_config/source.hpp>
9#include <userver/utils/periodic_task.hpp>
10#include <userver/utils/sliding_interval.hpp>
11#include <userver/yaml_config/yaml_config.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace congestion_control::v2 {
16
17class LinearController final : public Controller {
18public:
19 using StaticConfig = Controller::Config;
20
21 LinearController(
22 const std::string& name,
23 v2::Sensor& sensor,
24 Limiter& limiter,
25 Stats& stats,
26 const StaticConfig& config,
27 dynamic_config::Source config_source,
28 std::function<v2::Config(const dynamic_config::Snapshot&)> config_getter
29 );
30
31 Limit Update(const Sensor::Data& current) override;
32
33private:
34 StaticConfig config_;
35 utils::SlidingInterval<int64_t> current_load_;
36 utils::SlidingInterval<int64_t> long_timings_;
37 utils::SlidingInterval<int64_t> short_timings_;
38 std::optional<std::size_t> current_limit_;
39 std::size_t epochs_passed_{0};
40
41 dynamic_config::Source config_source_;
42 std::function<v2::Config(const dynamic_config::Snapshot&)> config_getter_;
43};
44
45LinearController::StaticConfig
46Parse(const yaml_config::YamlConfig& value, formats::parse::To<LinearController::StaticConfig>);
47
48} // namespace congestion_control::v2
49
50USERVER_NAMESPACE_END