Repository navigation
Conversation
…spill event or have a spill rejected - finalEvents is a synchronized list: with final merge off, spill callbacks add their events from the spill threads - The spill pool queues instead of rejecting: core = max = maxThreads, LinkedBlockingQueue, idle threads time out - testConcurrentSpillsWithFinalMergeDisabled: 40 writers, 4 at a time, 64 buffers of 4 KiB each, final merge off
|
💔 -1 overall
This message was automatically generated. |
| String auxiliaryService = defaultConf.get(TezConfiguration.TEZ_AM_SHUFFLE_AUXILIARY_SERVICE_ID, | ||
| TezConfiguration.TEZ_AM_SHUFFLE_AUXILIARY_SERVICE_ID_DEFAULT); |
There was a problem hiding this comment.
this logic is repeated many times in this class, and always falls back to default, can you please refactor to just simply use TezConfiguration.TEZ_AM_SHUFFLE_AUXILIARY_SERVICE_ID_DEFAULT?
| */ | ||
| @Test | ||
| @Timeout(value = 120, unit = TimeUnit.SECONDS) | ||
| public void testConcurrentSpillsWithFinalMergeDisabled() throws Exception { |
There was a problem hiding this comment.
the unit test has timed out for me locally without the patch? I guess that's not the expected behavior given there are assertions
[ERROR] org.apache.tez.runtime.library.common.writers.TestUnorderedPartitionedKVWriter.testConcurrentSpillsWithFinalMergeDisabled -- Time elapsed: 120.6 s <<< ERROR!
java.util.concurrent.TimeoutException: testConcurrentSpillsWithFinalMergeDisabled() timed out after 120 seconds
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Suppressed: java.lang.InterruptedException
at java.base/java.util.concurrent.FutureTask.awaitDone(FutureTask.java:471)
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:190)
at org.apache.tez.runtime.library.common.writers.TestUnorderedPartitionedKVWriter.testConcurrentSpillsWithFinalMergeDisabled(TestUnorderedPartitionedKVWriter.java:1145)
| // availableSlots bounds the spills in flight; the queue only absorbs the moment between a spill callback | ||
| // releasing its slot and its thread returning to the pool, which a SynchronousQueue rejected. |
There was a problem hiding this comment.
which a SynchronousQueue rejected mentions the old behavior, try to justify current state in code comments if possible
| ExecutorService writers = Executors.newFixedThreadPool(4); | ||
| try { | ||
| List<Future<?>> results = new ArrayList<>(); | ||
| for (int writer = 0; writer < 40; writer++) { | ||
| int id = writer; | ||
| results.add(writers.submit(() -> { | ||
| writeWithConcurrentSpills(id); | ||
| return null; | ||
| })); | ||
| } | ||
| for (Future<?> result : results) { | ||
| result.get(); | ||
| } | ||
| } finally { | ||
| writers.shutdownNow(); | ||
| } |
There was a problem hiding this comment.
maybe simplify:
List<Callable<Void>> writers = IntStream.range(0, 40)
.<Callable<Void>>mapToObj(id -> () -> {
writeWithConcurrentSpills(id);
return null;
})
.toList();
try (ExecutorService pool = Executors.newFixedThreadPool(4)) {
for (Future<Void> result : pool.invokeAll(writers)) {
result.get();
}
}
| // to restrict submission of more tasks than threads (e.g numBuffers > numThreads) | ||
| // This is maxThreads - 1, to avoid race between callback thread releasing semaphore and the | ||
| // thread calling tryAcquire. |
There was a problem hiding this comment.
The - 1 and this comment are leftovers from the SynchronousQueue: with the queue, a callback that has released its slot while its thread is still busy no longer causes a rejection. The semaphore itself is still needed, though: when no slot is free, scheduleSpill(false) leaves the filled buffers in filledBuffers and they are spilled together later, instead of each queueing as its own small spill (one more spill file, and one more event with final merge off or pipelined shuffle). Maybe update the comment so nobody removes it:
| // to restrict submission of more tasks than threads (e.g numBuffers > numThreads) | |
| // This is maxThreads - 1, to avoid race between callback thread releasing semaphore and the | |
| // thread calling tryAcquire. | |
| // Bounds the spills in flight. When no slot is free, filled buffers wait in filledBuffers and are spilled | |
| // together later instead of queueing one small spill each. The pool's queue absorbs a callback that has | |
| // released its slot while its thread is still busy, so the slots no longer need to stay below maxThreads. |
With
tez.runtime.enable.final-merge.in.output=false(and pipelined shuffle off), each spill's callback(
SpillCallback.onSuccess->mayBeSendEventsForSpill) adds the spill'sCompositeDataMovementEventtofinalEventson its spill thread, and
close()returns that list. When spills finish at the same time:finalEventsis a plainLinkedList, and twoaddAlls at once can corrupt it. If a node is lost but the size iskept,
close()returns anullandTezEventfails the attempt ("Unknown event"). If the node and the sizeincrement are both lost, the list is one event short and the consumer waits forever for that spill: a silent hang.
SynchronousQueue. A callback releases itsavailableSlotspermit whileit still runs on its pool thread, and the
maxThreads - 1permits leave room for one such thread, not several. Whenevery thread is busy,
scheduleSpillgets aRejectedExecutionExceptionand the task fails.UnorderedOutSpillerthreads, 1 to 2.6 hours old, in an LLAP daemon.Two spills in flight are routine: in Hive on Tez (LLAP), TPC-DS 10 TB, one q78 run had 218 of 1,377 writers of a map
vertex with two pool spills in flight, as
close()schedules a spill of the filled buffers while a mid-task one runs.A corruption needs two appends to overlap, so it is rare per writer.
The patch:
finalEventsa synchronized list.close()already waits for every pending spill underspillLockbefore itreads the list.
maxThreads, aLinkedBlockingQueueandallowCoreThreadTimeOut(true).availableSlotsstill bounds the spills in flight; the queue only absorbs the moment between a callback releasingits permit and its thread returning to the pool. Idle threads exit after 60 s.
Test:
testConcurrentSpillsWithFinalMergeDisabledruns 40 writers, 4 at a time, each with 64 buffers of 4 KiB (32spill threads), 16 partitions and 200,000 records, final merge off. It checks that no spill is rejected, that
close()returns no
null, and that it returns one spill event per spill. It is a stress test, so it can pass on a brokenwriter: on master it failed 6 of 6 runs (5
RejectedExecutionException, 1nullevent), and with other sizes it alsocaught the silent case (
spill events ==> expected: <316> but was: <315>). With the patch it passed 8 of 8 runs, ~28 seach (14-core laptop).
TestUnorderedPartitionedKVWriter: 371 run, 0 failures; tez-runtime-library: 824 run, 0 failures (2 async-http tests error with a nettyNoSuchFieldErrorin my local build, on master too).