<fix>[core]: reuse GroupedConsumeQueue timer @ZSTAC-86636#4490
<fix>[core]: reuse GroupedConsumeQueue timer @ZSTAC-86636#4490ZStack-Robot wants to merge 1 commit into
Conversation
根因:GroupedConsumeQueue.start() 每次执行都会 new Timer 并在 TimerTask finally 中递归调用 start()。每个 Timer 会创建独立 TimerThread,旧 Timer 只能依赖 GC/Finalizer 清理;HA 与 LongJob 通知队列启动后即空转调度,导致 Timer-* 线程持续创建,最终可能触发 unable to create new native thread。 修复方案:每个 GroupedConsumeQueue 实例复用一个 daemon Timer,通过 schedule(timerTask, 1000, 1000) 周期执行 collectItems();使用 AtomicBoolean 防止重复 start;捕获单次 collect/consume 异常并记录日志,避免 TimerTask 异常退出。 Jira: http://jira.zstack.io/browse/ZSTAC-86636 影响范围:仅影响 GroupedConsumeQueue 的后台分组延迟消费调度方式。HA 进度通知和 LongJob 进度通知仍按原有 timeliness 配置聚合消费;线程模型由每轮创建 TimerThread 收敛为每个队列一个 daemon TimerThread,不改变通知内容和分组逻辑。 Verification: - git diff --check - env JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home PATH=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/bin:$PATH mvn -pl core -am -DskipTests compile Co-Authored-By-AI: true
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 52 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Warning
|
背景 / 根因
GroupedConsumeQueue.start()原实现每次执行都会new Timer(),并在TimerTask finally中递归调用start()。每个Timer都会创建独立TimerThread,旧Timer只能依赖 GC/Finalizer 清理。HA 与 LongJob 通知队列在 MN 启动后即开始空转调度,导致
Timer-*按约 2 个/秒持续创建;当 GC/Finalizer 清理速度跟不上时,会积压 native threads,最终触发unable to create new native thread。Jira: http://jira.zstack.io/browse/ZSTAC-86636
本次变更
GroupedConsumeQueue实例复用一个 daemonTimer。timer.schedule(timerTask, 1000, 1000)周期执行collectItems(),替代递归start()。AtomicBoolean防止重复start()创建重复调度。TimerTask异常退出后队列不再消费。影响范围
core/src/main/java/org/zstack/core/thread/GroupedConsumeQueue.java。timeliness配置聚合消费;通知内容、分组 key、消费逻辑不变。TimerThread收敛为每个队列最多一个 daemonTimerThread,消除Timer-*持续增长风险。验证
git diff --checkenv JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home PATH=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/bin:$PATH mvn -pl core -am -DskipTests compilesync from gitlab !10446