Skip to content

Commit

Permalink
Add 'kphp_request_time_script_max_running_interval' mertric collecting (
Browse files Browse the repository at this point in the history
#1111)

Signed-off-by: Petr Shumilov <[email protected]>
Co-authored-by: Petr Shumilov <[email protected]>
  • Loading branch information
PetrShumilov and PetrShumilov authored Oct 3, 2024
1 parent 38b4837 commit 02d3786
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions server/php-runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ void PhpScript::init(script_t *script, php_query_data_t *data_to_set) noexcept {

script_time = 0;
net_time = 0;
script_max_running_interval = 0;
script_init_rusage = get_rusage_info();

queries_cnt = 0;
Expand Down Expand Up @@ -281,7 +282,9 @@ void PhpScript::update_net_time() noexcept {

void PhpScript::update_script_time() noexcept {
double new_cur_timestamp = dl_time();
script_time += new_cur_timestamp - cur_timestamp;
double delta = new_cur_timestamp - cur_timestamp;
script_time += delta;
script_max_running_interval = std::fmax(script_max_running_interval, delta);
cur_timestamp = new_cur_timestamp;
}

Expand Down Expand Up @@ -320,7 +323,7 @@ void PhpScript::finish() noexcept {
}
process_rusage_t script_rusage = get_script_rusage();

vk::singleton<ServerStats>::get().add_request_stats(script_time, net_time, script_init_time_sec, connection_process_time_sec,
vk::singleton<ServerStats>::get().add_request_stats(script_time, net_time, script_max_running_interval, script_init_time_sec, connection_process_time_sec,
queries_cnt, long_queries_cnt, script_mem_stats, vk::singleton<CurlMemoryUsage>::get().total_allocated, script_rusage, error_type);
if (save_state == run_state_t::error) {
assert (error_message != nullptr);
Expand Down
1 change: 1 addition & 0 deletions server/php-runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class PhpScript {
double net_time{0};
double script_time{0};
double last_net_time_delta{0};
double script_max_running_interval{0};
int queries_cnt{0};
int long_queries_cnt{0};

Expand Down
5 changes: 3 additions & 2 deletions server/server-stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,12 @@ void ServerStats::after_fork(pid_t worker_pid, uint64_t active_connections, uint
last_update_aggr_stats = std::chrono::steady_clock::now();
}

void ServerStats::add_request_stats(double script_time_sec, double net_time_sec, double script_init_time_sec, double connection_process_time_sec,
void ServerStats::add_request_stats(double script_time_sec, double net_time_sec, double script_max_running_interval_sec, double script_init_time_sec, double connection_process_time_sec,
int64_t script_queries, int64_t long_script_queries, const memory_resource::MemoryStats &script_memory_stats, int64_t curl_total_allocated, process_rusage_t script_rusage, script_error_t error) noexcept {
auto &stats = worker_type_ == WorkerType::job_worker ? shared_stats_->job_workers : shared_stats_->general_workers;
const auto script_time = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(script_time_sec));
const auto net_time = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(net_time_sec));
const auto script_max_running_interval = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(script_max_running_interval_sec));
const auto script_init_time = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(script_init_time_sec));
const auto http_connection_process_time = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(connection_process_time_sec));
const auto script_user_time = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::duration<double>(script_rusage.user_time));
Expand All @@ -656,7 +657,7 @@ void ServerStats::add_request_stats(double script_time_sec, double net_time_sec,
stats.add_request_stats(queries_stat, error, script_memory_stats, curl_total_allocated);
shared_stats_->workers.add_worker_stats(queries_stat, worker_process_id_);

StatsHouseManager::get().add_request_stats(script_time.count(), net_time.count(), error, script_memory_stats, script_queries, long_script_queries,
StatsHouseManager::get().add_request_stats(script_time.count(), net_time.count(), script_max_running_interval.count(), error, script_memory_stats, script_queries, long_script_queries,
script_user_time.count(), script_system_time.count(),
script_init_time.count(), http_connection_process_time.count(),
script_rusage.voluntary_context_switches, script_rusage.involuntary_context_switches);
Expand Down
2 changes: 1 addition & 1 deletion server/server-stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ServerStats : vk::not_copyable {
public:
void init() noexcept;

void add_request_stats(double script_time_sec, double net_time_sec, double script_init_time_sec, double connection_process_time_sec,
void add_request_stats(double script_time_sec, double net_time_sec, double script_max_running_interval_sec, double script_init_time_sec, double connection_process_time_sec,
int64_t script_queries, int64_t long_script_queries,
const memory_resource::MemoryStats &script_memory_stats, int64_t curl_total_allocated,
process_rusage_t script_rusage, script_error_t error) noexcept;
Expand Down
3 changes: 2 additions & 1 deletion server/statshouse/statshouse-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void StatsHouseManager::generic_cron_check_if_tag_host_needed() {
}
}

void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, script_error_t error,
void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, uint64_t script_max_running_interval_ns, script_error_t error,
const memory_resource::MemoryStats &script_memory_stats, uint64_t script_queries, uint64_t long_script_queries,
uint64_t script_user_time_ns, uint64_t script_system_time_ns,
uint64_t script_init_time, uint64_t http_connection_process_time,
Expand All @@ -110,6 +110,7 @@ void StatsHouseManager::add_request_stats(uint64_t script_time_ns, uint64_t net_

client.metric("kphp_request_time").tag("script").tag(worker_type).tag(status).write_value(script_time_ns);
client.metric("kphp_request_time").tag("net").tag(worker_type).tag(status).write_value(net_time_ns);
client.metric("kphp_request_script_time_max_running_interval").tag(worker_type).tag(status).write_value(script_max_running_interval_ns);
client.metric("kphp_request_cpu_time").tag("user").tag(worker_type).tag(status).write_value(script_user_time_ns);
client.metric("kphp_request_cpu_time").tag("system").tag(worker_type).tag(status).write_value(script_system_time_ns);
client.metric("kphp_request_init_time").tag(worker_type).tag(status).write_value(script_init_time);
Expand Down
2 changes: 1 addition & 1 deletion server/statshouse/statshouse-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class StatsHouseManager : vk::not_copyable {
return this->instance_cache_key_normalization_function != nullptr;
}

void add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, script_error_t error, const memory_resource::MemoryStats &script_memory_stats,
void add_request_stats(uint64_t script_time_ns, uint64_t net_time_ns, uint64_t script_max_running_interval_ns, script_error_t error, const memory_resource::MemoryStats &script_memory_stats,
uint64_t script_queries, uint64_t long_script_queries,
uint64_t script_user_time_ns, uint64_t script_system_time_ns,
uint64_t script_init_time, uint64_t http_connection_process_time,
Expand Down

0 comments on commit 02d3786

Please sign in to comment.