Skip to content

Commit

Permalink
fix: remove instantaneous_metric and collect network metrics every 5 …
Browse files Browse the repository at this point in the history
…seconds (OpenAtomFoundation#1757)

Remove the instantaneous_metric thread and use DoTimingTask() to collect network traffic every 5 seconds.

Fixes: OpenAtomFoundation#1756

Signed-off-by: yaoyinnan <[email protected]>
  • Loading branch information
yaoyinnan authored Jul 19, 2023
1 parent ce7d807 commit 236ae84
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class PikaServer : public pstd::noncopyable {
void AutoPurge();
void AutoDeleteExpiredDump();
void AutoKeepAliveRSync();
void AutoInstantaneousMetric();
void AutoUpdateNetworkMetric();

std::string host_;
int port_ = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/pika_instant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ double Instant::getInstantaneousMetric(std::string metric) {
return sum / STATS_METRIC_SAMPLES;
}

/* ======================= Cron: called every 100 ms ======================== */
/* ======================= Cron: called every 5 s ======================== */

/* Add a sample to the instantaneous metric. This function computes the quotient
* of the increment of value and base, which is useful to record operation count
Expand Down
14 changes: 4 additions & 10 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,6 @@ void PikaServer::Start() {
}
LOG(INFO) << "Pika Server going to start";

// Auto update instantaneous metric
std::thread instantaneous_metric([&]() {
while (!exit_) {
AutoInstantaneousMetric();
// wake up every 100 milliseconds
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
});

while (!exit_) {
DoTimingTask();
Expand Down Expand Up @@ -1313,6 +1305,8 @@ void PikaServer::DoTimingTask() {
AutoKeepAliveRSync();
// Reset server qps
ResetLastSecQuerynum();
// Auto update network instantaneous metric
AutoUpdateNetworkMetric();
}

void PikaServer::AutoCompactRange() {
Expand Down Expand Up @@ -1493,9 +1487,9 @@ void PikaServer::AutoKeepAliveRSync() {
}
}

void PikaServer::AutoInstantaneousMetric() {
void PikaServer::AutoUpdateNetworkMetric() {
monotime current_time = getMonotonicUs();
size_t factor = 1000000; // us
size_t factor = 5e6; // us, 5s
instant_->trackInstantaneousMetric(STATS_METRIC_NET_INPUT, g_pika_server->NetInputBytes() + g_pika_server->NetReplInputBytes(),
current_time, factor);
instant_->trackInstantaneousMetric(STATS_METRIC_NET_OUTPUT, g_pika_server->NetOutputBytes() + g_pika_server->NetReplOutputBytes(),
Expand Down
8 changes: 4 additions & 4 deletions tools/pika_exporter/exporter/metrics/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var collectStatsMetrics = map[string]MetricConfig{
Parser: &normalParser{},
MetricMeta: &MetaData{
Name: "instantaneous_input_kbps",
Help: "the network's read rate per second in KB/sec",
Help: "the network's read rate per second in KB/sec, calculated as an average of 16 samples collected every 5 seconds.",
Type: metricTypeCounter,
Labels: []string{LabelNameAddr, LabelNameAlias},
ValueName: "instantaneous_input_kbps",
Expand All @@ -91,7 +91,7 @@ var collectStatsMetrics = map[string]MetricConfig{
Parser: &normalParser{},
MetricMeta: &MetaData{
Name: "instantaneous_output_kbps",
Help: "the network's write rate per second in KB/sec",
Help: "the network's write rate per second in KB/sec, calculated as an average of 16 samples collected every 5 seconds.",
Type: metricTypeCounter,
Labels: []string{LabelNameAddr, LabelNameAlias},
ValueName: "instantaneous_output_kbps",
Expand All @@ -101,7 +101,7 @@ var collectStatsMetrics = map[string]MetricConfig{
Parser: &normalParser{},
MetricMeta: &MetaData{
Name: "instantaneous_input_repl_kbps",
Help: "the network's read rate per second in KB/sec for replication purposes",
Help: "the network's read rate per second in KB/sec for replication purposes, calculated as an average of 16 samples collected every 5 seconds.",
Type: metricTypeCounter,
Labels: []string{LabelNameAddr, LabelNameAlias},
ValueName: "instantaneous_input_repl_kbps",
Expand All @@ -111,7 +111,7 @@ var collectStatsMetrics = map[string]MetricConfig{
Parser: &normalParser{},
MetricMeta: &MetaData{
Name: "instantaneous_output_repl_kbps",
Help: "the network's write rate per second in KB/sec for replication purposes",
Help: "the network's write rate per second in KB/sec for replication purposes, calculated as an average of 16 samples collected every 5 seconds.",
Type: metricTypeCounter,
Labels: []string{LabelNameAddr, LabelNameAlias},
ValueName: "instantaneous_output_repl_kbps",
Expand Down

0 comments on commit 236ae84

Please sign in to comment.