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 {
18 public:
19 using StaticConfig = Controller::Config;
20
21 LinearController(
22 const std::string& name, v2::Sensor& sensor, Limiter& limiter,
23 Stats& stats, const StaticConfig& config,
24 dynamic_config::Source config_source,
25 std::function<v2::Config(const dynamic_config::Snapshot&)> config_getter);
26
27 Limit Update(const Sensor::Data& current) override;
28
29 private:
30 StaticConfig config_;
31 utils::SlidingInterval<int64_t> current_load_;
32 utils::SlidingInterval<int64_t> long_timings_;
33 utils::SlidingInterval<int64_t> short_timings_;
34 std::optional<std::size_t> current_limit_;
35 std::size_t epochs_passed_{0};
36
37 dynamic_config::Source config_source_;
38 std::function<v2::Config(const dynamic_config::Snapshot&)> config_getter_;
39};
40
41LinearController::StaticConfig Parse(
42 const yaml_config::YamlConfig& value,
43 formats::parse::To<LinearController::StaticConfig>);
44
45} // namespace congestion_control::v2
46
47USERVER_NAMESPACE_END