Skip to content

[API Proposal]: PinnedBlockMemoryPool metrics #61594

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

Open
BrennanConroy opened this issue Apr 21, 2025 · 2 comments
Open

[API Proposal]: PinnedBlockMemoryPool metrics #61594

BrennanConroy opened this issue Apr 21, 2025 · 2 comments
Labels
api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Comments

@BrennanConroy
Copy link
Member

BrennanConroy commented Apr 21, 2025

Background and Motivation

Add metrics to the PinnedBlockMemoryPool that's used by Kestrel, IIS, and Http.Sys.

Proposed API

Microsoft.AspNetCore.MemoryPool

Name Instrument Type Unit Description
aspnetcore.memorypool.current_memory UpDownCounter {bytes} Number of bytes that are currently pooled by the pool.
Name Instrument Type Unit Description
aspnetcore.memorypool.total_allocated Counter {bytes} Total number of allocations made by the pool.
Name Instrument Type Unit Description
aspnetcore.memorypool.evicted_memory Counter {bytes} Total number of bytes that have been evicted.
Name Instrument Type Unit Description
aspnetcore.memorypool.total_rented Counter {bytes} Total number of rented bytes from the pool.
@BrennanConroy BrennanConroy added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Apr 21, 2025
@ghost ghost added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Apr 21, 2025
@BrennanConroy BrennanConroy added api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Apr 21, 2025
@gfoidl gfoidl added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Apr 22, 2025
@JamesNK
Copy link
Member

JamesNK commented May 29, 2025

There can be multiple instances of memory pools. They will all write to the same counters so metrics will represent all metrics. For example, Kestrel HTTP layer could have a memory pool, Kestrel sockets layer could have a memory pool, a library could have created their own memory pool (SignalR, gRPC, etc).

There should be a way to view metrics for individual memory pools. The way to do that would be to add tags. A memory pool is given a name and that name is added as a tag when recording the value.

public void IncrementTotalMemory(int bytes)
{
    _totalAllocatedMemory.Add(bytes, new KeyValuePair<string, object>("aspnetcore.memorypool.owner", _owner));
}

This should be fine because the number of memory pools and owners should be low carindality. Although it might be worth calling out in the .NET API to avoid have many names to avoid exceeding metrics dimensions limits.

Name could be specified when creating a memory pool:

public KestrelThing(IMemoryPoolFactory<T> memoryPoolFactory)
{
    _memoryPool = memoryPoolFactory.Create(new MemoryPoolOptions { Owner = "Kestrel" });
}

@BrennanConroy
Copy link
Member Author

_memoryPool = memoryPoolFactory.Create(new MemoryPoolOptions { Owner = "Kestrel" });

That's an interesting idea. Adding options to the Create call. What potential future options would there be? David was wondering about options for eviction delay and various thresholds in #61554 (comment) and #61554 (comment) but those seem specific to our implementation. We'd likely want options to be more generic and apply to "all" pool implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

No branches or pull requests

3 participants