Skip to content

Commit

Permalink
Storages: Add Block pop-up latency metrics (#9260) (#9419)
Browse files Browse the repository at this point in the history
ref #9417

Signed-off-by: ti-chi-bot <[email protected]>

Co-authored-by: jinhelin <[email protected]>
  • Loading branch information
ti-chi-bot and JinheLin authored Sep 20, 2024
1 parent 5489b48 commit 7d8b38d
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 5 deletions.
6 changes: 5 additions & 1 deletion dbms/src/Common/TiFlashMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,11 @@ namespace DB
F(type_fg_read, {"type", "fg_read"}), \
F(type_bg_read, {"type", "bg_read"}), \
F(type_fg_write, {"type", "fg_write"}), \
F(type_bg_write, {"type", "bg_write"}))
F(type_bg_write, {"type", "bg_write"})) \
M(tiflash_read_thread_internal_us, \
"Durations of read thread internal components", \
Histogram, \
F(type_block_queue_pop_latency, {{"type", "block_queue_pop_latency"}}, ExpBuckets{1, 2, 20}))


/// Buckets with boundaries [start * base^0, start * base^1, ..., start * base^(size-1)]
Expand Down
22 changes: 18 additions & 4 deletions dbms/src/Storages/DeltaMerge/ReadThread/WorkQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.
#pragma once

#include <Common/TiFlashMetrics.h>
#include <stdint.h>

#include <cassert>
Expand All @@ -30,7 +31,8 @@ class WorkQueue
std::condition_variable reader_cv;
std::condition_variable writer_cv;
std::condition_variable finish_cv;
std::queue<T> queue;
// <value, push_timestamp_ns>
std::queue<std::pair<T, UInt64>> queue;
bool done;
std::size_t max_size;

Expand All @@ -47,6 +49,12 @@ class WorkQueue
return queue.size() >= max_size;
}

static void reportPopLatency(UInt64 push_timestamp_ns)
{
auto latency_ns = clock_gettime_ns_adjusted(push_timestamp_ns) - push_timestamp_ns;
GET_METRIC(tiflash_read_thread_internal_us, type_block_queue_pop_latency).Observe(latency_ns / 1000.0);
}

public:
/**
* Constructs an empty work queue with an optional max size.
Expand Down Expand Up @@ -83,7 +91,7 @@ class WorkQueue
{
return false;
}
queue.push(std::forward<U>(item));
queue.push(std::make_pair(std::forward<U>(item), clock_gettime_ns()));
peak_queue_size = std::max(queue.size(), peak_queue_size);
if (size != nullptr)
{
Expand All @@ -104,6 +112,7 @@ class WorkQueue
*/
bool pop(T & item)
{
UInt64 push_timestamp_ns = 0;
{
std::unique_lock<std::mutex> lock(mu);
++pop_times;
Expand All @@ -117,10 +126,12 @@ class WorkQueue
assert(done);
return false;
}
item = std::move(queue.front());
item = std::move(queue.front().first);
push_timestamp_ns = queue.front().second;
queue.pop();
}
writer_cv.notify_one();
reportPopLatency(push_timestamp_ns);
return true;
}

Expand All @@ -135,6 +146,7 @@ class WorkQueue
*/
bool tryPop(T & item)
{
UInt64 push_timestamp_ns = 0;
{
std::unique_lock<std::mutex> lock(mu);
++pop_times;
Expand All @@ -150,10 +162,12 @@ class WorkQueue
return false;
}
}
item = std::move(queue.front());
item = std::move(queue.front().first);
push_timestamp_ns = queue.front().second;
queue.pop();
}
writer_cv.notify_one();
reportPopLatency(push_timestamp_ns);
return true;
}

Expand Down
128 changes: 128 additions & 0 deletions metrics/grafana/tiflash_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -8783,6 +8783,134 @@
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_TEST-CLUSTER}",
"fieldConfig": {
"defaults": {},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 165
},
"hiddenSeries": false,
"id": 292,
"legend": {
"alignAsTable": false,
"avg": true,
"current": false,
"max": false,
"min": false,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null as zero",
"options": {
"alertThreshold": true
},
"percentage": false,
"pluginVersion": "7.5.17",
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"exemplar": true,
"expr": "histogram_quantile(0.999, sum(rate(tiflash_read_thread_internal_us_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (le, type))",
"format": "time_series",
"interval": "",
"intervalFactor": 1,
"legendFormat": "999-{{type}}",
"refId": "A"
},
{
"exemplar": true,
"expr": "histogram_quantile(0.99, sum(rate(tiflash_read_thread_internal_us_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (le, type))",
"format": "time_series",
"interval": "",
"intervalFactor": 1,
"legendFormat": "99-{{type}}",
"refId": "B"
},
{
"exemplar": true,
"expr": "histogram_quantile(0.95, sum(rate(tiflash_read_thread_internal_us_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (le, type))",
"format": "time_series",
"interval": "",
"intervalFactor": 1,
"legendFormat": "95-{{type}}",
"refId": "C"
},
{
"exemplar": true,
"expr": "histogram_quantile(0.80, sum(rate(tiflash_read_thread_internal_us_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (le, type))",
"format": "time_series",
"interval": "",
"intervalFactor": 1,
"legendFormat": "80-{{type}}",
"refId": "D"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Read Thread Internal Duration",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:222",
"format": "µs",
"label": null,
"logBase": 1,
"max": null,
"min": "0",
"show": true
},
{
"$$hashKey": "object:223",
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
Expand Down

0 comments on commit 7d8b38d

Please sign in to comment.