feat: Mutex redesign - isolate event processing for better ordering and throughput#2137
Conversation
…e IDs" This reverts commit c03f9d8.
…, and notification processing
|
Thanks for opening this pull request and contributing to the project! The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch. In the meantime, anyone in the community is encouraged to test this pull request and provide feedback. ✅ How to confirm it worksIf you’ve tested this PR, please comment below with: This helps us speed up the review and merge process. 📦 To test this PR locally:If you encounter any issues or have feedback, feel free to comment as well. |
|
@jlucaso1 please evaluate performance impact and review, seems important |
|
This is a good solution, but not the definitive, maybe the message.upsert is freezing in the main mutex caused by some deadlock. This approach will mitigate this and will help us to find where the deadlock is happening specifically. About the perfomance (memory usage and cpu) is fine and worth. We are only splitting principles. good work @Santosl2 |
Thx dude! |
This pull request refactors the mutex usage in the socket modules to improve concurrency control and processing order for different event types. Instead of a single
processingMutex, the code now uses dedicated mutexes for messages, receipts, notifications, and app state patches. This change enhances clarity, prevents resource contention, and allows more granular locking for each event type.Concurrency and Mutex Refactoring:
processingMutexwith four dedicated mutexes:messageMutex,receiptMutex,appStatePatchMutex, andnotificationMutexinsrc/Socket/chats.ts. Each mutex now ensures ordered processing for its respective event type.src/Socket/chats.ts,src/Socket/messages-recv.ts, andsrc/Socket/messages-send.tsto use the new mutexes instead ofprocessingMutex. [1] [2] [3]Event Processing Improvements:
src/Socket/messages-recv.tsto use the appropriate mutex for receipts (receiptMutex), notifications (notificationMutex), and messages (messageMutex) to ensure each type is processed in order independently. [1] [2] [3]src/Socket/chats.tsto useappStatePatchMutex, ensuring app state patches are handled in order without blocking other event types.src/Socket/messages-send.tsto usemessageMutexfor appending messages, improving isolation between message events.