From aaec9d1db6985fead84004ea8d293d02f2a5dca7 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 1 Nov 2016 22:20:24 +0300 Subject: [PATCH] Attempt for improvement [#METR-21840]. --- .../Storages/MergeTree/SimpleMergeSelector.h | 10 ++----- .../MergeTree/SimpleMergeSelector.cpp | 27 +++++++------------ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/dbms/include/DB/Storages/MergeTree/SimpleMergeSelector.h b/dbms/include/DB/Storages/MergeTree/SimpleMergeSelector.h index 2e4b5b438da..2db28290884 100644 --- a/dbms/include/DB/Storages/MergeTree/SimpleMergeSelector.h +++ b/dbms/include/DB/Storages/MergeTree/SimpleMergeSelector.h @@ -17,15 +17,9 @@ public: * This behaviour balances merge-tree workload. * It called 'base', because merge-tree depth could be estimated as logarithm with that base. */ - double base = 8; - - /** Lower base by 1 after that time. - * It will be lowered by 2 after that time * 2^1, - * It will be lowered by 3 after that time * 2^2, - * and so on, exponentially. - */ - time_t lower_base_after = 30; + double base = 2; + time_t lower_base_after_seconds = 300; size_t lower_base_after_num_parts = 20; /// Zero means unlimited. diff --git a/dbms/src/Storages/MergeTree/SimpleMergeSelector.cpp b/dbms/src/Storages/MergeTree/SimpleMergeSelector.cpp index 0790fedce81..e8a87eb4b0b 100644 --- a/dbms/src/Storages/MergeTree/SimpleMergeSelector.cpp +++ b/dbms/src/Storages/MergeTree/SimpleMergeSelector.cpp @@ -74,6 +74,7 @@ struct Estimator void selectWithinPartition( const SimpleMergeSelector::PartsInPartition & parts, const size_t max_total_size_to_merge, + const time_t current_min_part_age, Estimator & estimator, const SimpleMergeSelector::Settings & settings) { @@ -115,7 +116,8 @@ void selectWithinPartition( double actual_base = settings.base; - if (parts.size() > settings.lower_base_after_num_parts) + if (parts.size() > settings.lower_base_after_num_parts + || current_min_part_age > settings.lower_base_after_seconds) actual_base = 1; { @@ -129,21 +131,6 @@ void selectWithinPartition( max_size = it->size; } - if (actual_base > 1) - { - time_t min_age = -1; - for (auto it = local_estimator.best_begin; it != local_estimator.best_end; ++it) - if (min_age == -1 || it->age < min_age) - min_age = it->age; - - if (min_age > settings.lower_base_after) - { - actual_base -= log2(min_age - settings.lower_base_after); - if (actual_base < 1) - actual_base = 1; - } - } - if (static_cast(sum_size) / max_size >= actual_base) estimator.consider(local_estimator.best_begin, local_estimator.best_end, sum_size, 0, 0); } @@ -156,10 +143,16 @@ SimpleMergeSelector::PartsInPartition SimpleMergeSelector::select( const Partitions & partitions, const size_t max_total_size_to_merge) { + time_t min_age = -1; + for (const auto & partition : partitions) + for (const auto & part : partition) + if (min_age == -1 || part.age < min_age) + min_age = part.age; + Estimator estimator; for (const auto & partition : partitions) - selectWithinPartition(partition, max_total_size_to_merge, estimator, settings); + selectWithinPartition(partition, max_total_size_to_merge, min_age, estimator, settings); return estimator.getBest(); }