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

   ## Summary
   
   Add an opt-in `--pubsubAsyncPullEnabled` option to `PubsubOptions` so 
`PubsubUnboundedSource.PubsubReader` runs its Pub/Sub `pull()` RPC on a 
background daemon thread pool instead of blocking `UnboundedReader.advance()`.
   
   ## Motivation
   
   `PubsubUnboundedSource.PubsubReader.pull()` currently blocks the caller 
thread on every HTTP/gRPC `pull()` call. On runners like Flink (FLIP-27 
`FlinkUnboundedSourceReader`), time spent inside `pollNext()` / `advance()` is 
billed as `busyTimeMsPerSecond` rather than `idleTimeMsPerSecond`. As a result, 
a standalone Pub/Sub source vertex reports ~100% busy even when it is only 
waiting on network I/O and downstream operators are mostly idle, which skews 
utilization metrics and prevents Flink's autoscaler from scaling down cleanly.
   
   Running only the `client.pull(...)` RPC asynchronously on a bounded daemon 
pool while keeping all mutable `PubsubReader` state (`notYetRead`, `inFlight`, 
`safeToAckIds`, `getCheckpointMark()`) strictly on the single reader thread 
avoids any thread-safety changes to `UnboundedReader` or checkpointing.
   
   ## Changes
   
   - `PubsubOptions`: add opt-in `--pubsubAsyncPullEnabled` (default `false`).
   - `PubsubUnboundedSource.PubsubReader`:
     - Add a shared bounded daemon `ThreadPoolExecutor` 
(`allowCoreThreadTimeOut(true)`).
     - When `pubsubAsyncPullEnabled` is enabled, `pull()` submits 
`client.pull(...)` asynchronously and returns immediately if a pull is still in 
flight; completed pulls are harvested on the reader thread on the next 
`advance()`.
     - Track `pendingPullInFlight` in `maybeCloseClient()` (matching 
`numInFlightCheckpoints`) so the client is not closed while a pull is running, 
and best-effort NACK messages received after `close()`.
   - `PubsubUnboundedSourceTest`: add 
`asyncPullDeliversMessageAndClosesCleanly`.
   
   ## Verification
   
   - `./gradlew :sdks:java:io:google-cloud-platform:spotlessApply 
:sdks:java:io:google-cloud-platform:checkstyleMain 
:sdks:java:io:google-cloud-platform:checkstyleTest` passed.
   - `./gradlew :sdks:java:io:google-cloud-platform:test --tests 
'org.apache.beam.sdk.io.gcp.pubsub.*Test'` passed (198/198).
   


-- 
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