Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support auto spill set by tidb #8037

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions dbms/src/Core/AutoSpillTrigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,26 @@ class AutoSpillTrigger
AutoSpillTrigger(
const MemoryTrackerPtr & memory_tracker_,
const std::shared_ptr<QueryOperatorSpillContexts> & query_operator_spill_contexts_,
float auto_memory_revoke_trigger_threshold,
float auto_memory_revoke_target_threshold)
double auto_memory_revoke_trigger_threshold)
: memory_tracker(memory_tracker_)
, query_operator_spill_contexts(query_operator_spill_contexts_)
{
RUNTIME_CHECK_MSG(memory_tracker->getLimit() > 0, "Memory limit must be set for auto spill trigger");
RUNTIME_CHECK_MSG(
auto_memory_revoke_target_threshold >= 0 && auto_memory_revoke_trigger_threshold > 0,
"Invalid auto trigger threshold {} or invalid auto target threshold {}",
auto_memory_revoke_trigger_threshold,
auto_memory_revoke_target_threshold);
if (unlikely(
auto_memory_revoke_trigger_threshold < auto_memory_revoke_target_threshold
|| auto_memory_revoke_trigger_threshold > MAX_TRIGGER_THRESHOLD))
auto_memory_revoke_trigger_threshold > 0,
"Invalid auto trigger threshold {}",
auto_memory_revoke_trigger_threshold);
if (unlikely(auto_memory_revoke_trigger_threshold > MAX_TRIGGER_THRESHOLD))
{
LOG_WARNING(
query_operator_spill_contexts->getLogger(),
"Auto trigger threshold {} less than auto target threshold {} or more than max trigger threshold {}, "
"not valid, use default value instead",
"Auto trigger threshold {} more than max trigger threshold {}, not valid, use default value instead",
auto_memory_revoke_trigger_threshold,
auto_memory_revoke_target_threshold,
MAX_TRIGGER_THRESHOLD);
/// invalid value, set the value to default value
auto_memory_revoke_trigger_threshold = 0.7;
auto_memory_revoke_target_threshold = 0.5;
}
auto auto_memory_revoke_target_threshold = std::max(0.0, auto_memory_revoke_trigger_threshold - 0.2);
trigger_threshold = static_cast<Int64>(memory_tracker->getLimit() * auto_memory_revoke_trigger_threshold);
target_threshold = static_cast<Int64>(memory_tracker->getLimit() * auto_memory_revoke_target_threshold);
force_trigger_threshold = static_cast<Int64>(memory_tracker->getLimit() * MAX_TRIGGER_THRESHOLD);
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Flash/FlashService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ void updateSettingsFromTiDB(const grpc::ServerContext * grpc_context, ContextPtr
std::make_pair("tidb_max_bytes_before_tiflash_external_group_by", "max_bytes_before_external_group_by"),
std::make_pair("tidb_max_bytes_before_tiflash_external_sort", "max_bytes_before_external_sort"),
std::make_pair("tidb_enable_tiflash_pipeline_model", "enable_pipeline"),
std::make_pair("tidb_max_tiflash_query_memory_per_node", "max_memory_usage"),
std::make_pair("tidb_tiflash_auto_spill_ratio", "auto_memory_revoke_trigger_threshold"),
windtalker marked this conversation as resolved.
Show resolved Hide resolved
};
for (const auto & names : tidb_varname_to_tiflash_varname)
{
Expand Down
8 changes: 2 additions & 6 deletions dbms/src/Flash/executeQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ QueryExecutorPtr doExecuteAsBlockIO(IQuerySource & dag, Context & context, bool
{
dag_context.setAutoSpillMode();
auto auto_spill_trigger_threshold = context.getSettingsRef().auto_memory_revoke_trigger_threshold.get();
auto auto_spill_target_threshold = context.getSettingsRef().auto_memory_revoke_target_threshold.get();
auto auto_spill_trigger = std::make_shared<AutoSpillTrigger>(
memory_tracker,
dag_context.getQueryOperatorSpillContexts(),
auto_spill_trigger_threshold,
auto_spill_target_threshold);
auto_spill_trigger_threshold);
dag_context.setAutoSpillTrigger(auto_spill_trigger);
}

Expand Down Expand Up @@ -181,12 +179,10 @@ std::optional<QueryExecutorPtr> executeAsPipeline(Context & context, bool intern
context.getDAGContext()->registerOperatorSpillContext(operator_spill_context);
};
auto auto_spill_trigger_threshold = context.getSettingsRef().auto_memory_revoke_trigger_threshold.get();
auto auto_spill_target_threshold = context.getSettingsRef().auto_memory_revoke_target_threshold.get();
auto auto_spill_trigger = std::make_shared<AutoSpillTrigger>(
memory_tracker,
dag_context.getQueryOperatorSpillContexts(),
auto_spill_trigger_threshold,
auto_spill_target_threshold);
auto_spill_trigger_threshold);
dag_context.setAutoSpillTrigger(auto_spill_trigger);
executor = std::make_unique<PipelineExecutor>(
memory_tracker,
Expand Down
3 changes: 1 addition & 2 deletions dbms/src/Interpreters/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ struct Settings
M(SettingInt64, max_buffered_bytes_in_executor, 100LL * 1024 * 1024, "The max buffered size in each executor, 0 mean unlimited, use 200MB as the default value") \
M(SettingUInt64, ddl_sync_interval_seconds, 60, "The interval of background DDL sync schema in seconds") \
M(SettingUInt64, ddl_restart_wait_seconds, 180, "The wait time for sync schema in seconds when restart") \
M(SettingFloat, auto_memory_revoke_trigger_threshold, 0.7, "Trigger auto memory revocation when the memory usage is above this percentage.") \
M(SettingFloat, auto_memory_revoke_target_threshold, 0.5, "When auto revoking memory, try to revoke enough that the memory usage is filled below the target percentage at the end.") \
M(SettingDouble, auto_memory_revoke_trigger_threshold, 0.0, "Trigger auto memory revocation when the memory usage is above this percentage.") \
M(SettingUInt64, remote_read_queue_size, 0, "size of remote read queue, 0 means it is determined automatically") \
M(SettingBool, enable_cop_stream_for_remote_read, true, "Enable cop stream for remote read") \
M(SettingUInt64, cop_timeout_for_remote_read, 60, "cop timeout seconds for remote read") \
Expand Down