Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Move metrics enabled check in the disk_log_consumer and log_serialize…
Browse files Browse the repository at this point in the history
…r loops so that each loop iteration doesn't count as a sample. (#1534)
  • Loading branch information
mbutrovich authored Apr 27, 2021
1 parent 723df9b commit 97eb7ec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
30 changes: 20 additions & 10 deletions src/storage/write_ahead_log/disk_log_consumer_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ void DiskLogConsumerTask::DiskLogConsumerTaskLoop() {
const std::chrono::microseconds max_sleep = std::chrono::microseconds(10000);
// Time since last log file persist
auto last_persist = std::chrono::high_resolution_clock::now();

// Initialize whether to collect metrics outside of the spin loop so as not to count each loop iteration as a sample
// (by calling ComponentToRecord this increments the sample count)
bool logging_metrics_enabled =
common::thread_context.metrics_store_ != nullptr &&
common::thread_context.metrics_store_->ComponentToRecord(metrics::MetricsComponent::LOGGING);

// Disk log consumer task thread spins in this loop. When notified or periodically, we wake up and process serialized
// buffers
do {
const bool logging_metrics_enabled =
common::thread_context.metrics_store_ != nullptr &&
common::thread_context.metrics_store_->ComponentToRecord(metrics::MetricsComponent::LOGGING);

if (logging_metrics_enabled && !common::thread_context.resource_tracker_.IsRunning()) {
// start the operating unit resource tracker
common::thread_context.resource_tracker_.Start();
Expand Down Expand Up @@ -118,13 +121,20 @@ void DiskLogConsumerTask::DiskLogConsumerTaskLoop() {
persist_cv_.notify_all();
}

if (logging_metrics_enabled && num_buffers > 0) {
// Stop the resource tracker for this operating unit
common::thread_context.resource_tracker_.Stop();
auto &resource_metrics = common::thread_context.resource_tracker_.GetMetrics();
common::thread_context.metrics_store_->RecordConsumerData(num_bytes, num_buffers, persist_interval_.count(),
resource_metrics);
if (num_buffers > 0) {
if (common::thread_context.resource_tracker_.IsRunning()) {
// Stop the resource tracker for this operating unit
common::thread_context.resource_tracker_.Stop();
auto &resource_metrics = common::thread_context.resource_tracker_.GetMetrics();
common::thread_context.metrics_store_->RecordConsumerData(num_bytes, num_buffers, persist_interval_.count(),
resource_metrics);
}
num_bytes = num_buffers = 0;
// Update whether to collect metrics only if we did work (starting a new event) so as not to count each loop
// iteration as a sample (by calling ComponentToRecord this increments the sample count)
logging_metrics_enabled =
common::thread_context.metrics_store_ != nullptr &&
common::thread_context.metrics_store_->ComponentToRecord(metrics::MetricsComponent::LOGGING);
}
} while (run_task_);
// Be extra sure we processed everything
Expand Down
28 changes: 18 additions & 10 deletions src/storage/write_ahead_log/log_serializer_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ void LogSerializerTask::LogSerializerTaskLoop() {

uint64_t num_bytes = 0, num_records = 0, num_txns = 0;

// Initialize whether to collect metrics outside of the spin loop so as not to count each loop iteration as a sample
// (by calling ComponentToRecord this increments the sample count)
bool logging_metrics_enabled =
common::thread_context.metrics_store_ != nullptr &&
common::thread_context.metrics_store_->ComponentToRecord(metrics::MetricsComponent::LOGGING);
do {
const bool logging_metrics_enabled =
common::thread_context.metrics_store_ != nullptr &&
common::thread_context.metrics_store_->ComponentToRecord(metrics::MetricsComponent::LOGGING);

if (logging_metrics_enabled && !common::thread_context.resource_tracker_.IsRunning()) {
// start the operating unit resource tracker
common::thread_context.resource_tracker_.Start();
Expand All @@ -48,13 +49,20 @@ void LogSerializerTask::LogSerializerTaskLoop() {
std::tie(num_bytes, num_records, num_txns) = Process();
curr_sleep = std::min(num_records > 0 ? serialization_interval_ : curr_sleep * 2, max_sleep);

if (logging_metrics_enabled && num_records > 0) {
// Stop the resource tracker for this operating unit
common::thread_context.resource_tracker_.Stop();
auto &resource_metrics = common::thread_context.resource_tracker_.GetMetrics();
common::thread_context.metrics_store_->RecordSerializerData(num_bytes, num_records, num_txns,
serialization_interval_.count(), resource_metrics);
if (num_records > 0) {
if (common::thread_context.resource_tracker_.IsRunning()) {
// Stop the resource tracker for this operating unit
common::thread_context.resource_tracker_.Stop();
auto &resource_metrics = common::thread_context.resource_tracker_.GetMetrics();
common::thread_context.metrics_store_->RecordSerializerData(num_bytes, num_records, num_txns,
serialization_interval_.count(), resource_metrics);
}
num_bytes = num_records = num_txns = 0;
// Update whether to collect metrics only if we did work (starting a new event) so as not to count each loop
// iteration as a sample (by calling ComponentToRecord this increments the sample count)
logging_metrics_enabled =
common::thread_context.metrics_store_ != nullptr &&
common::thread_context.metrics_store_->ComponentToRecord(metrics::MetricsComponent::LOGGING);
}
} while (run_task_);
// To be extra sure we processed everything
Expand Down

0 comments on commit 97eb7ec

Please sign in to comment.