Skip to content

Commit

Permalink
Master-process initialization time stats (#932)
Browse files Browse the repository at this point in the history
A preparation for ML runtime that could be time consuming
We want to have some metrics to monitor
  • Loading branch information
mkornaukhov03 authored Nov 8, 2023
1 parent adaba6d commit 6e987fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/php-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::chrono::nanoseconds>(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) {
Expand Down
5 changes: 5 additions & 0 deletions server/statshouse/statshouse-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions server/statshouse/statshouse-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6e987fb

Please sign in to comment.