Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow consumers to choose BoundedChannelFullMode #54

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

Mpdreamz
Copy link
Member

@Mpdreamz Mpdreamz commented Apr 9, 2024

This PR exposes BoundedChannelFullMode

This allows consumers to decide certain trade offs themselves.

Here are four example all pushing a million documents to the channel in a tight loop (extreme case of overproducing).

BoundedChannelFullMode.Wait is still the default but in these cases where we extremely overproduce it can allocate more then expected see: https://github.com/dotnet/runtime/blob/fadd8313653f71abd0068c8bf914be88edb2c8d3/src/libraries/System.Threading.Channels/src/System/Threading/Channels/BoundedChannel.cs#L609

A downside of BoundedChannelFullMode.DropWrite is that TryWrite on a BoundedChannel will always return true: https://github.com/dotnet/runtime/blob/fadd8313653f71abd0068c8bf914be88edb2c8d3/src/libraries/System.Threading.Channels/src/System/Threading/Channels/BoundedChannel.cs#L428 and there won't be any notifications of items that failed to write.

On a dataset of a million documents using the following buffer options:

default scenario

Inbound Outbound Concurrency FullMode Indexed All
100_000 (default) 1_000 (default) default (>1) WAIT
image

default scenario with DropWrite

Inbound Outbound Concurrency FullMode Indexed All
100_000 (default) 1_000 (default) default (>1) DROPWRITE 💥 (only 710_001 docs made it)
image

constraint scenario

Inbound Outbound Concurrency FullMode Indexed All
1_000 200 default (>1) WAIT

While successful it takes quite a bit longer to index all million items.

image

constraint scenario with DropWrite

Inbound Outbound Concurrency FullMode Indexed All
1_000 200 default (>1) DROPWRITE 💥 (only 264_601 docs made it)
image

@Mpdreamz
Copy link
Member Author

Mpdreamz commented Apr 9, 2024

The defaults scenarios still have 'high' gen2 allocations but they are all owned by the TlsOverPerCoreLockedStacksArrayPool backing the System.Channels BoundedBuffer.

Unsure if there is anything we can do to control it.

See e.g this proposal to .NET dotnet/runtime#53895

Copy link
Contributor

@stevejgordon stevejgordon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Mpdreamz Mpdreamz merged commit a05bf2c into main Apr 10, 2024
4 checks passed
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