Skip to content

Commit 1df1380

Browse files
author
Alex Katsman
committed
Make settings controlling connection drop on overloaded CPU hot-reloadable
1 parent f258b50 commit 1df1380

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

programs/server/Server.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,6 +1951,8 @@ try
19511951
global_context->setMaxPendingMutationsExecutionTimeToWarn(new_server_settings[ServerSetting::max_pending_mutations_execution_time_to_warn]);
19521952
global_context->getAccessControl().setAllowTierSettings(new_server_settings[ServerSetting::allow_feature_tier]);
19531953

1954+
global_context->setOSCPUOverloadSettings(new_server_settings[ServerSetting::min_os_cpu_wait_time_ratio_to_drop_connection], new_server_settings[ServerSetting::max_os_cpu_wait_time_ratio_to_drop_connection]);
1955+
19541956
size_t read_bandwidth = new_server_settings[ServerSetting::max_remote_read_network_bandwidth_for_server];
19551957
size_t write_bandwidth = new_server_settings[ServerSetting::max_remote_write_network_bandwidth_for_server];
19561958

@@ -2859,10 +2861,9 @@ void Server::createServers(
28592861

28602862
const TCPServerConnectionFilter::Ptr & connection_filter = new TCPServerConnectionFilter{[&]()
28612863
{
2862-
const auto & server_settings = global_context->getServerSettings();
2863-
return !ProfileEvents::checkCPUOverload(server_settings[ServerSetting::os_cpu_busy_time_threshold],
2864-
server_settings[ServerSetting::min_os_cpu_wait_time_ratio_to_drop_connection],
2865-
server_settings[ServerSetting::max_os_cpu_wait_time_ratio_to_drop_connection],
2864+
return !ProfileEvents::checkCPUOverload(global_context->getServerSettings()[ServerSetting::os_cpu_busy_time_threshold],
2865+
global_context->getMinOSCPUWaitTimeRatioToDropConnection(),
2866+
global_context->getMaxOSCPUWaitTimeRatioToDropConnection(),
28662867
/*should_throw*/ false);
28672868
}};
28682869

src/Core/ServerSettings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,9 @@ void ServerSettings::dumpToSystemServerSettingsColumns(ServerSettingColumnsParam
11731173
{"max_pending_mutations_execution_time_to_warn", {std::to_string(context->getMaxPendingMutationsExecutionTimeToWarn()), ChangeableWithoutRestart::Yes}},
11741174
{"max_partition_size_to_drop", {std::to_string(context->getMaxPartitionSizeToDrop()), ChangeableWithoutRestart::Yes}},
11751175

1176+
{"min_os_cpu_wait_time_ratio_to_drop_connection", {std::to_string(context->getMinOSCPUWaitTimeRatioToDropConnection()), ChangeableWithoutRestart::Yes}},
1177+
{"max_os_cpu_wait_time_ratio_to_drop_connection", {std::to_string(context->getMaxOSCPUWaitTimeRatioToDropConnection()), ChangeableWithoutRestart::Yes}},
1178+
11761179
{"max_concurrent_queries", {std::to_string(context->getProcessList().getMaxSize()), ChangeableWithoutRestart::Yes}},
11771180
{"max_concurrent_insert_queries",
11781181
{std::to_string(context->getProcessList().getMaxInsertQueriesAmount()), ChangeableWithoutRestart::Yes}},

src/Interpreters/Context.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ struct ContextSharedPart : boost::noncopyable
530530
/// Only for system.server_settings, actually value stored in reloader itself
531531
std::atomic_size_t config_reload_interval_ms = ConfigReloader::DEFAULT_RELOAD_INTERVAL.count();
532532

533+
double min_os_cpu_wait_time_ratio_to_drop_connection = 10.0;
534+
double max_os_cpu_wait_time_ratio_to_drop_connection = 20.0;
535+
533536
String format_schema_path; /// Path to a directory that contains schema files used by input formats.
534537
String google_protos_path; /// Path to a directory that contains the proto files for the well-known Protobuf types.
535538
mutable OnceFlag action_locks_manager_initialized;
@@ -4561,6 +4564,25 @@ void Context::setMaxDatabaseNumToWarn(size_t max_database_to_warn)
45614564
shared->max_database_num_to_warn = max_database_to_warn;
45624565
}
45634566

4567+
double Context::getMinOSCPUWaitTimeRatioToDropConnection() const
4568+
{
4569+
SharedLockGuard lock(shared->mutex);
4570+
return shared->min_os_cpu_wait_time_ratio_to_drop_connection;
4571+
}
4572+
4573+
double Context::getMaxOSCPUWaitTimeRatioToDropConnection() const
4574+
{
4575+
SharedLockGuard lock(shared->mutex);
4576+
return shared->max_os_cpu_wait_time_ratio_to_drop_connection;
4577+
}
4578+
4579+
void Context::setOSCPUOverloadSettings(double min_os_cpu_wait_time_ratio_to_drop_connection, double max_os_cpu_wait_time_ratio_to_drop_connection)
4580+
{
4581+
SharedLockGuard lock(shared->mutex);
4582+
shared->min_os_cpu_wait_time_ratio_to_drop_connection = min_os_cpu_wait_time_ratio_to_drop_connection;
4583+
shared->max_os_cpu_wait_time_ratio_to_drop_connection = max_os_cpu_wait_time_ratio_to_drop_connection;
4584+
}
4585+
45644586
std::shared_ptr<Cluster> Context::getCluster(const std::string & cluster_name) const
45654587
{
45664588
if (auto res = tryGetCluster(cluster_name))

src/Interpreters/Context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,10 @@ class Context: public ContextData, public std::enable_shared_from_this<Context>
10351035
void setMaxPendingMutationsToWarn(size_t max_pending_mutations_to_warn);
10361036
void setMaxPendingMutationsExecutionTimeToWarn(size_t max_pending_mutations_execution_time_to_warn);
10371037

1038+
double getMinOSCPUWaitTimeRatioToDropConnection() const;
1039+
double getMaxOSCPUWaitTimeRatioToDropConnection() const;
1040+
void setOSCPUOverloadSettings(double min_os_cpu_wait_time_ratio_to_drop_connection, double max_os_cpu_wait_time_ratio_to_drop_connection);
1041+
10381042
/// The port that the server listens for executing SQL queries.
10391043
UInt16 getTCPPort() const;
10401044

0 commit comments

Comments
 (0)