userver: userver/storages/mongo/pool_config.hpp Source File
Loading...
Searching...
No Matches
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};
22
23/// MongoDB connection pool configuration
24struct PoolConfig final {
25 enum class DriverImpl {
26 kMongoCDriver,
27 };
28
29 /// Default connection timeout
30 static constexpr auto kDefaultConnTimeout = std::chrono::seconds{2};
31 /// Default socket timeout
32 static constexpr auto kDefaultSoTimeout = std::chrono::seconds{10};
33 /// Default connection queue timeout
34 static constexpr auto kDefaultQueueTimeout = std::chrono::seconds{1};
35 /// Default initial connection count
36 static constexpr size_t kDefaultInitialSize = 16;
37 /// Default total connections limit
38 static constexpr size_t kDefaultMaxSize = 128;
39 /// Default idle connections limit
40 static constexpr size_t kDefaultIdleLimit = 64;
41 /// Default establishing connections limit
42 static constexpr size_t kDefaultConnectingLimit = 8;
43 /// Default pool maintenance period
44 static constexpr auto kDefaultMaintenancePeriod = std::chrono::seconds{15};
45 /// Default application name
46 static constexpr char kDefaultAppName[] = "userver";
47
48 /// @throws InvalidConfigException if the config is invalid
49 void Validate(const std::string& pool_id) const;
50
51 /// Connection (I/O) timeout
52 std::chrono::milliseconds conn_timeout = kDefaultConnTimeout;
53 /// Socket (I/O) timeout
54 std::chrono::milliseconds so_timeout = kDefaultSoTimeout;
55 /// Connection queue wait time
56 std::chrono::milliseconds queue_timeout = kDefaultQueueTimeout;
57 /// Initial connection count
58 size_t initial_size = kDefaultInitialSize;
59 /// Total connections limit
60 size_t max_size = kDefaultMaxSize;
61 /// Idle connections limit
62 size_t idle_limit = kDefaultIdleLimit;
63 /// Establishing connections limit
64 size_t connecting_limit = kDefaultConnectingLimit;
65 /// Instance selection latency window override
66 std::optional<std::chrono::milliseconds> local_threshold{};
67 /// Pool maintenance period
68 std::chrono::milliseconds maintenance_period = kDefaultMaintenancePeriod;
69
70 /// Application name (sent to server)
71 std::string app_name = kDefaultAppName;
72 /// Default max replication lag for the pool
74
75 /// Driver implementation to use
76 DriverImpl driver_impl = DriverImpl::kMongoCDriver;
77
78 /// Whether to write detailed stats
80
81 /// Congestion control config
82 congestion_control::v2::LinearController::StaticConfig cc_config;
83};
84
85PoolConfig Parse(const yaml_config::YamlConfig& config,
86 formats::parse::To<PoolConfig>);
87
88} // namespace storages::mongo
89
90USERVER_NAMESPACE_END