userver: userver/storages/mongo/pool_config.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
pool_config.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/mongo/pool_config.hpp
4/// @brief @copybrief storages::mongo::PoolConfig
5
6#include <chrono>
7#include <cstddef>
8#include <optional>
9#include <string>
10
11#include <userver/components/component_fwd.hpp>
12#include <userver/congestion_control/controllers/linear.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace storages::mongo {
17
18enum class StatsVerbosity {
19 kTerse, ///< Only pool stats and read/write overalls by collection
20 kFull, ///< Stats with separate metrics per operation type and label
21 kNone, ///< No stats at all
22};
23
24/// @brief Mongo connection pool options
25///
26/// Dynamic option @ref MONGO_CONNECTION_POOL_SETTINGS
27struct PoolSettings final {
28 /// Default initial connection count
29 static constexpr size_t kDefaultInitialSize = 16;
30 /// Default total connections limit
31 static constexpr size_t kDefaultMaxSize = 128;
32 /// Default idle connections limit
33 static constexpr size_t kDefaultIdleLimit = 64;
34 /// Default establishing connections limit
35 static constexpr size_t kDefaultConnectingLimit = 8;
36
37 /// Initial connection count
39 /// Total connections limit
41 /// Idle connections limit
43 /// Establishing connections limit
45
46 /// @throws InvalidConfigException if pool settings are invalid
47 void Validate(const std::string& pool_id) const;
48};
49
50PoolSettings Parse(const yaml_config::YamlConfig& config, formats::parse::To<PoolSettings>);
51
52/// MongoDB connection pool configuration
53struct PoolConfig final {
54 enum class DriverImpl {
55 kMongoCDriver,
56 };
57
58 /// Default connection timeout
59 static constexpr auto kDefaultConnTimeout = std::chrono::seconds{2};
60 /// Default socket timeout
61 static constexpr auto kDefaultSoTimeout = std::chrono::seconds{10};
62 /// Default connection queue timeout
63 static constexpr auto kDefaultQueueTimeout = std::chrono::seconds{1};
64 /// Default pool maintenance period
65 static constexpr auto kDefaultMaintenancePeriod = std::chrono::seconds{15};
66 /// Default application name
67 static constexpr char kDefaultAppName[] = "userver";
68
69 /// @throws InvalidConfigException if the config is invalid
70 void Validate(const std::string& pool_id) const;
71
72 /// Connection (I/O) timeout
73 std::chrono::milliseconds conn_timeout = kDefaultConnTimeout;
74 /// Socket (I/O) timeout
75 std::chrono::milliseconds so_timeout = kDefaultSoTimeout;
76 /// Connection queue wait time
77 std::chrono::milliseconds queue_timeout = kDefaultQueueTimeout;
78 /// settings for connections pool
79 PoolSettings pool_settings{};
80 /// Instance selection latency window override
81 std::optional<std::chrono::milliseconds> local_threshold{};
82 /// Pool maintenance period
83 std::chrono::milliseconds maintenance_period = kDefaultMaintenancePeriod;
84
85 /// Application name (sent to server)
87 /// Default max replication lag for the pool
88 std::optional<std::chrono::seconds> max_replication_lag;
89
90 /// Driver implementation to use
91 DriverImpl driver_impl = DriverImpl::kMongoCDriver;
92
93 /// Whether to write detailed stats
95
96 /// Congestion control config
97 congestion_control::v2::LinearController::StaticConfig cc_config;
98};
99
100PoolConfig Parse(const yaml_config::YamlConfig& config, formats::parse::To<PoolConfig>);
101
102} // namespace storages::mongo
103
104USERVER_NAMESPACE_END