Skip to content

Switch to Channel-based message processing#315

Merged
239573049 merged 3 commits intoAIDotNet:mainfrom
geffzhang:channel-based-message-processing
Feb 13, 2026
Merged

Switch to Channel-based message processing#315
239573049 merged 3 commits intoAIDotNet:mainfrom
geffzhang:channel-based-message-processing

Conversation

@geffzhang
Copy link
Contributor

Replace manual SemaphoreSlim/task-list concurrency with a bounded Channel producer/consumer model. Adds System.Threading.Channels and a bounded channel (capacity 100, FullMode=Wait) as a shared buffer. Refactors ExecuteAsync to run a single producer that dequeues messages and writes to the channel, and MaxConcurrency consumer tasks that read from the channel and call ProcessMessageAsync. Completes the channel writer on shutdown and preserves message completion, retry and dead-letter handling. This simplifies concurrency control, provides backpressure, and cleans up task management and error handling.

Replace manual SemaphoreSlim/task-list concurrency with a bounded Channel producer/consumer model. Adds System.Threading.Channels and a bounded channel (capacity 100, FullMode=Wait) as a shared buffer. Refactors ExecuteAsync to run a single producer that dequeues messages and writes to the channel, and MaxConcurrency consumer tasks that read from the channel and call ProcessMessageAsync. Completes the channel writer on shutdown and preserves message completion, retry and dead-letter handling. This simplifies concurrency control, provides backpressure, and cleans up task management and error handling.
Initialize the bounded Channel in the constructor with a capacity based on MaxConcurrency (Math.Max(1, MaxConcurrency) * 100) instead of a fixed 100. Preserve SingleWriter/SingleReader and FullMode settings. Also simplify task creation in ExecuteAsync by calling ProduceMessagesAsync and ConsumeMessagesAsync directly (removing unnecessary Task.Run wrappers) and awaiting them together with Task.WhenAll. These changes size the queue according to configured concurrency and reduce task scheduling overhead.
@239573049 239573049 merged commit d698978 into AIDotNet:main Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants