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

feat(hotspot): add a cluster level perf_counter to display hotspot #732

Merged
merged 11 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion rdsn
Submodule rdsn updated 48 files
+16 −3 src/perf_counter/builtin_counters.cpp
+16 −3 src/perf_counter/builtin_counters.h
+16 −3 src/replica/backup/test/main.cpp
+16 −3 src/replica/duplication/duplication_pipeline.cpp
+16 −3 src/replica/duplication/duplication_pipeline.h
+16 −3 src/replica/duplication/test/duplication_sync_timer_test.cpp
+16 −3 src/replica/duplication/test/duplication_test_base.h
+16 −3 src/replica/duplication/test/load_from_private_log_test.cpp
+16 −3 src/replica/duplication/test/main.cpp
+16 −25 src/replica/duplication/test/mutation_batch_test.cpp
+16 −3 src/replica/duplication/test/replica_duplicator_manager_test.cpp
+16 −3 src/replica/duplication/test/replica_duplicator_test.cpp
+16 −3 src/replica/duplication/test/replica_http_service_test.cpp
+16 −3 src/replica/duplication/test/ship_mutation_test.cpp
+16 −3 src/replica/log_block.cpp
+16 −3 src/replica/log_block.h
+16 −3 src/replica/mutation_log_replay.cpp
+16 −3 src/replica/replica_http_service.cpp
+16 −3 src/replica/replica_http_service.h
+17 −0 src/replica/replica_restore.cpp
+1 −1 src/replica/replica_stub.cpp
+16 −3 src/replica/replica_throttle.cpp
+16 −3 src/replica/test/backup_block_service_mock.h
+17 −0 src/replica/test/cold_backup_context_test.cpp
+16 −3 src/replica/test/log_block_test.cpp
+16 −3 src/replica/test/log_file_test.cpp
+17 −0 src/replica/test/main.cpp
+16 −3 src/replica/test/replica_learn_test.cpp
+16 −3 src/replica/test/throttling_controller_test.cpp
+17 −0 src/runtime/security/security.thrift
+26 −0 src/runtime/task/task_code.cpp
+25 −0 src/runtime/test/corrupt_message.cpp
+16 −3 src/runtime/test/message_reader_test.cpp
+16 −3 src/runtime/test/task_test.cpp
+16 −3 src/runtime/test/thrift_message_parser_test.cpp
+26 −0 src/runtime/threadpool_code.cpp
+25 −0 src/utils/error_code.cpp
+16 −3 src/utils/fail_point.cpp
+16 −3 src/utils/fail_point_impl.h
+16 −3 src/utils/flags.cpp
+16 −3 src/utils/math.cpp
+25 −0 src/utils/strings.cpp
+16 −3 src/utils/test/endian_test.cpp
+16 −3 src/utils/test/file_system_test.cpp
+16 −3 src/utils/test/hostname_test.cpp
+17 −0 src/utils/test/main.cpp
+16 −3 src/utils/test/rand_test.cpp
+26 −0 src/zookeeper/test/distributed_lock_zookeeper.cpp
39 changes: 28 additions & 11 deletions src/server/hotspot_partition_calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,18 @@ void hotspot_partition_calculator::init_perf_counter(int partition_count)
_hot_points[i][data_type].init_app_counter(
"app.pegasus", counter_name.c_str(), COUNTER_TYPE_NUMBER, counter_desc.c_str());
}

string total_desc =
_app_name + '.' +
(data_type == partition_qps_type::WRITE_HOTSPOT_DATA ? "write.total" : "read.total");
std::string counter_name = fmt::format("app.stat.hotspots.{}", total_desc);
std::string counter_desc = fmt::format("statistic the hotspots of app {}", total_desc);
_total_hotspot_cnt[data_type].init_app_counter(
"app.pegasus", counter_name.c_str(), COUNTER_TYPE_NUMBER, counter_desc.c_str());
}
}

