feat: Redis distributed lock for high concurrency#662
feat: Redis distributed lock for high concurrency#662jlin53882 wants to merge 6 commits intoCortexReach:masterfrom
Conversation
- Add src/redis-lock.ts: Token-based Redis lock with graceful fallback - Add test files for performance, edge cases, and optimization - Add ioredis dependency Fixes CortexReach#643: improves 200 concurrent write success from 6% to 97.5% Requires: npm install ioredis
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
CI StatusThe CI failures are NOT related to this PR. Here's the analysis: Failed Jobs & Root Causes
Evidence
The failing tests existed in master branch before this PR. They need to be fixed separately. What's in This PROnly Redis distributed lock implementation:
|
- Replace no-op lock with proper file lock fallback - Maintains lock protection even without Redis - Import proper-lockfile for file lock support
Update: Fallback to File LockChangeUpdated the fallback behavior when Redis is unavailable:
Code Change\\ ypescript // After (file lock) Behavior
This maintains lock protection even without Redis. |
- Remove retries from sync lock (not supported) - Handle Windows path for tmp directory - Ignore ENOENT when releasing - Add fallback unit tests
Update: Fallback tests addedAdded unit tests for file lock fallback behavior: Test Results
Changes
|
- Log Redis unavailable with error details - Log file lock acquire/release with key and path - Use emoji markers for clarity (✅/❌)
Update: Detailed logging addedLogging Improvements
PurposeThese detailed logs help verify that:
|
- Add Redis lock manager initialization - Modify runWithFileLock to use Redis lock first, fallback to file lock - Add integration test for 20/50 concurrent operations - Fixes Issue CortexReach#643 lock contention
Update: Redis Lock 整合到 store.ts現在可以直接使用 Redis Lock!修改 store.ts 的
測試結果
實際運作 Log
單元測試新增 est/redis-lock-store-integration.test.mjs 測試整合後的並發表現。 需要
|
Update: Auto-Capture Lock Contention Test新增測試測試結果
發現每次 auto-capture 都會:
這就是 Issue #665 的問題。 解決方案實作 �ulkStore() 批次寫入,減少 lock 取得次數。 |
5b86a9a to
7f1475d
Compare
Summary
This PR implements a Redis-based distributed lock to solve the high concurrency lock contention problem identified in Issue #643.
Problem
When captureAssistant=true and sessionMemory.enabled=true:
Solution
Add src/redis-lock.ts with:
Test Results
15x improvement!
Required
\
npm install ioredis
\\
Related