Skip to content

Commit d4fab30

Browse files
authored
Add cancellation into response statistics (#329)
* Add cancellation into response statistics * Update backend API version * Revert "Update backend API version" This reverts commit 86ea0dd.
1 parent 854bdcb commit d4fab30

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/backend_model_instance.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,10 @@ TRITONBACKEND_ModelInstanceReportResponseStatistics(
11031103
RETURN_TRITONSERVER_ERROR_IF_ERROR(
11041104
sa->UpdateResponseEmpty(key, rs->response_start, rs->response_end));
11051105
}
1106+
} else if (
1107+
TRITONSERVER_ErrorCode(rs->error) == TRITONSERVER_ERROR_CANCELLED) {
1108+
RETURN_TRITONSERVER_ERROR_IF_ERROR(
1109+
sa->UpdateResponseCancel(key, rs->response_start, rs->response_end));
11061110
} else {
11071111
RETURN_TRITONSERVER_ERROR_IF_ERROR(sa->UpdateResponseFail(
11081112
key, rs->response_start, rs->compute_output_start, rs->response_end));

src/infer_stats.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,33 @@ InferenceStatsAggregator::UpdateResponseEmpty(
336336
return Status::Success;
337337
}
338338

339+
Status
340+
InferenceStatsAggregator::UpdateResponseCancel(
341+
const std::string& key, const uint64_t response_start_ns,
342+
const uint64_t response_end_ns)
343+
{
344+
if (response_start_ns > response_end_ns) {
345+
return Status(
346+
Status::Code::INVALID_ARG,
347+
"Response start cannot happen after response end");
348+
}
349+
const uint64_t total_duration_ns = response_end_ns - response_start_ns;
350+
351+
{
352+
std::lock_guard<std::mutex> lock(mu_);
353+
354+
auto it = response_stats_.find(key);
355+
if (it == response_stats_.end()) {
356+
it = response_stats_.emplace(key, InferResponseStats()).first;
357+
}
358+
359+
it->second.cancel_count++;
360+
it->second.cancel_duration_ns += total_duration_ns;
361+
}
362+
363+
return Status::Success;
364+
}
365+
339366
void
340367
InferenceStatsAggregator::UpdateInferBatchStats(
341368
MetricModelReporter* metric_reporter, const size_t batch_size,

src/infer_stats.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class InferenceStatsAggregator {
8484
compute_output_count(0), compute_output_duration_ns(0),
8585
success_count(0), success_duration_ns(0), fail_count(0),
8686
fail_duration_ns(0), empty_response_count(0),
87-
empty_response_duration_ns(0)
87+
empty_response_duration_ns(0), cancel_count(0), cancel_duration_ns(0)
8888
{
8989
}
9090
uint64_t compute_infer_count;
@@ -97,6 +97,8 @@ class InferenceStatsAggregator {
9797
uint64_t fail_duration_ns;
9898
uint64_t empty_response_count;
9999
uint64_t empty_response_duration_ns;
100+
uint64_t cancel_count;
101+
uint64_t cancel_duration_ns;
100102
};
101103

102104
struct InferBatchStats {
@@ -181,6 +183,11 @@ class InferenceStatsAggregator {
181183
const std::string& key, const uint64_t response_start_ns,
182184
const uint64_t response_end_ns);
183185

186+
// Add durations to response stats for a cancellation response.
187+
Status UpdateResponseCancel(
188+
const std::string& key, const uint64_t response_start_ns,
189+
const uint64_t response_end_ns);
190+
184191
// Add durations to batch infer stats for a batch execution.
185192
// 'success_request_count' is the number of success requests in the
186193
// batch that have infer_stats attached.

src/tritonserver.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,9 @@ TRITONSERVER_ServerModelStatistics(
29592959
metadata, res_stat, "empty_response",
29602960
res_pair.second.empty_response_count,
29612961
res_pair.second.empty_response_duration_ns);
2962+
SetDurationStat(
2963+
metadata, res_stat, "cancel", res_pair.second.cancel_count,
2964+
res_pair.second.cancel_duration_ns);
29622965
RETURN_IF_STATUS_ERROR(
29632966
response_stats.Add(res_pair.first.c_str(), std::move(res_stat)));
29642967
}

0 commit comments

Comments
 (0)