Skip to content

[API review] IMemoryPoolFactory options #63085

@JamesNK

Description

@JamesNK

Background and Motivation

IMemoryPoolFactory<T> was added in #61003.

This issue proposes a small change to support options when creating a memory pool. Initially options will only be used to pass the owner of the factory, which is used in diagnostics.

The owner in telemetry allows memory pools used by different servers (iis, httpsys, kestrel) or libraries to be viewed separately when there are multiple memory pools in the same app.

In the future more options could be passed (eviction options like timer frequency?) but none are planned for now.

Proposed API

namespace Microsoft.AspNetCore.Connections;

public interface IMemoryPoolFactory<T>
{
-    MemoryPool<T> Create();
+    MemoryPool<T> Create(MemoryPoolOptions? options = null);
}

+ public class MemoryPoolOptions
+ {
+     public string? Owner { get; set; }
+ }

Usage Examples

public class MyType(IMemoryPoolFactory<byte> memoryPoolFactory)
{
    private readonly MemoryPool<byte> _pool = memoryPoolFactory.Create(new { Owner = "contoso" });
}

Alternative Designs

  • MemoryPool<T> Create(MemoryPoolOptions? options = null) parameter is optional. Decided to use optional parameter to avoid users having to pass empty options.
  • MemoryPoolOptions is no sealed in case factory implementions want to extend it with new values.

Risks

Metadata

Metadata

Assignees

Labels

api-ready-for-reviewAPI is ready for formal API review - https://github.com/dotnet/apireviewsarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions