Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added avatar.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/io-investigation-348.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 深入調查:loadSessionStore() 在 cron 頻繁執行下的 I/O 開銷 (#348)
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.

此處建議補上錯誤處理/回傳值檢查:目前若上游回傳非預期格式,可能導致後續流程拋出非預期例外或產生難以追蹤的狀態。


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.

請確認此變更是否有對應測試(至少涵蓋:正常路徑、空值/缺值、以及外部依賴失敗)。若目前未涵蓋,建議補上以避免回歸。

本文件針對 `loadSessionStore()` 在高頻 cron 執行場景下的 I/O 效能瓶頸進行初步分析與實驗設計。
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.

此處的抽象與命名建議再明確一些:請補充註解/文件說明設計意圖與假設前提,避免後續維護時誤用或改壞。


## 問題定義
當 cron 任務頻繁執行時,`loadSessionStore()` 頻繁進行磁盤讀寫操作,可能導致:
1. **I/O 寫入爭搶**:多個並發任務同時讀寫 `sessions.json`。
2. **鎖等待**:SQLite/檔案鎖導致延遲增加。
3. **磁盤壽命**:過高的寫入頻率影響 VM 環境的 disk I/O。

## 初步建議
1. **讀取快取**:在 memory 中維護 `sessions.json` 的快取,而非每次呼叫都讀取磁盤。
2. **批次處理**:將多次 I/O 寫入合併為單次 Batch 寫入。
3. **檢查機制**:增加「僅在狀態發生變更時」才寫入磁盤的邏輯。

Loading