void hotspot_partition_calculator::stat_histories_analyse(int data_type,
void hotspot_partition_calculator::stat_histories_analyse(uint32_t data_type,
std::vector<int> &hot_points)
{
double table_qps_sum = 0, standard_deviation = 0, table_qps_avg = 0;
Expand Down Expand Up @@ -121,13 +129,19 @@ void hotspot_partition_calculator::stat_histories_analyse(int data_type,
}
}

void hotspot_partition_calculator::update_hot_point(int data_type, std::vector<int> &hot_points)
void hotspot_partition_calculator::update_hot_point(uint32_t data_type,
const std::vector<int> &hot_points)
{
dcheck_eq(_hot_points.size(), hot_points.size());
int size = hot_points.size();
uint32_t hotspot_count = 0;
for (int i = 0; i < size; i++) {
_hot_points[i][data_type].get()->set(hot_points[i]);
if (hot_points[i] >= FLAGS_hot_partition_threshold) {
hotspot_count++;
}
}
_total_hotspot_cnt[data_type].get()->set(hotspot_count);
}

void hotspot_partition_calculator::data_analyse()
Expand All @@ -136,18 +150,21 @@ void hotspot_partition_calculator::data_analyse()
"The number of partitions in this table has changed, and hotspot analysis cannot be "
"performed,in %s",
_app_name.c_str());
for (int data_type = 0; data_type <= 1; data_type++) {
// data_type 0: READ_HOTSPOT_DATA; 1: WRITE_HOTSPOT_DATA
std::vector<int> hot_points;
stat_histories_analyse(data_type, hot_points);
update_hot_point(data_type, hot_points);
}

std::vector<int> read_hot_points;
stat_histories_analyse(READ_HOTSPOT_DATA, read_hot_points);
update_hot_point(READ_HOTSPOT_DATA, read_hot_points);

std::vector<int> write_hot_points;
stat_histories_analyse(WRITE_HOTSPOT_DATA, write_hot_points);
update_hot_point(WRITE_HOTSPOT_DATA, write_hot_points);

if (!FLAGS_enable_detect_hotkey) {
return;
}
for (int data_type = 0; data_type <= 1; data_type++) {
detect_hotkey_in_hotpartition(data_type);
}

detect_hotkey_in_hotpartition(READ_HOTSPOT_DATA);
detect_hotkey_in_hotpartition(WRITE_HOTSPOT_DATA);
}

void hotspot_partition_calculator::detect_hotkey_in_hotpartition(int data_type)
Expand Down
8 changes: 6 additions & 2 deletions src/server/hotspot_partition_calculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ class hotspot_partition_calculator
private:
// empirical rule to calculate hot point of each partition
// ref: https://en.wikipedia.org/wiki/68%E2%80%9395%E2%80%9399.7_rule
void stat_histories_analyse(int data_type, std::vector<int> &hot_points);
void stat_histories_analyse(uint32_t data_type, std::vector<int> &hot_points);
// set hot_point to corresponding perf_counter
void update_hot_point(int data_type, std::vector<int> &hot_points);
void update_hot_point(uint32_t data_type, const std::vector<int> &hot_points);
void detect_hotkey_in_hotpartition(int data_type);

const std::string _app_name;
void init_perf_counter(int perf_counter_count);
// usually a partition with "hot-point value" >= 3 can be considered as a hotspot partition.
hot_partition_counters _hot_points;
// hotspot_cnt c[type_of_read(0)/write(1)_stat] = number of hot partition count in one table
// per data_analyse
std::array<dsn::perf_counter_wrapper, 2> _total_hotspot_cnt;

// saving historical data can improve accuracy
stat_histories _partitions_stat_histories;
std::shared_ptr<shell_context> _shell_context;
Expand Down
41 changes: 36 additions & 5 deletions src/server/test/hotspot_partition_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,26 @@ class hotspot_partition_test : public pegasus_server_test_base
return result;
}

std::array<uint32_t, 2>
get_calculator_total_hotspot_cnt(const std::array<dsn::perf_counter_wrapper, 2> &cnts)
{
std::array<uint32_t, 2> result;
result[READ_HOTSPOT_DATA] = cnts[READ_HOTSPOT_DATA].get()->get_value();
result[WRITE_HOTSPOT_DATA] = cnts[WRITE_HOTSPOT_DATA].get()->get_value();
return result;
}

