kennknowles opened a new pull request, #41919:
URL: https://github.com/apache/beam/pull/41919

   ### Summary
   - Switch `UnboundedScheduledExecutorService`'s backing `SynchronousQueue` to 
fair (`FIFO`) mode (`new SynchronousQueue<Runnable>(true)`) so returning 
workers match the oldest waiting `offer()` first instead of starving older 
callers past the 10 ms timeout under LIFO contention.
   - Add a package-private `@VisibleForTesting` constructor `(NanoClock, long 
offerTimeout, TimeUnit offerTimeoutUnit)` while preserving the 10 ms production 
default (`DEFAULT_OFFER_TIMEOUT_MILLIS = 10`).
   - Deflake 
`UnboundedScheduledExecutorServiceTest#testThreadsAreAddedOnlyAsNeededWithContention`:
     - Pass a 1 s offer timeout so normal CI scheduling stalls or GC pauses 
between `FutureTask` completion (unblocking `.get()`) and the worker looping 
back to `SynchronousQueue.poll()` do not spuriously spawn extra threads.
     - Warm up 20 worker threads concurrently on a `CountDownLatch` and assert 
the expected pool size (`21`, including `TaskLauncher`).
     - Run 200 sequential no-op submissions per caller thread (reducing thread 
oversubscription while keeping handoff contention high).
     - Assert the exact expected pool size (`21`) with a failure message 
reporting the actual `largestPool` value, and clean up latches/executors in 
`finally`.
   
   ### Background
   `testThreadsAreAddedOnlyAsNeededWithContention` failed again on #41655 ([run 
45501936142](https://github.com/apache/beam/actions/runs/45501936142/job/142075413350)),
 logging `Created 157 threads to execute at most 100 parallel tasks` (2.366 s 
elapsed for 200 × 5 ms sleeps). Previously tracked in #31590 (and see #41799 
for a prior test-only PR).
   
   ### Verification
   Ran locally with Java 21:
   - `./gradlew :sdks:java:core:test --tests 
org.apache.beam.sdk.util.UnboundedScheduledExecutorServiceTest` (12/12 passed; 
`testThreadsAreAddedOnlyAsNeededWithContention` ran in 2.093 s and created 21 
threads)
   - `./gradlew :sdks:java:core:spotlessCheck :sdks:java:core:spotbugsMain 
:sdks:java:core:checkstyleMain :sdks:java:core:checkstyleTest`
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to