Skip to content

feat(native): Add counter to track http client connection reuse#26822

Merged
kewang1024 merged 1 commit intoprestodb:masterfrom
kewang1024:http-client-reuse
Jan 12, 2026
Merged

feat(native): Add counter to track http client connection reuse#26822
kewang1024 merged 1 commit intoprestodb:masterfrom
kewang1024:http-client-reuse

Conversation

@kewang1024
Copy link
Copy Markdown
Collaborator

== NO RELEASE NOTE ==

@kewang1024 kewang1024 requested review from a team as code owners December 17, 2025 21:00
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Dec 17, 2025
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Dec 17, 2025

Reviewer's Guide

Adds HTTP client metrics to distinguish first-use versus reused connections using transaction sequence numbers, and registers the corresponding counters in the metrics system.

Sequence diagram for HTTP client connection reuse metrics

sequenceDiagram
    participant Client
    participant HttpClient
    participant HTTPTransaction
    participant ResponseHandler
    participant MetricsSystem

    Client->>HttpClient: sendRequest()
    HttpClient->>HTTPTransaction: createOrReuseTransaction()
    HTTPTransaction->>ResponseHandler: setTransaction(this)
    ResponseHandler->>HTTPTransaction: getSequenceNumber()
    HTTPTransaction-->>ResponseHandler: seqNo

    alt seqNo == 0 (first use)
        ResponseHandler->>MetricsSystem: RECORD_METRIC_VALUE(kCounterHttpClientConnectionFirstUse)
    else seqNo > 0 (reused connection)
        ResponseHandler->>MetricsSystem: RECORD_METRIC_VALUE(kCounterHttpClientConnectionReuse)
    end

    ResponseHandler-->>HTTPTransaction: transactionHandlerReady()
    HTTPTransaction-->>HttpClient: transactionReady()
    HttpClient-->>Client: responseProcessed
Loading

Flow diagram for HTTP client connection reuse counters definition and usage

flowchart TD
    A[Headers in Counters_h<br/>kCounterHttpClientConnectionFirstUse<br/>kCounterHttpClientConnectionReuse] --> B[Metrics registration in Counters_cpp<br/>registerPrestoMetrics<br/>DEFINE_METRIC for both counters]
    B --> C[Metrics system<br/>stores SUM counters]
    C --> D[HttpClient ResponseHandler_setTransaction<br/>txn_.getSequenceNumber]
    D -->|seqNo == 0| E[RECORD_METRIC_VALUE<br/>kCounterHttpClientConnectionFirstUse]
    D -->|seqNo > 0| F[RECORD_METRIC_VALUE<br/>kCounterHttpClientConnectionReuse]
Loading

File-Level Changes

Change Details Files
Instrument HttpClient to count first-use vs reused connections based on transaction sequence number.
  • In ResponseHandler::setTransaction, fetch the HTTPTransaction sequence number when the transaction is set.
  • Record kCounterHttpClientConnectionReuse when sequence number is greater than zero and log a VLOG(2) message indicating reuse.
  • Record kCounterHttpClientConnectionFirstUse when sequence number is zero, representing the first request on a connection.
  • Document how sequence number maps to connection reuse semantics in comments.
presto-native-execution/presto_cpp/main/http/HttpClient.cpp
Define and register new counters for HTTP client connection first use and reuse.
  • Add two new counter names for HTTP client connection_first_use and connection_reuse in Counters.h with brief documentation comments.
  • Register the new counters in registerPrestoMetrics using DEFINE_METRIC with StatType::SUM so they are exposed to the metrics subsystem alongside existing HTTP client metrics.
presto-native-execution/presto_cpp/main/common/Counters.h
presto-native-execution/presto_cpp/main/common/Counters.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kewang1024 kewang1024 force-pushed the http-client-reuse branch 2 times, most recently from 20887f0 to 924a77e Compare December 18, 2025 20:17
@kewang1024 kewang1024 merged commit 0dfdb99 into prestodb:master Jan 12, 2026
86 of 88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:Meta PR from Meta

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants