Skip to content

Commit 1f61957

Browse files
committed
Record http client transaction create delay time
1 parent 1c43927 commit 1f61957

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

presto-native-execution/presto_cpp/main/common/Counters.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ void registerPrestoMetrics() {
3232
DEFINE_METRIC(kCounterHTTPRequestLatencyMs, facebook::velox::StatType::AVG);
3333
DEFINE_METRIC(
3434
kCounterHttpClientNumConnectionsCreated, facebook::velox::StatType::SUM);
35+
// Tracks http client transaction create delay in range of [0, 30s] with
36+
// 30 buckets and reports P50, P90, P99, and P100.
37+
DEFINE_HISTOGRAM_METRIC(
38+
kCounterHTTPClientTransactionCreateDelay,
39+
1'000,
40+
0,
41+
30'000,
42+
50,
43+
90,
44+
99,
45+
100);
3546
DEFINE_METRIC(kCounterNumQueryContexts, facebook::velox::StatType::AVG);
3647
DEFINE_METRIC(kCounterNumTasks, facebook::velox::StatType::AVG);
3748
DEFINE_METRIC(kCounterNumTasksBytesProcessed, facebook::velox::StatType::AVG);

presto-native-execution/presto_cpp/main/common/Counters.h

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ constexpr folly::StringPiece kCounterHTTPRequestLatencyMs{
4141

4242
constexpr folly::StringPiece kCounterHttpClientNumConnectionsCreated{
4343
"presto_cpp.http.client.num_connections_created"};
44+
constexpr folly::StringPiece kCounterHTTPClientTransactionCreateDelay{
45+
"presto_cpp.http.client.transaction_create_delay_ms"};
4446
/// Peak number of bytes queued in PrestoExchangeSource waiting for consume.
4547
constexpr folly::StringPiece kCounterExchangeSourcePeakQueuedBytes{
4648
"presto_cpp.exchange_source_peak_queued_bytes"};

presto-native-execution/presto_cpp/main/http/HttpClient.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
#include <folly/synchronization/Latch.h>
2121
#include <velox/common/base/Exceptions.h>
2222
#include "presto_cpp/main/common/Configs.h"
23+
#include "presto_cpp/main/common/Counters.h"
2324
#include "presto_cpp/main/common/Utils.h"
2425
#include "presto_cpp/main/http/HttpClient.h"
26+
#include "velox/common/base/StatsReporter.h"
2527

2628
namespace facebook::presto::http {
2729

@@ -168,7 +170,8 @@ HttpResponse::nextAllocationSize(uint64_t dataLength) const {
168170
}
169171

170172
std::string HttpResponse::dumpBodyChain() const {
171-
return bodyChain_.empty() ? "Empty response" : util::extractMessageBody(bodyChain_);
173+
return bodyChain_.empty() ? "Empty response"
174+
: util::extractMessageBody(bodyChain_);
172175
}
173176

174177
class ResponseHandler : public proxygen::HTTPTransactionHandler {
@@ -448,7 +451,10 @@ folly::SemiFuture<proxygen::HTTPTransaction*> HttpClient::createTransaction(
448451
}
449452
auto idleSessionFuture = idleSessions_->getIdleSession();
450453
auto getFromIdleSession =
451-
[self = shared_from_this(), this, handler](
454+
[self = shared_from_this(),
455+
this,
456+
handler,
457+
startTimeMs = velox::getCurrentTimeMs()](
452458
proxygen::HTTPSessionBase* session) -> proxygen::HTTPTransaction* {
453459
if (!session) {
454460
return nullptr;
@@ -472,6 +478,9 @@ folly::SemiFuture<proxygen::HTTPTransaction*> HttpClient::createTransaction(
472478
nullptr,
473479
nullptr);
474480
sessionPool_->putSession(session);
481+
RECORD_HISTOGRAM_METRIC_VALUE(
482+
kCounterHTTPClientTransactionCreateDelay,
483+
velox::getCurrentTimeMs() - startTimeMs);
475484
return sessionPool_->getTransaction(handler);
476485
};
477486
if (idleSessionFuture.isReady()) {

0 commit comments

Comments
 (0)