void test_policy_in_scenarios(std::vector<row_data> scenario,
std::vector<std::vector<double>> &expect_result)
std::vector<std::vector<double>> &expect_result,
std::array<uint32_t, 2> expect_cnt)
{
calculator.data_aggregate(std::move(scenario));
calculator.data_analyse();
std::vector<std::vector<double>> result = get_calculator_result(calculator._hot_points);
auto cnt = get_calculator_total_hotspot_cnt(calculator._total_hotspot_cnt);

ASSERT_EQ(result, expect_result);
ASSERT_EQ(cnt, expect_cnt);
}

void aggregate_analyse_data(std::vector<row_data> scenario,
Expand All @@ -101,7 +114,9 @@ TEST_F(hotspot_partition_test, hotspot_partition_policy)
std::vector<row_data> test_rows = generate_row_data();
std::vector<std::vector<double>> expect_vector = {{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}};
test_policy_in_scenarios(test_rows, expect_vector);

std::array<uint32_t, 2> expect_hotspot_cnt = {0, 0};
test_policy_in_scenarios(test_rows, expect_vector, expect_hotspot_cnt);

// Insert hotspot scenario_0 data to test
test_rows = generate_row_data();
Expand All @@ -110,14 +125,16 @@ TEST_F(hotspot_partition_test, hotspot_partition_policy)
test_rows[HOT_SCENARIO_0_READ_HOT_PARTITION].get_qps = 5000.0;
test_rows[HOT_SCENARIO_0_WRITE_HOT_PARTITION].put_qps = 5000.0;
expect_vector = {{0, 0, 0, 0, 0, 0, 0, 4}, {4, 0, 0, 0, 0, 0, 0, 0}};
test_policy_in_scenarios(test_rows, expect_vector);
expect_hotspot_cnt = {1, 1};
test_policy_in_scenarios(test_rows, expect_vector, expect_hotspot_cnt);

// Insert hotspot scenario_0 data to test again
test_rows = generate_row_data();
test_rows[HOT_SCENARIO_0_READ_HOT_PARTITION].get_qps = 5000.0;
test_rows[HOT_SCENARIO_0_WRITE_HOT_PARTITION].put_qps = 5000.0;
expect_vector = {{0, 0, 0, 0, 0, 0, 0, 4}, {4, 0, 0, 0, 0, 0, 0, 0}};
test_policy_in_scenarios(test_rows, expect_vector);
expect_hotspot_cnt = {1, 1};
test_policy_in_scenarios(test_rows, expect_vector, expect_hotspot_cnt);

// Insert hotspot scenario_1 data to test again
test_rows = generate_row_data();
Expand All @@ -126,7 +143,21 @@ TEST_F(hotspot_partition_test, hotspot_partition_policy)
test_rows[HOT_SCENARIO_1_READ_HOT_PARTITION].get_qps = 5000.0;
test_rows[HOT_SCENARIO_1_WRITE_HOT_PARTITION].put_qps = 5000.0;
expect_vector = {{0, 0, 0, 4, 0, 0, 0, 0}, {0, 0, 4, 0, 0, 0, 0, 0}};
test_policy_in_scenarios(test_rows, expect_vector);
expect_hotspot_cnt = {1, 1};
test_policy_in_scenarios(test_rows, expect_vector, expect_hotspot_cnt);

test_rows = generate_row_data();
const int HOT_SCENARIO_2_READ_HOT_PARTITION_0 = 3;
const int HOT_SCENARIO_2_READ_HOT_PARTITION_1 = 5;
const int HOT_SCENARIO_2_WRITE_HOT_PARTITION = 2;

test_rows[HOT_SCENARIO_2_READ_HOT_PARTITION_0].get_qps = 7000.0;
test_rows[HOT_SCENARIO_2_READ_HOT_PARTITION_1].get_qps = 8000.0;
test_rows[HOT_SCENARIO_2_WRITE_HOT_PARTITION].put_qps = 7000.0;

expect_vector = {{0, 0, 0, 4, 0, 4, 0, 0}, {0, 0, 4, 0, 0, 0, 0, 0}};
expect_hotspot_cnt = {2, 1};
test_policy_in_scenarios(test_rows, expect_vector, expect_hotspot_cnt);
clear_calculator_histories();
}

Expand Down