Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ SystemConfig::SystemConfig() {
NUM_PROP(kHttpClientHttp2InitialStreamWindow, 1 << 23 /*8MB*/),
NUM_PROP(kHttpClientHttp2StreamWindow, 1 << 23 /*8MB*/),
NUM_PROP(kHttpClientHttp2SessionWindow, 1 << 26 /*64MB*/),
BOOL_PROP(kHttpClientConnectionReuseCounterEnabled, true),
STR_PROP(kExchangeMaxErrorDuration, "3m"),
STR_PROP(kExchangeRequestTimeout, "20s"),
STR_PROP(kExchangeConnectTimeout, "20s"),
Expand Down Expand Up @@ -952,6 +953,11 @@ uint32_t SystemConfig::httpClientHttp2SessionWindow() const {
return optionalProperty<uint32_t>(kHttpClientHttp2SessionWindow).value();
}

bool SystemConfig::httpClientConnectionReuseCounterEnabled() const {
return optionalProperty<bool>(kHttpClientConnectionReuseCounterEnabled)
.value();
}

std::chrono::duration<double> SystemConfig::exchangeMaxErrorDuration() const {
return velox::config::toDuration(
optionalProperty(kExchangeMaxErrorDuration).value());
Expand Down
7 changes: 7 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,11 @@ class SystemConfig : public ConfigBase {
static constexpr std::string_view kHttpClientHttp2SessionWindow{
"http-client.http2.session-window"};

/// Whether to enable HTTP client connection reuse counter reporting.
/// When enabled, tracks connection first use and reuse metrics.
static constexpr std::string_view kHttpClientConnectionReuseCounterEnabled{
"http-client.connection-reuse-counter-enabled"};

static constexpr std::string_view kExchangeMaxErrorDuration{
"exchange.max-error-duration"};

Expand Down Expand Up @@ -1153,6 +1158,8 @@ class SystemConfig : public ConfigBase {

uint32_t httpClientHttp2SessionWindow() const;

bool httpClientConnectionReuseCounterEnabled() const;

std::chrono::duration<double> exchangeMaxErrorDuration() const;

std::chrono::duration<double> exchangeRequestTimeoutMs() const;
Expand Down
4 changes: 4 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Counters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ void registerPrestoMetrics() {
100);
DEFINE_METRIC(
kCounterHttpClientNumConnectionsCreated, facebook::velox::StatType::SUM);
DEFINE_METRIC(
kCounterHttpClientConnectionFirstUse, facebook::velox::StatType::SUM);
DEFINE_METRIC(
kCounterHttpClientConnectionReuse, facebook::velox::StatType::SUM);
// Tracks http client transaction create delay in range of [0, 30s] with
// 30 buckets and reports P50, P90, P99, and P100.
DEFINE_HISTOGRAM_METRIC(
Expand Down
7 changes: 7 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ constexpr std::string_view kCounterHTTPRequestSizeBytes{

constexpr std::string_view kCounterHttpClientNumConnectionsCreated{
"presto_cpp.http.client.num_connections_created"};
/// Number of HTTP requests that are the first request on a connection
// (seqNo == 0).
constexpr std::string_view kCounterHttpClientConnectionFirstUse{
"presto_cpp.http.client.connection_first_use"};
/// Number of HTTP requests sent on reused connections (seqNo > 0).
constexpr std::string_view kCounterHttpClientConnectionReuse{
"presto_cpp.http.client.connection_reuse"};
constexpr std::string_view kCounterHTTPClientTransactionCreateDelay{
"presto_cpp.http.client.transaction_create_delay_ms"};
/// Peak number of bytes queued in PrestoExchangeSource waiting for consume.
Expand Down
13 changes: 13 additions & 0 deletions presto-native-execution/presto_cpp/main/http/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ class ResponseHandler : public proxygen::HTTPTransactionHandler {
void setTransaction(proxygen::HTTPTransaction* txn) noexcept override {
txn_ = CHECK_NOTNULL(txn);
protocol_ = txn_->getTransport().getCodec().getProtocol();
// Track connection usage via sequence number:
// - seqNo == 0: First request on this connection
// - seqNo > 0: Connection is being reused for subsequent requests
// Reuse rate = connection_reuse / (connection_first_use + connection_reuse)
if (SystemConfig::instance()->httpClientConnectionReuseCounterEnabled()) {
const uint32_t seqNo = txn_->getSequenceNumber();
if (seqNo > 0) {
RECORD_METRIC_VALUE(kCounterHttpClientConnectionReuse);
VLOG(2) << "HttpClient reusing connection, seqNo=" << seqNo;
} else {
RECORD_METRIC_VALUE(kCounterHttpClientConnectionFirstUse);
}
}
}

void detachTransaction() noexcept override {
Expand Down
Loading