-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Milestone
Description
Background and Motivation
Add metrics to the PinnedBlockMemoryPool that's used by Kestrel, IIS, and Http.Sys.
Proposed API
Microsoft.AspNetCore.MemoryPool
aspnetcore.memorypool.pooled
Name | Instrument Type | Unit | Description |
---|---|---|---|
aspnetcore.memorypool.pooled |
UpDownCounter | By |
Number of bytes currently pooled and available for reuse. |
Attribute | Type | Description | Examples | Presence |
---|---|---|---|---|
owner |
string | The name of the library or subsystem using the memory pool instance. | kestrel ; iis |
if owner is specified when the memory pool is created. |
aspnetcore.memorypool.allocated
Name | Instrument Type | Unit | Description |
---|---|---|---|
aspnetcore.memorypool.allocated |
Counter | By |
Total number of bytes allocated by the memory pool. Allocation occurs when a memory rental request exceeds the available pooled memory. |
Attribute | Type | Description | Examples | Presence |
---|---|---|---|---|
owner |
string | The name of the library or subsystem using the memory pool instance. | kestrel ; iis |
if owner is specified when the memory pool is created. |
aspnetcore.memorypool.evicted
Name | Instrument Type | Unit | Description |
---|---|---|---|
aspnetcore.memorypool.evicted |
Counter | By |
Total number of bytes evicted from the memory pool. Eviction occurs when idle pooled memory is reclaimed. |
Attribute | Type | Description | Examples | Presence |
---|---|---|---|---|
owner |
string | The name of the library or subsystem using the memory pool instance. | kestrel ; iis |
if owner is specified when the memory pool is created. |
aspnetcore.memorypool.rented
Name | Instrument Type | Unit | Description |
---|---|---|---|
aspnetcore.memorypool.rented |
Counter | By |
Total number of rented bytes from the pool. |
Attribute | Type | Description | Examples | Presence |
---|---|---|---|---|
owner |
string | The name of the library or subsystem using the memory pool instance. | kestrel ; iis |
if owner is specified when the memory pool is created. |
Microsoft.AspNetCore.Connections.Abstractions.dll
namespace Microsoft.AspNetCore.Connections;
public interface IMemoryPoolFactory
{
- MemoryPool<byte> CreatePool();
+ MemoryPool<byte> CreatePool(MemoryPoolOptions? options = null);
}
// Maybe not sealed to allow custom factory impls to pass through custom options?
+ public sealed class MemoryPoolOptions
+ {
+ public string? Owner { get; set; }
+ }
Usage
public class MyBackgroundService : BackgroundService
{
private readonly MemoryPool<byte> _memoryPool;
public MyBackgroundService(IMemoryPoolFactory factory)
{
_memoryPool = factory.CreatePool(new MemoryPoolOptions() { Owner = "BackgroundService" });
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
try
{
await Task.Delay(20, stoppingToken);
var rented = _memoryPool.Rent(100);
rented.Dispose();
}
catch (OperationCanceledException)
{
return;
}
}
}
}
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions