Skip to content

Conversation

@duxiao1212
Copy link
Contributor

@duxiao1212 duxiao1212 commented Nov 25, 2025

Summary: as title

Differential Revision: D87850298

Release Notes

== NO RELEASE NOTE ==

@duxiao1212 duxiao1212 requested review from a team as code owners November 25, 2025 17:23
@prestodb-ci prestodb-ci added the from:Meta PR from Meta label Nov 25, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 25, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the spiller thread pool handling in PrestoServer to separately track a CPU-thread-pool executor pointer for stall monitoring while keeping a generic executor handle, and updates all server initialization and wiring to use the new pointer.

Sequence diagram for PrestoServer spiller CPU pool initialization and wiring

sequenceDiagram
participant PrestoServer
participant SystemConfig
participant SpillerExecutor as folly_CPUThreadPoolExecutor
participant TaskManager

PrestoServer->>SystemConfig: getSpillerNumCpuThreadsHwMultiplier()
SystemConfig-->>PrestoServer: multiplier
PrestoServer->>PrestoServer: compute numSpillerCpuThreads
alt numSpillerCpuThreads > 0
  PrestoServer->>SpillerExecutor: create CPUThreadPoolExecutor(numSpillerCpuThreads, NamedThreadFactory)
  PrestoServer->>PrestoServer: set spillerCpuExecutor_ = SpillerExecutor
  PrestoServer->>PrestoServer: set spillerExecutor_ (std_unique_ptr_folly_Executor)
end

PrestoServer->>TaskManager: create TaskManager(driverCpuExecutor_, httpSrvCpuExecutor_, spillerCpuExecutor_)
TaskManager-->>PrestoServer: TaskManager instance
Loading

Class diagram for updated PrestoServer spiller executors

classDiagram
class PrestoServer {
  - folly_CPUThreadPoolExecutor* driverCpuExecutor_
  - std_unique_ptr_folly_Executor spillerExecutor_
  - folly_CPUThreadPoolExecutor* spillerCpuExecutor_
  + void initializeThreadPools()
  + void run()
  + void createTaskManager()
}

class TaskManager {
  + TaskManager(folly_CPUThreadPoolExecutor* driverCpuExecutor, folly_Executor* httpSrvCpuExecutor, folly_CPUThreadPoolExecutor* spillerCpuExecutor)
}

PrestoServer --> TaskManager : creates
Loading

File-Level Changes

Change Details Files
Separate spiller CPU thread pool pointer from the generic spiller executor and propagate it through server initialization and task manager wiring.
  • Introduce a raw folly::CPUThreadPoolExecutor pointer for the spiller CPU pool alongside a generic std::unique_ptrfolly::Executor for the spiller executor.
  • Adjust spiller thread pool construction to create a CPUThreadPoolExecutor, capture its raw pointer for monitoring, and store it as a generic Executor.
  • Update startup logging and PeriodicTaskManager initialization to use the spiller CPU executor pointer instead of the generic executor.
  • Update TaskManager construction to receive the driver and spiller CPU executor pointers, aligning with stall monitoring expectations.
presto-native-execution/presto_cpp/main/PrestoServer.cpp
presto-native-execution/presto_cpp/main/PrestoServer.h

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
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 - here's some feedback:

  • spillerCpuExecutor_ is never initialized when numSpillerCpuThreads == 0, but is still passed into TaskManager in createTaskManager(), so it should be explicitly initialized to nullptr and guarded wherever it is used.
  • Having both spillerExecutor_ and spillerCpuExecutor_ pointing at the same pool introduces a risk of them getting out of sync; consider simplifying the ownership model (e.g., always using spillerExecutor_.get() where a raw pointer is needed or centralizing the cast) to avoid duplication.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- spillerCpuExecutor_ is never initialized when numSpillerCpuThreads == 0, but is still passed into TaskManager in createTaskManager(), so it should be explicitly initialized to nullptr and guarded wherever it is used.
- Having both spillerExecutor_ and spillerCpuExecutor_ pointing at the same pool introduces a risk of them getting out of sync; consider simplifying the ownership model (e.g., always using spillerExecutor_.get() where a raw pointer is needed or centralizing the cast) to avoid duplication.

## Individual Comments

### Comment 1
<location> `presto-native-execution/presto_cpp/main/PrestoServer.cpp:548-555` </location>
<code_context>
     PRESTO_STARTUP_LOG(INFO)
-        << "Spiller CPU executor '" << spillerExecutor_->getName() << "', has "
-        << spillerExecutor_->numThreads() << " threads.";
+        << "Spiller CPU executor '" << spillerCpuExecutor_->getName()
+        << "', has " << spillerCpuExecutor_->numThreads() << " threads.";
   } else {
     PRESTO_STARTUP_LOG(INFO) << "Spill executor was not configured.";
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Align the null-check with the pointer being dereferenced to avoid potential null dereferences.

The guard condition checks `spillerExecutor_ != nullptr`, but the block dereferences `spillerCpuExecutor_`. If these ever get out of sync (e.g., `spillerExecutor_` set while `spillerCpuExecutor_` is left null), this will crash. Please either guard on `spillerCpuExecutor_` or ensure both pointers are checked before dereferencing `spillerCpuExecutor_`.

```suggestion
  }
  if (spillerCpuExecutor_ != nullptr) {
    PRESTO_STARTUP_LOG(INFO)
        << "Spiller CPU executor '" << spillerCpuExecutor_->getName()
        << "', has " << spillerCpuExecutor_->numThreads() << " threads.";
  } else {
    PRESTO_STARTUP_LOG(INFO) << "Spill executor was not configured.";
  }
  auto* asyncDataCache = velox::cache::AsyncDataCache::getInstance();
```
</issue_to_address>

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.

duxiao1212 added a commit to duxiao1212/presto that referenced this pull request Nov 26, 2025
@duxiao1212 duxiao1212 changed the title [Prestissimo] Add stall thread monitoring to Spiller cpu pool feat: Add stall thread monitoring to Spiller cpu pool Nov 26, 2025
Summary:

as title

Differential Revision: D87850298
// folly::CPUThreadPoolExecutor. The executor is stored as abstract type to
// provide flexibility of thread pool monitoring. The underlying
// folly::CPUThreadPoolExecutor can be obtained through 'spillerCpuExecutor_'.
std::unique_ptr<folly::Executor> spillerExecutor_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @duxiao1212 for this code. I'm not sure I follow the motivation for this change. Please can you help explain.

Copy link
Contributor Author

@duxiao1212 duxiao1212 Nov 26, 2025

Choose a reason for hiding this comment

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

You're right @aditi-pandit - the original type worked. However, we need to change it to std::unique_ptr<folly::Executor> because the build system allows wrapping executors with monitoring capabilities.

Background

While investigating stuck driver issues, we identified the need for thread monitoring capability on the spiller thread executor. This helps detect and diagnose thread stalls during spill operations.

Implementation

By storing as the base type Executor, the executor can be wrapped with monitoring.
While keeping the typed spillerCpuExecutor_ pointer allows PeriodicTaskManager to access monitoring methods.

This follows the same pattern as driverExecutor_ and enables consistent thread stall detection across execution contexts.

@duxiao1212 duxiao1212 changed the title feat: Add stall thread monitoring to Spiller cpu pool feat: Allow flexible thread pool monitoring for Spiller cpu pool Dec 4, 2025
@tanjialiang tanjialiang merged commit 360276c into prestodb:master Dec 4, 2025
85 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants