[Improvement] Avoid potential OOM in SessionPoolExample by replacing unbounded thread pool
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
開啟 example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java,檢查第 74 行附近的 ExecutorService 初始化。確認目前固定執行緒池的佇列如何運作,然後驗證範例使用有界容量,並且不依賴無界佇列即可提供背壓。
由索引模型根據 Issue 內容生成。
描述
Search before asking
- I searched in the issues and found nothing similar.
Version
Master
Describe the bug and provide the minimal reproduce step
Description:
In example/session/src/main/java/org/apache/iotdb/SessionPoolExample.java, the ExecutorService is initialized using Executors.newFixedThreadPool(10) (Line 74).
Problem:
Executors.newFixedThreadPool uses an unbounded LinkedBlockingQueue (capacity: Integer.MAX_VALUE) by default. As this is an official example, users often copy-paste this code for production. In high-throughput write scenarios, if the production rate exceeds the consumption rate, tasks accumulate indefinitely in the queue, leading to OutOfMemoryError: Java heap space.
Code Location:
// org.apache.iotdb.SessionPoolExample.java
service = Executors.newFixedThreadPool(10); // Unbounded Queue risk
What did you expect to see?
Official examples should demonstrate best practices by using bounded queues to ensure system stability. The thread pool should provide backpressure (block or reject) when the queue is full, preventing memory exhaustion.
What did you see instead?
The example uses an unbounded queue pattern (UBSCQ), which creates a hidden memory leak risk for downstream users who adopt this code snippet.
Anything else?
Suggested Fix: Replace the factory method with a custom ThreadPoolExecutor using a bounded queue (e.g., ArrayBlockingQueue).
Proposed Code:
service = new ThreadPoolExecutor(
10, 10, 0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<>(1000) // Bounded capacity
);
Are you willing to submit a PR?
- I'm willing to submit a PR!
- 主要語言
- Java
- 星號
- 6.4k
- 分支
- 1.2k
- 平均合併
- 1 天 20 小時
- 30 天內合併 PR
- 137
環境準備
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
apache/iotdb 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 82/100
apache/iotdb#18655 · 1 個 reaction ·
維護者通常 1 天內回覆
-
IoTDB Edge: stop-edge.sh does not stop its own process when IOTDB_HOME is set, and reports success未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
Content
難度 2/5 1-3 小時 新手友好度 68/100
RunestoneInteractive/rs#1559 · 1 則留言 ·
維護者通常 2 天內回覆
-
documentation
難度 2/5 1-3 小時 新手友好度 86/100
inu-appcenter/memorIN-backend#298 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 85/100
opendataloader-project/opendataloader-pdf#757 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
redhat-developer/intellij-quarkus#1626 ·