question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[SignalR] Allow controlling maximum buffer size on client

See original GitHub issue

Background and Motivation

We currently allow control over the “maximum buffer size” on the server: https://docs.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-3.1&tabs=dotnet#advanced-http-configuration-options

(We derive the PauseWriterThreshold and ResumeWriterThreshold values from that).

However, we don’t let the .NET client configure this. We should consider doing so to allow the client better control over backpressure.

This is important for high performance scenarios where the users might be receiving a large batch of data e.g https://github.com/dotnet/aspnetcore/issues/34895 and want to control how much memory is OK to allocate for unprocessed messages.

Proposed API

namespace Microsoft.AspNetCore.Http.Connections.Client
{
    public class HttpConnectionOptions
    {
+        /// <summary>
+        /// Gets or sets the maximum buffer size for data read by the application before backpressure is applied.
+        /// </summary>
+        /// <remarks>
+        /// The default value is 1MB.
+        /// </remarks>
+        public long TransportMaxBufferSize { get; set; }
+        
+        /// <summary>
+        /// Gets or sets the maximum buffer size for data written by the application before backpressure is applied.
+        /// </summary>
+        /// <remarks>
+        /// The default value is 1MB.
+        /// </remarks>
+        public long ApplicationMaxBufferSize { get; set; }
    }
}

Usage Examples

var hubConnection = new HubConnectionBuilder()
                    .WithUrl("http://localhost:5000/chat", o =>
                    {
                        // Set the transport buffer size to 30 MB before yielding
                        o.TransportMaxBufferSize = 1024 * 1024 * 30;
                    })
                    .Build();

Risks

None

Notes:

  • This mirrors the properties on the server side, but the naming isn’t great. Transport -> transport to application buffer (inbound) and Application -> application to transport (outbound).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
BrennanConroycommented, Apr 17, 2020

Right, and if we backport, we can only backport the default value

And also should have an AppContext switch to disable this just in case.

1reaction
BrennanConroycommented, Apr 10, 2020

Right, and if we backport, we can only backport the default value

Read more comments on GitHub >

github_iconTop Results From Across the Web

Security considerations in ASP.NET Core SignalR
By default, SignalR limits these buffers to 32 KB. The largest message a client or server can send is 32 KB. The maximum...
Read more >
SignalR Performance
DefaultMessageBufferSize : By default, SignalR retains 1000 messages in memory per hub per connection. · Max concurrent requests per application: ...
Read more >
Can I reduce the Circular Buffer to "1"? Is that a good idea?
The primary purpose of this minimum buffer size is to ensure that SignalR's long-polling transport works somewhat reliably.
Read more >
How to Increase the Blazor SignalR Maximum Message Size
The SignalR WebSocket has a default maximum message size of 32 KB. A large Editor Value , FileSelect file size, or a PDFViewer...
Read more >
Advanced SignalR configuration: fine-tuning the server-side ...
This option represents the maximum buffer size for the data exchange in the application layer in bytes. By default, it's set to 65...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found