Skip to content

Commit

Permalink
Add metrics about memory usage for cop task (#1152) (#1177)
Browse files Browse the repository at this point in the history
* add cop memory usage metrics

* add grafana

Co-authored-by: xufei <[email protected]>
  • Loading branch information
ti-srebot and windtalker authored Oct 23, 2020
1 parent 0a8f670 commit 3c4d454
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dbms/src/Common/TiFlashMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ namespace DB
M(tiflash_coprocessor_request_duration_seconds, "Bucketed histogram of request duration", Histogram, \
F(type_batch, {{"type", "batch"}}, ExpBuckets{0.0005, 2, 20}), F(type_cop, {{"type", "cop"}}, ExpBuckets{0.0005, 2, 20}), \
F(type_super_batch, {{"type", "super_batch"}}, ExpBuckets{0.0005, 2, 20})) \
M(tiflash_coprocessor_request_memory_usage, "Bucketed histogram of request memory usage", Histogram, \
F(type_cop, {{"type", "cop"}}, ExpBuckets{1024 * 1024, 2, 16}), \
F(type_super_batch, {{"type", "super_batch"}}, ExpBuckets{1024 * 1024, 2, 16})) \
M(tiflash_coprocessor_request_error, "Total number of request error", Counter, F(reason_meet_lock, {"reason", "meet_lock"}), \
F(reason_region_not_found, {"reason", "region_not_found"}), F(reason_epoch_not_match, {"reason", "epoch_not_match"}), \
F(reason_kv_client_error, {"reason", "kv_client_error"}), F(reason_internal_error, {"reason", "internal_error"}), \
Expand Down
13 changes: 13 additions & 0 deletions dbms/src/Flash/Coprocessor/DAGDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <Common/TiFlashMetrics.h>
#include <Core/QueryProcessingStage.h>
#include <DataStreams/BlockIO.h>
#include <DataStreams/IProfilingBlockInputStream.h>
Expand All @@ -9,6 +10,7 @@
#include <Flash/Coprocessor/StreamingDAGResponseWriter.h>
#include <Flash/Coprocessor/UnaryDAGResponseWriter.h>
#include <Interpreters/Context.h>
#include <Interpreters/ProcessList.h>
#include <Interpreters/executeQuery.h>
#include <Storages/Transaction/KVStore.h>
#include <Storages/Transaction/LockException.h>
Expand Down Expand Up @@ -94,6 +96,17 @@ try
copyData(*streams.in, *dag_output_stream);
}

auto process_info = context.getProcessListElement()->getInfo();
auto peak_memory = process_info.peak_memory_usage > 0 ? process_info.peak_memory_usage : 0;
if constexpr (!batch)
{
GET_METRIC(context.getTiFlashMetrics(), tiflash_coprocessor_request_memory_usage, type_cop).Observe(peak_memory);
}
else
{
GET_METRIC(context.getTiFlashMetrics(), tiflash_coprocessor_request_memory_usage, type_super_batch).Observe(peak_memory);
}

if (auto * p_stream = dynamic_cast<IProfilingBlockInputStream *>(streams.in.get()))
{
LOG_DEBUG(log,
Expand Down
106 changes: 106 additions & 0 deletions metrics/grafana/tiflash_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,112 @@
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_TEST-CLUSTER}",
"fill": 1,
"gridPos": {
"h": 7,
"w": 12,
"x": 0,
"y": 23
},
"id": 63,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null as zero",
"percentage": false,
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "histogram_quantile(0.999, sum(rate(tiflash_coprocessor_request_memory_usage_bucket{instance=~\"$instance\"}[1m])) by (le, type))",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "999-{{type}}",
"refId": "A"
},
{
"expr": "histogram_quantile(0.99, sum(rate(tiflash_coprocessor_request_memory_usage_bucket{instance=~\"$instance\"}[1m])) by (le, type))",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "99-{{type}}",
"refId": "B"
},
{
"expr": "histogram_quantile(0.95, sum(rate(tiflash_coprocessor_request_memory_usage_bucket{instance=~\"$instance\"}[1m])) by (le, type))",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "95-{{type}}",
"refId": "C"
},
{
"expr": "histogram_quantile(0.80, sum(rate(tiflash_coprocessor_request_memory_usage_bucket{instance=~\"$instance\"}[1m])) by (le, type))",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "80-{{type}}",
"refId": "D"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Cop task memory usage",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": "0",
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"repeat": null,
Expand Down

0 comments on commit 3c4d454

Please sign in to comment.