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
11 changes: 11 additions & 0 deletions presto-native-execution/presto_cpp/main/common/Configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ SystemConfig::SystemConfig() {
NUM_PROP(kAnnouncementMaxFrequencyMs, 30'000), // 30s
NUM_PROP(kHeartbeatFrequencyMs, 0),
BOOL_PROP(kHttpClientHttp2Enabled, false),
NUM_PROP(kHttpClientHttp2MaxStreamsPerConnection, 1),
Copy link
Copy Markdown
Contributor

@shangm2 shangm2 Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Do you think it is a good idea to give a more realistic default value in case people forget to update config for some clusters?

Copy link
Copy Markdown
Collaborator Author

@kewang1024 kewang1024 Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is actually a suggestion from proxygen folks, to start with on-par performance with http1.1

Right now I'm doing benchmarking so that later we can figure out a recommended value

NUM_PROP(kHttpClientHttp2FlowControlWindow, 1 << 24 /*16MB*/),
Comment on lines 236 to +238
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Default values for HTTP/2 settings may be overly restrictive for production use.

A max streams per connection value of 1 may significantly reduce HTTP/2 throughput. Please consider a higher default or add documentation to help users tune this setting for their needs.

Suggested change
BOOL_PROP(kHttpClientHttp2Enabled, false),
NUM_PROP(kHttpClientHttp2MaxStreamsPerConnection, 1),
NUM_PROP(kHttpClientHttp2FlowControlWindow, 1 << 24 /*16MB*/),
BOOL_PROP(kHttpClientHttp2Enabled, false),
// Default is 100 streams per connection. Tune for your workload; higher values improve throughput but may increase resource usage.
NUM_PROP(kHttpClientHttp2MaxStreamsPerConnection, 100),
NUM_PROP(kHttpClientHttp2FlowControlWindow, 1 << 24 /*16MB*/),

STR_PROP(kExchangeMaxErrorDuration, "3m"),
STR_PROP(kExchangeRequestTimeout, "20s"),
STR_PROP(kExchangeConnectTimeout, "20s"),
Expand Down Expand Up @@ -860,6 +862,15 @@ bool SystemConfig::httpClientHttp2Enabled() const {
return optionalProperty<bool>(kHttpClientHttp2Enabled).value();
}

uint32_t SystemConfig::httpClientHttp2MaxStreamsPerConnection() const {
return optionalProperty<uint32_t>(kHttpClientHttp2MaxStreamsPerConnection)
.value();
}

uint32_t SystemConfig::httpClientHttp2FlowControlWindow() const {
return optionalProperty<uint32_t>(kHttpClientHttp2FlowControlWindow).value();
}

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

/// Maximum concurrent streams per HTTP/2 connection
static constexpr std::string_view kHttpClientHttp2MaxStreamsPerConnection{
"http-client.http2.max-streams-per-connection"};

/// HTTP/2 flow control window size in bytes.
/// Controls the initial receive window, stream window, and session window.
static constexpr std::string_view kHttpClientHttp2FlowControlWindow{
"http-client.http2.flow-control-window"};

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

Expand Down Expand Up @@ -1042,6 +1051,10 @@ class SystemConfig : public ConfigBase {

bool httpClientHttp2Enabled() const;

uint32_t httpClientHttp2MaxStreamsPerConnection() const;

uint32_t httpClientHttp2FlowControlWindow() const;

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

std::chrono::duration<double> exchangeRequestTimeoutMs() const;
Expand Down
24 changes: 24 additions & 0 deletions presto-native-execution/presto_cpp/main/http/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ HttpClient::HttpClient(
address_(address),
transactionTimeout_(transactionTimeout),
connectTimeout_(connectTimeout),
http2Enabled_(SystemConfig::instance()->httpClientHttp2Enabled()),
maxConcurrentStreams_(
SystemConfig::instance()->httpClientHttp2MaxStreamsPerConnection()),
http2FlowControlWindow_(
SystemConfig::instance()->httpClientHttp2FlowControlWindow()),
pool_(std::move(pool)),
sslContext_(sslContext),
reportOnBodyStatsFunc_(std::move(reportOnBodyStatsFunc)),
Expand Down Expand Up @@ -303,13 +308,19 @@ class ConnectionHandler : public proxygen::HTTPConnector::Callback {
proxygen::SessionPool* sessionPool,
proxygen::WheelTimerInstance transactionTimeout,
std::chrono::milliseconds connectTimeout,
bool http2Enabled,
uint32_t maxConcurrentStreams,
uint32_t http2FlowControlWindow,
folly::EventBase* eventBase,
const folly::SocketAddress& address,
folly::SSLContextPtr sslContext)
: responseHandler_(responseHandler),
sessionPool_(sessionPool),
transactionTimer_(transactionTimeout),
connectTimeout_(connectTimeout),
http2Enabled_(http2Enabled),
maxConcurrentStreams_(maxConcurrentStreams),
http2FlowControlWindow_(http2FlowControlWindow),
eventBase_(eventBase),
address_(address),
sslContext_(std::move(sslContext)) {}
Expand All @@ -330,6 +341,13 @@ class ConnectionHandler : public proxygen::HTTPConnector::Callback {
}

void connectSuccess(proxygen::HTTPUpstreamSession* session) override {
if (http2Enabled_) {
session->setFlowControl(
http2FlowControlWindow_,
http2FlowControlWindow_,
http2FlowControlWindow_);
session->setMaxConcurrentOutgoingStreams(maxConcurrentStreams_);
}
auto txn = session->newTransaction(responseHandler_.get());
if (txn) {
responseHandler_->sendRequest(txn);
Expand All @@ -352,6 +370,9 @@ class ConnectionHandler : public proxygen::HTTPConnector::Callback {
// The connect timeout used to timeout the duration from starting connection
// to connect success
const std::chrono::milliseconds connectTimeout_;
const bool http2Enabled_;
const uint32_t maxConcurrentStreams_;
const uint32_t http2FlowControlWindow_;
folly::EventBase* const eventBase_;
const folly::SocketAddress address_;
const folly::SSLContextPtr sslContext_;
Expand Down Expand Up @@ -518,6 +539,9 @@ void HttpClient::sendRequest(std::shared_ptr<ResponseHandler> responseHandler) {
sessionPool_,
proxygen::WheelTimerInstance(transactionTimeout_, eventBase_),
connectTimeout_,
http2Enabled_,
maxConcurrentStreams_,
http2FlowControlWindow_,
eventBase_,
address_,
sslContext_);
Expand Down
3 changes: 3 additions & 0 deletions presto-native-execution/presto_cpp/main/http/HttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ class HttpClient : public std::enable_shared_from_this<HttpClient> {
const folly::SocketAddress address_;
const std::chrono::milliseconds transactionTimeout_;
const std::chrono::milliseconds connectTimeout_;
const bool http2Enabled_;
const uint32_t maxConcurrentStreams_;
const uint32_t http2FlowControlWindow_;
const std::shared_ptr<velox::memory::MemoryPool> pool_;
const folly::SSLContextPtr sslContext_;
const std::function<void(int)> reportOnBodyStatsFunc_;
Expand Down
Loading