From 6e987fbb6f9befa06c4d382b2b9dc80aa1de7621 Mon Sep 17 00:00:00 2001 From: Mikhail Kornaukhov <66915223+mkornaukhov03@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:13:42 +0300 Subject: [PATCH] Master-process initialization time stats (#932) A preparation for ML runtime that could be time consuming We want to have some metrics to monitor --- server/php-engine.cpp | 7 +++++++ server/statshouse/statshouse-manager.cpp | 5 +++++ server/statshouse/statshouse-manager.h | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/server/php-engine.cpp b/server/php-engine.cpp index 6dea76896a..79d3903e01 100644 --- a/server/php-engine.cpp +++ b/server/php-engine.cpp @@ -63,6 +63,7 @@ #include "runtime/rpc.h" #include "runtime/thread-pool.h" #include "server/confdata-binlog-replay.h" +#include "server/confdata-stats.h" #include "server/database-drivers/adaptor.h" #include "server/database-drivers/connector.h" #include "server/job-workers/job-worker-client.h" @@ -1641,6 +1642,8 @@ char **get_runtime_options(int *count) noexcept; void init_all() { srand48((long)cycleclock_now()); + auto start_time = std::chrono::steady_clock::now(); + //init pending_http_queue pending_http_queue.first_query = pending_http_queue.last_query = (conn_query *)&pending_http_queue; php_worker_run_flag = 0; @@ -1674,6 +1677,10 @@ void init_all() { worker_id = (int)lrand48(); init_confdata_binlog_reader(); + + auto end_time = std::chrono::steady_clock::now(); + uint64_t total_init_ns = std::chrono::duration_cast(start_time - end_time).count(); + StatsHouseManager::get().add_init_master_stats(total_init_ns, ConfdataStats::get().initial_loading_time.count()); } void init_logname(const char *src) { diff --git a/server/statshouse/statshouse-manager.cpp b/server/statshouse/statshouse-manager.cpp index 3ad25aed29..905c29009f 100644 --- a/server/statshouse/statshouse-manager.cpp +++ b/server/statshouse/statshouse-manager.cpp @@ -244,6 +244,11 @@ void StatsHouseManager::add_common_master_stats(const workers_stats_t &workers_s } } +void StatsHouseManager::add_init_master_stats(uint64_t total_init_ns, uint64_t confdata_init_ns) { + client.metric("kphp_by_host_master_total_init_time", true).write_value(total_init_ns); + client.metric("kphp_by_host_master_confdata_init_time", true).write_value(confdata_init_ns); +} + void StatsHouseManager::add_job_workers_shared_memory_stats(const job_workers::JobStats &job_stats) { using namespace job_workers; diff --git a/server/statshouse/statshouse-manager.h b/server/statshouse/statshouse-manager.h index 7957a04681..f17270fda4 100644 --- a/server/statshouse/statshouse-manager.h +++ b/server/statshouse/statshouse-manager.h @@ -61,6 +61,11 @@ class StatsHouseManager : vk::not_copyable { void add_common_master_stats(const workers_stats_t &workers_stats, const memory_resource::MemoryStats &memory_stats, double cpu_s_usage, double cpu_u_usage, long long int instance_cache_memory_swaps_ok, long long int instance_cache_memory_swaps_fail); + /** + * Must be called from master process only + */ + void add_init_master_stats(uint64_t total_init_ns, uint64_t confdata_init_ns); + private: StatsHouseClient client; bool need_write_enable_tag_host = false;