diff --git a/presto-native-execution/presto_cpp/main/common/Configs.cpp b/presto-native-execution/presto_cpp/main/common/Configs.cpp index ec9a9afcde08a..89f14085da3e2 100644 --- a/presto-native-execution/presto_cpp/main/common/Configs.cpp +++ b/presto-native-execution/presto_cpp/main/common/Configs.cpp @@ -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"), @@ -952,6 +953,11 @@ uint32_t SystemConfig::httpClientHttp2SessionWindow() const { return optionalProperty(kHttpClientHttp2SessionWindow).value(); } +bool SystemConfig::httpClientConnectionReuseCounterEnabled() const { + return optionalProperty(kHttpClientConnectionReuseCounterEnabled) + .value(); +} + std::chrono::duration SystemConfig::exchangeMaxErrorDuration() const { return velox::config::toDuration( optionalProperty(kExchangeMaxErrorDuration).value()); diff --git a/presto-native-execution/presto_cpp/main/common/Configs.h b/presto-native-execution/presto_cpp/main/common/Configs.h index 478e01bfbba28..2c44c3e845427 100644 --- a/presto-native-execution/presto_cpp/main/common/Configs.h +++ b/presto-native-execution/presto_cpp/main/common/Configs.h @@ -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"}; @@ -1153,6 +1158,8 @@ class SystemConfig : public ConfigBase { uint32_t httpClientHttp2SessionWindow() const; + bool httpClientConnectionReuseCounterEnabled() const; + std::chrono::duration exchangeMaxErrorDuration() const; std::chrono::duration exchangeRequestTimeoutMs() const; diff --git a/presto-native-execution/presto_cpp/main/common/Counters.cpp b/presto-native-execution/presto_cpp/main/common/Counters.cpp index 3e84df2eb20e2..da56b7c9df91c 100644 --- a/presto-native-execution/presto_cpp/main/common/Counters.cpp +++ b/presto-native-execution/presto_cpp/main/common/Counters.cpp @@ -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( diff --git a/presto-native-execution/presto_cpp/main/common/Counters.h b/presto-native-execution/presto_cpp/main/common/Counters.h index ca90a72bd03d1..52ecc1356e06b 100644 --- a/presto-native-execution/presto_cpp/main/common/Counters.h +++ b/presto-native-execution/presto_cpp/main/common/Counters.h @@ -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. diff --git a/presto-native-execution/presto_cpp/main/http/HttpClient.cpp b/presto-native-execution/presto_cpp/main/http/HttpClient.cpp index 708dbbbc3598e..0b5c559803a8f 100644 --- a/presto-native-execution/presto_cpp/main/http/HttpClient.cpp +++ b/presto-native-execution/presto_cpp/main/http/HttpClient.cpp @@ -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 {