Repository navigation
Commit 646ff18
fix: park the native scan loop instead of busy-polling while waiting on native I/O (#6219)
* fix: park the native scan loop instead of busy-polling while waiting on native I/O
executePlan's ScanExec path re-polled the plan's stream in a tight loop whenever
it returned Pending, relying on pull_input_batches to block on the JVM iterators
in between. Once every JVM-fed scan holds a batch or has reached EOF that pull is
a no-op, so a stream pending on native I/O (a Parquet or Iceberg scan reading
from S3 or HDFS) spun the executor thread at 100% CPU for the whole read. A
broadcast hash join over a native scan hits this on every probe-side read.
pull_input_batches and the two scan operators now report whether a buffer was
refilled. When the stream is Pending and nothing was pulled, the loop parks the
block_on task until a waker registered by that poll fires, bounded by a short
safety timeout, then re-enters the loop so JVM-fed scans still get refilled.
Awaiting the stream directly is not safe: ScanExec returns Pending without a
waker when an operator drains and re-polls it within one poll. The metrics
interval is checked every iteration now that iterations are no longer spins.
Closes #6091
Co-Authored-By: Claude Fable 5.1 <[email protected]>
* fix: wake the scan streams on refill and park the loop without a timeout
ScanStream and ShuffleScanStream now register the poll's waker when their
buffer is empty and get_next_batch wakes it after refilling, so every
Pending from the plan carries a waker. The loop in executePlan moves into
next_batch(stream, on_pending): poll, refill and check metrics on Pending,
then park until a waker fires. The 100 ms timeout, the bool from
get_next_batch and the tokio time feature are gone.
EOF stays buffered so a re-poll of an exhausted scan returns Ready(None)
again instead of another JNI round trip. The tracing memory sample sits
behind the metrics interval, and development.md describes the loop.
Tests drive next_batch with a stream pending on a sleep (with the park
removed it pulls 135,311 times in 50 ms) and with a ScanExec refilled by
the pull closure under a timeout, plus a ShuffleScanStream waker test.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
* fix: bound the sleep-based loop test and correct the threading notes
The JVM data source path polls operators on the Spark executor thread
inside block_on; only tasks they spawn run on tokio workers. The heading
now names ShuffleScanExec as well, since pull_input_batches feeds both
streams and both register a waker. The native-wait test gets the same
ten second bound as the refill test, so a lost wake fails instead of
hanging the suite.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
* fix: skip the park after a pull that made a JNI call
A JNI pull can run another Comet native plan on the executor thread, for
example when a native writer's input is itself native and is fed in
through CometArrowStream. That plan's block_on shares the thread's tokio
parker, which holds a single wake-up token. If the outer plan's native
I/O completes while the nested plan is parked, the nested park consumes
the wake-up, and the outer loop, which parked after every pull, then
waits for a wake that has already fired.
get_next_batch on both scan operators reports again whether it made the
JNI call, and next_batch parks only when no scan did. A no-op pull still
parks, so the busy-poll in #6091 stays fixed. The wakers stay, so every
Pending still carries one and the park needs no timeout.
The new nested block_on test runs a block_on inside the pull closure that
outlasts the stream's sleep, and asserts on elapsed time, because the
test's ten-second timeout would otherwise rescue the lost wake and let it
pass.
* fix: notice a wake-up with a flag of the loop's own, not the pull's result
next_batch skipped the park after a pull that made a JNI call, because
the call can run another Comet plan on this thread, and that plan's
block_on shares the thread's parker and can take the wake-up meant for
this loop. That relied on every such call reporting itself, and the
metrics update in the same closure calls into the JVM without doing so.
As suggested in review, next_batch now polls the stream with a waker
that sets a flag of its own before forwarding to block_on. A nested
park can take the parker's wake-up but not the flag, so the loop parks
only when the flag is still clear after the pull, and otherwise wakes
block_on itself to poll again. get_next_batch and pull_input_batches
return () again, as in the earlier commits.
It polls again by yielding to block_on rather than looping inside one
poll, so each poll gets a fresh coop budget. A stream that has spent
its budget wakes itself and returns Pending, and a loop would only get
past that because block_in_place leaves the budget unconstrained on a
thread that is not a tokio worker.
The loop tests now assert on elapsed time in the shared helper, because
the timeout's timer polls the future again when it fires, and that can
finish it. Without the check, a WakeFlag that did not forward to
block_on still passed the native I/O test, in 10 s.
* docs: say why next_batch runs on_pending inside block_in_place
The comment came over from the old loop and said block_in_place lets
tokio move other tasks off this worker. next_batch runs inside
block_on on the Spark task thread, which is not a tokio worker, so
there is no core to hand off. There block_in_place stops the coop
budget and exits the runtime context, and exiting is what lets a
nested Comet plan's block_on run inside on_pending instead of
panicking with "Cannot start a runtime from within a runtime".
on_pending also runs the metrics update now, not only the JNI pull.
Suggested in review.
---------
Co-authored-by: Michael Taranov <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>1 parent b01c168 commit 646ff18
4 files changed
Lines changed: 336 additions & 108 deletions
File tree
- docs/source/contributor-guide
- native/core/src/execution
- operators
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
| |||
95 | 94 | | |
96 | 95 | | |
97 | 96 | | |
| 97 | + | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
100 | 104 | | |
101 | 105 | | |
102 | 106 | | |
| |||
508 | 512 | | |
509 | 513 | | |
510 | 514 | | |
511 | | - | |
512 | | - | |
513 | 515 | | |
514 | 516 | | |
515 | 517 | | |
| |||
723 | 725 | | |
724 | 726 | | |
725 | 727 | | |
726 | | - | |
727 | 728 | | |
728 | 729 | | |
729 | 730 | | |
| |||
1019 | 1020 | | |
1020 | 1021 | | |
1021 | 1022 | | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
1022 | 1084 | | |
1023 | 1085 | | |
1024 | 1086 | | |
| |||
1156 | 1218 | | |
1157 | 1219 | | |
1158 | 1220 | | |
1159 | | - | |
1160 | | - | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
1164 | | - | |
1165 | | - | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
1170 | | - | |
1171 | | - | |
1172 | | - | |
1173 | | - | |
1174 | | - | |
1175 | | - | |
1176 | | - | |
1177 | | - | |
1178 | | - | |
1179 | | - | |
1180 | | - | |
1181 | | - | |
1182 | | - | |
1183 | | - | |
1184 | | - | |
1185 | | - | |
1186 | | - | |
1187 | | - | |
1188 | | - | |
1189 | | - | |
1190 | | - | |
1191 | | - | |
1192 | | - | |
1193 | | - | |
1194 | | - | |
1195 | | - | |
1196 | | - | |
1197 | | - | |
1198 | | - | |
1199 | | - | |
1200 | | - | |
1201 | | - | |
1202 | | - | |
1203 | | - | |
1204 | | - | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
1205 | 1244 | | |
1206 | | - | |
| 1245 | + | |
1207 | 1246 | | |
1208 | 1247 | | |
1209 | 1248 | | |
| |||
1265 | 1304 | | |
1266 | 1305 | | |
1267 | 1306 | | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
1268 | 1331 | | |
1269 | 1332 | | |
1270 | 1333 | | |
| |||
1827 | 1890 | | |
1828 | 1891 | | |
1829 | 1892 | | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
1830 | 1896 | | |
1831 | 1897 | | |
1832 | 1898 | | |
1833 | 1899 | | |
1834 | 1900 | | |
| 1901 | + | |
1835 | 1902 | | |
| 1903 | + | |
1836 | 1904 | | |
1837 | 1905 | | |
1838 | 1906 | | |
| 1907 | + | |
| 1908 | + | |
1839 | 1909 | | |
1840 | 1910 | | |
1841 | 1911 | | |
| |||
2312 | 2382 | | |
2313 | 2383 | | |
2314 | 2384 | | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
| 2421 | + | |
| 2422 | + | |
| 2423 | + | |
| 2424 | + | |
| 2425 | + | |
| 2426 | + | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
| 2454 | + | |
| 2455 | + | |
| 2456 | + | |
| 2457 | + | |
| 2458 | + | |
| 2459 | + | |
| 2460 | + | |
| 2461 | + | |
| 2462 | + | |
| 2463 | + | |
| 2464 | + | |
| 2465 | + | |
| 2466 | + | |
| 2467 | + | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
2315 | 2485 | | |
0 commit comments