You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2026/02/20 16:55:27 UTC

[PR] perf: Initialize tokio runtime worker threads from spark.executor.cores [datafusion-comet]

andygrove opened a new pull request, #3555:
URL: https://github.com/apache/datafusion-comet/pull/3555

   ## Summary
   
   - Initialize the tokio runtime worker thread count from `spark.executor.cores` instead of defaulting to all CPU cores
   - Resolves executor cores on the Scala side via `numDriverOrExecutorCores()` (handles `local`, `local[N]`, `local[*]`, and cluster modes) and injects the resolved value into the native config map
   - Replaces `Lazy<Runtime>` with `OnceLock<Runtime>` so the runtime can be initialized with the correct thread count from `createPlan()`
   
   ### Priority chain (highest to lowest)
   1. `COMET_WORKER_THREADS` env var — explicit override (unchanged)
   2. `spark.executor.cores` — Spark-aware default
   3. Tokio default (all CPU cores) — only if `get_runtime()` called before `createPlan`
   
   ## Test plan
   
   - [ ] `cd native && cargo build` passes
   - [ ] Existing tests pass (runtime API is unchanged)
   - [ ] Check logs for "Comet tokio runtime" message showing correct thread count
   - [ ] Verify env var override: `COMET_WORKER_THREADS=2` still takes precedence
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] perf: Initialize tokio runtime worker threads from spark.executor.cores [datafusion-comet]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on PR #3555:
URL: https://github.com/apache/datafusion-comet/pull/3555#issuecomment-3936431463

   @sqlbenchmark run tpch


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] perf: Initialize tokio runtime worker threads from spark.executor.cores [datafusion-comet]

Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich merged PR #3555:
URL: https://github.com/apache/datafusion-comet/pull/3555


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] perf: Initialize tokio runtime worker threads from spark.executor.cores [datafusion-comet]

Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich commented on code in PR #3555:
URL: https://github.com/apache/datafusion-comet/pull/3555#discussion_r2834779891


##########
spark/src/main/scala/org/apache/comet/CometExecIterator.scala:
##########
@@ -278,6 +278,11 @@ object CometExecIterator extends Logging {
         builder.putEntries(k, v)
       }
     }
+    // Inject the resolved executor cores so the native side can use it
+    // for tokio runtime thread count
+    val executorCores = numDriverOrExecutorCores(SparkEnv.get.conf)

Review Comment:
   What are the semantics of `numDriverOrExecutorCores`. It wasn't clear to me from reading the implementation. From the function name, it sounds like it might not always be `spark.executor.cores` depending on where it's invoked (driver or executor).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] perf: Initialize tokio runtime worker threads from spark.executor.cores [datafusion-comet]

Posted by "sqlbenchmark (via GitHub)" <gi...@apache.org>.
sqlbenchmark commented on PR #3555:
URL: https://github.com/apache/datafusion-comet/pull/3555#issuecomment-3936541059

   ## Comet TPC-H Benchmark Results
   
   **Baseline:** `main` (`f697d27`)
   **PR:** `d575428` - fmt
   **Scale Factor:** SF100
   **Iterations:** 1
   
   ### Query Times
   
   | Query | Baseline Avg (s) | Baseline Best (s) | PR Avg (s) | PR Best (s) | Change (Avg) | Change (Best) |
   |-------|-----------------|-------------------|-----------|------------|-------------|--------------|
   | Q1 | 10.44 | 10.44 | 10.46 | 10.46 | :white_circle: +0.2% | :white_circle: +0.2% |
   | Q2 | 5.79 | 5.79 | 5.89 | 5.89 | :white_circle: +1.6% | :white_circle: +1.6% |
   | Q3 | 9.70 | 9.70 | 9.72 | 9.72 | :white_circle: +0.2% | :white_circle: +0.2% |
   | Q4 | 11.35 | 11.35 | 11.52 | 11.52 | :white_circle: +1.5% | :white_circle: +1.5% |
   | Q5 | 18.72 | 18.72 | 19.11 | 19.11 | :white_circle: +2.1% | :white_circle: +2.1% |
   | Q6 | 2.42 | 2.42 | 2.36 | 2.36 | :white_circle: -2.3% | :white_circle: -2.3% |
   | Q7 | 11.95 | 11.95 | 11.94 | 11.94 | :white_circle: -0.1% | :white_circle: -0.1% |
   | Q8 | 24.80 | 24.80 | 24.34 | 24.34 | :white_circle: -1.9% | :white_circle: -1.9% |
   | Q9 | 38.72 | 38.72 | 37.95 | 37.95 | :white_circle: -2.0% | :white_circle: -2.0% |
   | Q10 | 10.32 | 10.32 | 10.14 | 10.14 | :white_circle: -1.7% | :white_circle: -1.7% |
   | Q11 | 4.44 | 4.44 | 4.39 | 4.39 | :white_circle: -1.0% | :white_circle: -1.0% |
   | Q12 | 6.86 | 6.86 | 7.10 | 7.10 | :white_circle: +3.6% | :white_circle: +3.6% |
   | Q13 | 6.80 | 6.80 | 6.79 | 6.79 | :white_circle: -0.2% | :white_circle: -0.2% |
   | Q14 | 3.54 | 3.54 | 3.56 | 3.56 | :white_circle: +0.5% | :white_circle: +0.5% |
   | Q15 | 7.11 | 7.11 | 6.90 | 6.90 | :white_circle: -2.9% | :white_circle: -2.9% |
   | Q16 | 4.77 | 4.77 | 4.50 | 4.50 | :green_circle: -5.7% | :green_circle: -5.7% |
   | Q17 | 32.14 | 32.14 | 32.12 | 32.12 | :white_circle: -0.1% | :white_circle: -0.1% |
   | Q18 | 33.65 | 33.65 | 33.24 | 33.24 | :white_circle: -1.2% | :white_circle: -1.2% |
   | Q19 | 6.68 | 6.68 | 6.67 | 6.67 | :white_circle: -0.1% | :white_circle: -0.1% |
   | Q20 | 6.50 | 6.50 | 6.59 | 6.59 | :white_circle: +1.4% | :white_circle: +1.4% |
   | Q21 | 46.39 | 46.39 | 46.42 | 46.42 | :white_circle: +0.1% | :white_circle: +0.1% |
   | Q22 | 4.99 | 4.99 | 4.85 | 4.85 | :white_circle: -2.8% | :white_circle: -2.8% |
   | **Total** | **308.08** | **308.08** | **306.57** | **306.57** | :white_circle: -0.5% | :white_circle: -0.5% |
   
   <details>
   <summary><b>Spark Configuration</b></summary>
   
   | Setting | Value |
   |---------|-------|
   | Spark Master | `local[*]` |
   | Driver Memory | 32G |
   | Driver Cores | 8 |
   | Executor Memory | 32G |
   | Executor Cores | 8 |
   | Off-Heap Enabled | true |
   | Off-Heap Size | 24g |
   | Shuffle Manager | `CometShuffleManager` |
   | Comet Replace SMJ | true |
   
   </details>
   
   ---
   *Automated benchmark run by dfbench*


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org