[PR #11092] [MERGED] refactor: use Channels as queueing mechanism for periodic websocket messages #12555

Closed
opened 2025-12-22 09:22:08 +01:00 by backuprepo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/jellyfin/jellyfin/pull/11092
Author: @cvium
Created: 3/2/2024
Status: Merged
Merged: 3/18/2024
Merged by: @crobibero

Base: masterHead: reduce_threads_in_baseperiodicwebsocketlistener


📝 Commits (6)

  • 14b5b31 refactor: use Channels as queueing mechanism for periodic websocket messages
  • a6766d8 change all lock statements to semaphoreslim
  • ccf16b8 Apply suggestions from code review
  • 3641d8c add more short circuits
  • 6809574 refactor to IAsyncDisposable and complete the Writer channel
  • 9ea09fd log channel errors during dispose

📊 Changes

5 files changed (+169 additions, -107 deletions)

View changed files

📝 Emby.Server.Implementations/Session/SessionManager.cs (+2 -5)
📝 Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs (+8 -5)
📝 Jellyfin.Api/WebSocketListeners/ScheduledTasksWebSocketListener.cs (+12 -9)
📝 Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs (+19 -17)
📝 MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs (+128 -71)

📄 Description

The old implementation used async void as the signature for the event handlers, which might lead to thread pool exhaustion as handlers would fetch the data synchronously despite the async signature on GetDataToSend. Furthermore, on every event, the list of active connections were retrieved inside a lock statement, which could also lead to threads being blocked during high traffic scenarios.

Queueing a bool is not great design, but this change only aims to alleviate the thread pool exhaustion.

Issues
Might fix #7783, but I have not been able to reproduce it.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/jellyfin/jellyfin/pull/11092 **Author:** [@cvium](https://github.com/cvium) **Created:** 3/2/2024 **Status:** ✅ Merged **Merged:** 3/18/2024 **Merged by:** [@crobibero](https://github.com/crobibero) **Base:** `master` ← **Head:** `reduce_threads_in_baseperiodicwebsocketlistener` --- ### 📝 Commits (6) - [`14b5b31`](https://github.com/jellyfin/jellyfin/commit/14b5b31d1cd82759e645a2f39fd2f167c1647d87) refactor: use Channels as queueing mechanism for periodic websocket messages - [`a6766d8`](https://github.com/jellyfin/jellyfin/commit/a6766d8a7c228a66f715fee08947f5990ec2dfba) change all lock statements to semaphoreslim - [`ccf16b8`](https://github.com/jellyfin/jellyfin/commit/ccf16b865ddd3f74df161513f11ebf9aa58829ed) Apply suggestions from code review - [`3641d8c`](https://github.com/jellyfin/jellyfin/commit/3641d8c2be40ba4226f105829f5430a0e97690d2) add more short circuits - [`6809574`](https://github.com/jellyfin/jellyfin/commit/68095741849790c294a99c9aafd9afcf14602fd9) refactor to IAsyncDisposable and complete the Writer channel - [`9ea09fd`](https://github.com/jellyfin/jellyfin/commit/9ea09fd6c9af388c62156b002a64a97dbc07a30b) log channel errors during dispose ### 📊 Changes **5 files changed** (+169 additions, -107 deletions) <details> <summary>View changed files</summary> 📝 `Emby.Server.Implementations/Session/SessionManager.cs` (+2 -5) 📝 `Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs` (+8 -5) 📝 `Jellyfin.Api/WebSocketListeners/ScheduledTasksWebSocketListener.cs` (+12 -9) 📝 `Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs` (+19 -17) 📝 `MediaBrowser.Controller/Net/BasePeriodicWebSocketListener.cs` (+128 -71) </details> ### 📄 Description The old implementation used async void as the signature for the event handlers, which might lead to thread pool exhaustion as handlers would fetch the data synchronously despite the async signature on GetDataToSend. Furthermore, on every event, the list of active connections were retrieved inside a `lock` statement, which could also lead to threads being blocked during high traffic scenarios. Queueing a bool is not great design, but this change only aims to alleviate the thread pool exhaustion. **Issues** Might fix #7783, but I have not been able to reproduce it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
backuprepo 2025-12-22 09:22:08 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: starred/jellyfin#12555
No description provided.