Skip to content

[runtime][python] Use descriptive thread names for the async executors - #1028

Merged
wenjin272 merged 3 commits into
apache:mainfrom
Zhuoxi2000:feature-async-thread-names
Aug 21, 2026
Merged

[runtime][python] Use descriptive thread names for the async executors#1028
wenjin272 merged 3 commits into
apache:mainfrom
Zhuoxi2000:feature-async-thread-names

Conversation

@Zhuoxi2000

Copy link
Copy Markdown
Contributor

Linked issue: #1013

Purpose of change

Both async executors relied on default thread names (pool-N-thread-M from the JDK 21 Executors.newFixedThreadPool, ThreadPoolExecutor-N_M from Python), which make Flink Agents async workers hard to attribute in TaskManager thread dumps, profiler output, and monitoring tools — especially idle workers, whose stacks contain only generic frames.

Following the naming convention suggested in the issue:

  • Java: a new AsyncExecutorThreadFactory names workers flink-agents-java-async-<pool-id>-thread-<worker-id>, with a process-unique pool id so multiple executor instances stay distinguishable. The factory lives in the JDK-agnostic src/main/java source set (the JDK 21 ContinuationActionExecutor consumes it), so it is unit-testable on every JDK. Only the name changes — daemon status and priority follow the default factory behavior.
  • Python: create_async_thread_pool passes a process-unique thread_name_prefix, yielding flink-agents-python-async-<pool-id>_<worker-id> via ThreadPoolExecutor's standard prefix mechanism.

Tests

  • Java: AsyncExecutorThreadFactoryTest — tasks submitted to an executor built with the factory run on threads matching flink-agents-java-async-\d+-thread-\d+; names are distinct across workers and across factory instances; daemon status and priority are unchanged from the default factory.
  • Python: test_async_thread_pool.py — submitted tasks observe names matching flink-agents-python-async-\d+_\d+, and two pools produce distinct prefixes.

API

None; thread naming only, no execution-behavior change.

Documentation

  • doc-needed
  • doc-not-needed
  • doc-included

Was this patch authored or co-authored using generative AI tooling?

  • Yes
  • No

If yes, include a Generated-by: <tool name and version> (<model name and version>) line, for example Generated-by: Claude Code 2.1.226 (Claude Opus 4.6), in the commit message so it reaches Git history. Repeat the same line here for reviewer visibility. See the ASF generative tooling guidance.

Generated-by: Claude Fable 5

@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs fixVersion/0.4.0 priority/major Default priority of the PR or issue. labels Aug 18, 2026
@Zhuoxi2000
Zhuoxi2000 marked this pull request as ready for review August 19, 2026 15:02
this.namePrefix = "flink-agents-java-async-" + POOL_ID.incrementAndGet() + "-thread-";
}

@Override

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR states that only the thread name changes, but new Thread(...) inherits the daemon status and priority of the calling thread, unlike the previous default thread factory, which normalizes them to non-daemon and NORM_PRIORITY. Could we delegate thread creation to Executors.defaultThreadFactory() to preserve the existing execution semantics?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch switched to Executors.defaultThreadFactory() so daemon status and priority keep the JDK defaults, and only the name is changed. Added a regression test for that as well.

*/
public final class AsyncExecutorThreadFactory implements ThreadFactory {

private static final AtomicInteger POOL_ID = new AtomicInteger();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use Executors.defaultThreadFactory(), the generated thread name already contains the pool and worker IDs (pool-N-thread-M). Could we simply prepend flink-agents-java-async- to that name instead of maintaining separate POOL_ID and workerId counters? The resulting name would be flink-agents-java-async-pool-N-thread-M.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done thread names now look like flink-agents-java-async-pool-N-thread-M, and the extra counters are gone.

@wenjin272 wenjin272 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing my comments. LGTM

@wenjin272
wenjin272 merged commit 087caa4 into apache:main Aug 21, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs fixVersion/0.4.0 priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants