Bump `MemoryPoolHttpResponseStreamWriter` buffer size up to 16K `char`s
- #3516 - fix tests that relied on otherwise-unused `HttpResponseStreamWriter.DefaultBufferSize`
This commit is contained in:
parent
68866f8716
commit
141b637d20
|
|
@ -15,9 +15,17 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
||||||
public class MemoryPoolHttpResponseStreamWriterFactory : IHttpResponseStreamWriterFactory
|
public class MemoryPoolHttpResponseStreamWriterFactory : IHttpResponseStreamWriterFactory
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The default size of created char buffers.
|
/// The default size of buffers <see cref="HttpResponseStreamWriter"/>s will allocate.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly int DefaultBufferSize = 1024; // 1KB - results in a 4KB byte array for UTF8.
|
/// <value>
|
||||||
|
/// 16K causes each <see cref="HttpResponseStreamWriter"/> to allocate one 16K
|
||||||
|
/// <see langword="char"/> array and one 32K (for UTF8) <see langword="byte"/> array.
|
||||||
|
/// </value>
|
||||||
|
/// <remarks>
|
||||||
|
/// <see cref="MemoryPoolHttpResponseStreamWriterFactory"/> maintains <see cref="ArrayPool{T}"/>s
|
||||||
|
/// for these arrays.
|
||||||
|
/// </remarks>
|
||||||
|
public static readonly int DefaultBufferSize = 16 * 1024;
|
||||||
|
|
||||||
private readonly ArrayPool<byte> _bytePool;
|
private readonly ArrayPool<byte> _bytePool;
|
||||||
private readonly ArrayPool<char> _charPool;
|
private readonly ArrayPool<char> _charPool;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
@ -23,7 +22,8 @@ namespace Microsoft.AspNetCore.Mvc
|
||||||
{
|
{
|
||||||
public class ContentResultTest
|
public class ContentResultTest
|
||||||
{
|
{
|
||||||
private const int DefaultCharacterChunkSize = HttpResponseStreamWriter.DefaultBufferSize;
|
private static readonly int DefaultCharacterChunkSize =
|
||||||
|
MemoryPoolHttpResponseStreamWriterFactory.DefaultBufferSize;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ContentResult_Response_NullContent_SetsContentTypeAndEncoding()
|
public async Task ContentResult_Response_NullContent_SetsContentTypeAndEncoding()
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc.Abstractions;
|
using Microsoft.AspNetCore.Mvc.Abstractions;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Internal;
|
||||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||||
|
|
@ -297,10 +298,21 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
Assert.Equal(expectedLength, memoryStream.Length);
|
Assert.Equal(expectedLength, memoryStream.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TheoryData<int> WriteLengthData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new TheoryData<int>
|
||||||
|
{
|
||||||
|
MemoryPoolHttpResponseStreamWriterFactory.DefaultBufferSize - 1,
|
||||||
|
MemoryPoolHttpResponseStreamWriterFactory.DefaultBufferSize + 1,
|
||||||
|
2 * MemoryPoolHttpResponseStreamWriterFactory.DefaultBufferSize + 4,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(HttpResponseStreamWriter.DefaultBufferSize - 1)]
|
[MemberData(nameof(WriteLengthData))]
|
||||||
[InlineData(HttpResponseStreamWriter.DefaultBufferSize + 1)]
|
|
||||||
[InlineData(2 * HttpResponseStreamWriter.DefaultBufferSize + 4)]
|
|
||||||
public async Task ExecuteAsync_AsynchronouslyFlushesToTheResponseStream_PriorToDispose(int writeLength)
|
public async Task ExecuteAsync_AsynchronouslyFlushesToTheResponseStream_PriorToDispose(int writeLength)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
@ -310,7 +322,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
||||||
await v.Writer.WriteAsync(text);
|
await v.Writer.WriteAsync(text);
|
||||||
});
|
});
|
||||||
|
|
||||||
var expectedWriteCallCount = Math.Ceiling((double)writeLength / HttpResponseStreamWriter.DefaultBufferSize);
|
var expectedWriteCallCount =
|
||||||
|
Math.Ceiling((double)writeLength / MemoryPoolHttpResponseStreamWriterFactory.DefaultBufferSize);
|
||||||
|
|
||||||
var context = new DefaultHttpContext();
|
var context = new DefaultHttpContext();
|
||||||
var stream = new Mock<Stream>();
|
var stream = new Mock<Stream>();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue