perf: Initialize tokio runtime worker threads from spark.executor.cores#3555
Merged
mbutrovich merged 2 commits intoapache:mainfrom Feb 20, 2026
Merged
Conversation
The tokio runtime was previously a process-wide lazy static initialized on first access with the default thread count (all CPU cores). This wastes resources when spark.executor.cores is less than the total CPU count. This change initializes the runtime dynamically using the resolved value of spark.executor.cores as the default worker thread count. The priority chain is: 1. COMET_WORKER_THREADS env var (explicit override, unchanged) 2. spark.executor.cores (resolved by numDriverOrExecutorCores) 3. Tokio default (all CPU cores, only if get_runtime() called before createPlan) The Scala side resolves spark.executor.cores via numDriverOrExecutorCores() which handles local, local[N], local[*], and cluster modes, then injects the resolved value into the config map sent to native code. On the Rust side, Lazy<Runtime> is replaced with OnceLock<Runtime> so the runtime can be initialized with the executor cores value from createPlan(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
Author
|
@sqlbenchmark run tpch |
Comet TPC-H Benchmark ResultsBaseline: Query Times
Spark Configuration
Automated benchmark run by dfbench |
mbutrovich
reviewed
Feb 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
spark.executor.coresinstead of defaulting to all CPU coresnumDriverOrExecutorCores()(handleslocal,local[N],local[*], and cluster modes) and injects the resolved value into the native config mapLazy<Runtime>withOnceLock<Runtime>so the runtime can be initialized with the correct thread count fromcreatePlan()Priority chain (highest to lowest)
COMET_WORKER_THREADSenv var — explicit override (unchanged)spark.executor.cores— Spark-aware defaultget_runtime()called beforecreatePlanTest plan
cd native && cargo buildpassesCOMET_WORKER_THREADS=2still takes precedence🤖 Generated with Claude Code