Commit c3ef76c
perf: Initialize tokio runtime worker threads from spark.executor.cores (apache#3555)
* perf: Initialize tokio runtime worker threads from spark.executor.cores
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>
* fmt
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent f697d27 commit c3ef76c
3 files changed
Lines changed: 39 additions & 7 deletions
File tree
- native/core/src/execution
- spark/src/main/scala/org/apache/comet
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
100 | 106 | | |
101 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
102 | 112 | | |
| 113 | + | |
| 114 | + | |
103 | 115 | | |
104 | 116 | | |
105 | 117 | | |
| |||
108 | 120 | | |
109 | 121 | | |
110 | 122 | | |
111 | | - | |
| 123 | + | |
112 | 124 | | |
113 | | - | |
114 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
115 | 129 | | |
116 | 130 | | |
117 | 131 | | |
118 | 132 | | |
119 | | - | |
| 133 | + | |
120 | 134 | | |
121 | 135 | | |
122 | 136 | | |
| |||
192 | 206 | | |
193 | 207 | | |
194 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
195 | 214 | | |
196 | 215 | | |
197 | 216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
43 | 51 | | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
281 | 286 | | |
282 | 287 | | |
283 | 288 | | |
| |||
0 commit comments