Skip to content

Commit 03b401e

Browse files
Copilottdykstra
andcommitted
Create memory management article and update Kestrel overview
Co-authored-by: tdykstra <[email protected]>
1 parent 82ccbce commit 03b401e

File tree

4 files changed

+49
-18
lines changed

4 files changed

+49
-18
lines changed

aspnetcore/fundamentals/servers/kestrel.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn about Kestrel, the cross-platform web server for ASP.NET Core
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: tdykstra
77
ms.custom: mvc
8-
ms.date: 08/25/2025
8+
ms.date: 12/04/2025
99
uid: fundamentals/servers/kestrel
1010
---
1111
# Kestrel web server in ASP.NET Core
@@ -14,7 +14,7 @@ uid: fundamentals/servers/kestrel
1414

1515
By [Tom Dykstra](https://github.com/tdykstra), [Chris Ross](https://github.com/Tratcher), and [Stephen Halter](https://twitter.com/halter73)
1616

17-
:::moniker range=">= aspnetcore-10.0"
17+
:::moniker range=">= aspnetcore-8.0"
1818

1919
Kestrel is a cross-platform [web server for ASP.NET Core](xref:fundamentals/servers/index). Kestrel is the recommended server for ASP.NET Core, and it's configured by default in ASP.NET Core project templates.
2020

@@ -33,7 +33,7 @@ Kestrel's features include:
3333
* Building a reverse proxy with [YARP](https://github.com/microsoft/reverse-proxy).
3434
* **Extensibility:** Customize Kestrel through configuration, middleware, and custom transports.
3535
* **Performance diagnostics:** Kestrel provides built-in performance diagnostics features, such as logging and metrics.
36-
* **Memory management:** Kestrel includes features for efficient memory management, such as automatic eviction from memory pool.
36+
* **Memory management:** Kestrel includes features for efficient memory management. For more information, see <xref:fundamentals/servers/kestrel/memory-management>.
3737

3838
## Get started
3939

@@ -43,13 +43,6 @@ ASP.NET Core project templates use Kestrel by default when not hosted with IIS.
4343

4444
For more information on configuring `WebApplication` and `WebApplicationBuilder`, see <xref:fundamentals/minimal-apis>.
4545

46-
## Optional client certificates
47-
48-
For information on apps that must protect a subset of the app with a certificate, see [Optional client certificates](xref:security/authentication/certauth#optional-client-certificates).
49-
50-
51-
[!INCLUDE[](includes/memory-eviction2.md)]
52-
5346
## Additional resources
5447

5548
<a name="endpoint-configuration"></a>

aspnetcore/fundamentals/servers/kestrel/includes/kestrel6.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ ASP.NET Core project templates use Kestrel by default when not hosted with IIS.
2121

2222
For more information on configuring `WebApplication` and `WebApplicationBuilder`, see <xref:fundamentals/minimal-apis>.
2323

24-
## Optional client certificates
25-
26-
For information on apps that must protect a subset of the app with a certificate, see [Optional client certificates](xref:security/authentication/certauth#optional-client-certificates).
27-
2824
## Behavior with debugger attached
2925

3026
The following timeouts and rate limits aren't enforced when a debugger is attached to a Kestrel process:
@@ -82,10 +78,6 @@ ASP.NET Core project templates use Kestrel by default when not hosted with IIS.
8278

8379
For more information on building the host, see the *Set up a host* and *Default builder settings* sections of <xref:fundamentals/host/generic-host#set-up-a-host>.
8480

85-
## Optional client certificates
86-
87-
For information on apps that must protect a subset of the app with a certificate, see [Optional client certificates](xref:security/authentication/certauth#optional-client-certificates).
88-
8981
## Additional resources
9082

9183
<a name="endpoint-configuration"></a>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Memory management in Kestrel
3+
author: tdykstra
4+
description: Learn about memory management in Kestrel, including automatic eviction from memory pools and using memory pool metrics.
5+
monikerRange: '>= aspnetcore-8.0'
6+
ms.author: tdykstra
7+
ms.date: 12/04/2024
8+
uid: fundamentals/servers/kestrel/memory-management
9+
---
10+
11+
# Memory management in Kestrel
12+
13+
[!INCLUDE[](~/includes/not-latest-version.md)]
14+
15+
By [Tom Dykstra](https://github.com/tdykstra)
16+
17+
This article provides guidance for managing memory in Kestrel, including automatic eviction from memory pools and using memory pool metrics.
18+
19+
## Automatic eviction from memory pool
20+
21+
The memory pools used by Kestrel, IIS, and HTTP.sys automatically evict memory blocks when the application is idle or under low load. The feature runs automatically and doesn't need to be enabled or configured manually.
22+
23+
In versions of .NET earlier than 10, memory allocated by the pool remains reserved, even when not in use. This automatic eviction feature reduces overall memory usage and helps applications stay responsive under varying workloads.
24+
25+
### Use memory pool metrics
26+
27+
The default memory pool used by the ASP.NET Core server implementations includes metrics, which can be used to monitor and analyze memory usage patterns. The metrics are under the name `"Microsoft.AspNetCore.MemoryPool"`.
28+
29+
For information about metrics and how to use them, see <xref:log-mon/metrics/metrics>.
30+
31+
## Manage memory pools
32+
33+
Besides using memory pools efficiently by evicting unneeded memory blocks, ASP.NET Core provides a built-in [IMemoryPoolFactory](https://source.dot.net/#Microsoft.AspNetCore.Connections.Abstractions/IMemoryPoolFactory.cs) and an implementation. It makes the implementation available to your application through dependency injection.
34+
35+
The following code example shows a simple background service that uses the built-in memory pool factory implementation to create memory pools. These pools benefit from the automatic eviction feature:
36+
37+
:::code language="csharp" source="~/fundamentals/servers/snippets/10.x/my-background-service.cs":::
38+
39+
To use a custom memory pool factory, make a class that implements `IMemoryPoolFactory` and register it with dependency injection, as the following example does. Memory pools created this way also benefit from the automatic eviction feature:
40+
41+
:::code language="csharp" source="~/fundamentals/servers/snippets/10.x/memory-pool-factory.cs":::
42+
43+
When you're using a memory pool, be aware of the pool's <xref:System.Buffers.MemoryPool`1.MaxBufferSize>.

aspnetcore/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,9 @@ items:
11901190
- name: Diagnostics
11911191
displayName: diagnostics
11921192
uid: fundamentals/servers/kestrel/diagnostics
1193+
- name: Memory management
1194+
displayName: memory, pool, kestrel
1195+
uid: fundamentals/servers/kestrel/memory-management
11931196
- name: HTTP/2
11941197
displayName: deploy, publish, server, Kestrel
11951198
uid: fundamentals/servers/kestrel/http2

0 commit comments

Comments
 (0)