userver: userver/components/manager_controller_component.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
manager_controller_component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/components/manager_controller_component.hpp
4/// @brief @copybrief components::ManagerControllerComponent
5
6#include <userver/components/component_fwd.hpp>
7#include <userver/components/raw_component_base.hpp>
8#include <userver/concurrent/async_event_source.hpp>
9#include <userver/dynamic_config/snapshot.hpp>
10#include <userver/engine/task/task_processor_fwd.hpp>
11#include <userver/utils/statistics/entry.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace components {
16
17namespace impl {
18class Manager;
19} // namespace impl
20
21// clang-format off
22
23/// @ingroup userver_components
24///
25/// @brief Component that prepares the engine internals and starts all the
26/// other components.
27///
28/// ## ManagerControllerComponent Dynamic config
29/// * @ref USERVER_TASK_PROCESSOR_PROFILER_DEBUG
30/// * @ref USERVER_TASK_PROCESSOR_QOS
31///
32/// ## Static options:
33/// Name | Description | Default value
34/// ---- | ----------- | -------------
35/// coro_pool.initial_size | amount of coroutines to preallocate on startup | 1000
36/// coro_pool.max_size | max amount of coroutines to keep preallocated | 4000
37/// coro_pool.stack_size | size of a single coroutine stack @ref scripts/docs/en/userver/stack.md | 256 * 1024
38/// coro_pool.local_cache_size | local coroutine cache size per thread | 32
39/// coro_pool.stack_usage_monitor_enabled | whether stack usage is accounted and warnings about too high stack usage are logged @ref scripts/docs/en/userver/stack.md | true
40/// event_thread_pool.threads | number of threads to process low level IO system calls (number of ev loops to start in libev) | 2
41/// event_thread_pool.thread_name | set OS thread name to this value | 'event-worker'
42/// components | dictionary of "component name": "options" | -
43/// default_task_processor | name of the default task processor to use in components | main-task-processor
44/// fs_task_processor | name of the blocking task processor to use in components | fs-task-processor
45/// task_processors.*NAME*.*OPTIONS* | dictionary of task processors to create and their options. See description below | -
46/// mlock_debug_info | whether to mlock(2) process debug info to prevent major page faults on unwinding | true
47/// disable_phdr_cache | whether to disable caching of phdr_info objects. Usable if rebuilding with cmake variable USERVER_DISABLE_PHDR_CACHE is off limits, and has the same effect | false
48/// static_config_validation.validate_all_components | whether to validate static config according to schema; should be `true` for all new services | true
49/// preheat_stacktrace_collector | whether to collect a dummy stacktrace at server start up (usable to avoid loading debug info at random point at runtime) | true
50/// userver_experiments.*NAME* | whether to enable certain userver experiments; these are gradually enabled by userver team, for internal use only | false
51/// graceful_shutdown_interval | at shutdown, first hang for this duration with /ping 5xx to give the balancer a chance to redirect new requests to other hosts | 0s
52/// enable_trx_tracker | Enable checking of heavy operations (like http calls) while having active database transactions. | true
53///
54/// ## Static task_processor options:
55/// Name | Description | Default value
56/// ---- | ----------- | -------------
57/// guess-cpu-limit | guess optimal threads count | false
58/// thread_name | set OS thread name to this value | Part of the task_processor name before the first '-' symbol with '-worker' appended; for example 'fs-worker' or 'main-worker'
59/// worker_threads | threads count for the task processor | -
60/// os-scheduling | OS scheduling mode for the task processor threads. 'idle' sets the lowest priority. 'low-priority' sets the priority below 'normal' but higher than 'idle'. | normal
61/// spinning-iterations | tunes the number of spin-wait iterations in case of an empty task queue before threads go to sleep | 1000
62/// task-processor-queue | Task queue mode for the task processor. `global-task-queue` default task queue. `work-stealing-task-queue` experimental with potentially better scalability than `global-task-queue`. | global-task-queue
63/// task-trace | optional dictionary of tracing options | empty (disabled)
64/// task-trace.every | set N to trace each Nth task | 1000
65/// task-trace.max-context-switch-count | set upper limit of context switches to trace for a single task | 1000
66/// task-trace.logger | required name of logger to write traces to, should not be the 'default' logger | -
67///
68/// Tips and tricks on `task-trace` usage are described in
69/// @ref scripts/docs/en/userver/profile_context_switches.md.
70///
71/// ## Static configuration example:
72///
73/// @snippet components/common_component_list_test.cpp Sample components manager config component config
74
75// clang-format on
76class ManagerControllerComponent final : public RawComponentBase {
77public:
78 /// @ingroup userver_component_names
79 /// @brief The default name of components::ManagerControllerComponent
80 static constexpr std::string_view kName = "manager-controller";
81
82 ManagerControllerComponent(const components::ComponentConfig& config, const components::ComponentContext& context);
83
84 ~ManagerControllerComponent() override;
85
86private:
87 void WriteStatistics(utils::statistics::Writer& writer);
88
89 void OnConfigUpdate(const dynamic_config::Snapshot& cfg);
90
91 const components::impl::Manager& components_manager_;
92 utils::statistics::Entry statistics_holder_;
93 concurrent::AsyncEventSubscriberScope config_subscription_;
94};
95
96template <>
97inline constexpr auto kConfigFileMode<ManagerControllerComponent> = ConfigFileMode::kNotRequired;
98
99} // namespace components
100
101USERVER_NAMESPACE_END