diff --git a/aspnetcore/fundamentals/servers/kestrel.md b/aspnetcore/fundamentals/servers/kestrel.md index d4c1ef0dca1d..e29d1adfea3d 100644 --- a/aspnetcore/fundamentals/servers/kestrel.md +++ b/aspnetcore/fundamentals/servers/kestrel.md @@ -5,7 +5,7 @@ description: Learn about Kestrel, the cross-platform web server for ASP.NET Core monikerRange: '>= aspnetcore-3.1' ms.author: tdykstra ms.custom: mvc -ms.date: 08/25/2025 +ms.date: 12/04/2025 uid: fundamentals/servers/kestrel --- # Kestrel web server in ASP.NET Core @@ -33,7 +33,7 @@ Kestrel's features include: * Building a reverse proxy with [YARP](https://github.com/microsoft/reverse-proxy). * **Extensibility:** Customize Kestrel through configuration, middleware, and custom transports. * **Performance diagnostics:** Kestrel provides built-in performance diagnostics features, such as logging and metrics. -* **Memory management:** Kestrel includes features for efficient memory management, such as automatic eviction from memory pool. +* **Memory management:** Kestrel includes features for efficient memory management. For more information, see . ## Get started @@ -43,13 +43,6 @@ ASP.NET Core project templates use Kestrel by default when not hosted with IIS. For more information on configuring `WebApplication` and `WebApplicationBuilder`, see . -## Optional client certificates - -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). - - -[!INCLUDE[](includes/memory-eviction2.md)] - ## Additional resources diff --git a/aspnetcore/fundamentals/servers/kestrel/includes/kestrel6.md b/aspnetcore/fundamentals/servers/kestrel/includes/kestrel6.md index 3c43dd078ffc..733f32e39b29 100644 --- a/aspnetcore/fundamentals/servers/kestrel/includes/kestrel6.md +++ b/aspnetcore/fundamentals/servers/kestrel/includes/kestrel6.md @@ -1,4 +1,64 @@ -:::moniker range=">= aspnetcore-6.0 <=aspnetcore-9.0" +:::moniker range=">= aspnetcore-8.0 <= aspnetcore-9.0" + +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. + +Kestrel's features include: + +* **Cross-platform:** Kestrel is a cross-platform web server that runs on Windows, Linux, and macOS. +* **High performance:** Kestrel is optimized to handle a large number of concurrent connections efficiently. +* **Lightweight:** Optimized for running in resource-constrained environments, such as containers and edge devices. +* **Security hardened:** Kestrel supports HTTPS and is hardened against web server vulnerabilities. +* **Wide protocol support:** Kestrel supports common web protocols, including: + * HTTP/1.1, [HTTP/2](xref:fundamentals/servers/kestrel/http2) and [HTTP/3](xref:fundamentals/servers/kestrel/http3) + * [WebSockets](xref:fundamentals/websockets) +* **Integration with ASP.NET Core:** Seamless integration with other ASP.NET Core components, such as the middleware pipeline, dependency injection, and configuration system. +* **Flexible workloads**: Kestrel supports many workloads: + * ASP.NET app frameworks such as Minimal APIs, MVC, Razor pages, SignalR, Blazor, and gRPC. + * Building a reverse proxy with [YARP](https://github.com/microsoft/reverse-proxy). +* **Extensibility:** Customize Kestrel through configuration, middleware, and custom transports. +* **Performance diagnostics:** Kestrel provides built-in performance diagnostics features, such as logging and metrics. + +## Get started + +ASP.NET Core project templates use Kestrel by default when not hosted with IIS. In the following template-generated `Program.cs`, the method calls internally: + +:::code language="csharp" source="~/fundamentals/servers/kestrel/samples/6.x/KestrelSample/Program.cs" id="snippet_CreateBuilder" highlight="1"::: + +For more information on configuring `WebApplication` and `WebApplicationBuilder`, see . + +## Behavior with debugger attached + +The following timeouts and rate limits aren't enforced when a debugger is attached to a Kestrel process: + +* +* +* +* +* +* +* + +## Additional resources + + +* + +* + +* + +* + +* +* +* +* +* [RFC 9110: HTTP Semantics (Section 7.2: Host and :authority)](https://www.rfc-editor.org/rfc/rfc9110#field.host) +* When using UNIX sockets on Linux, the socket isn't automatically deleted on app shutdown. For more information, see [this GitHub issue](https://github.com/dotnet/aspnetcore/issues/14134). + +:::moniker-end + +:::moniker range=">= aspnetcore-6.0 < aspnetcore-8.0" Kestrel is a cross-platform [web server for ASP.NET Core](xref:fundamentals/servers/index). Kestrel is the web server that's included and enabled by default in ASP.NET Core project templates. @@ -21,10 +81,6 @@ ASP.NET Core project templates use Kestrel by default when not hosted with IIS. For more information on configuring `WebApplication` and `WebApplicationBuilder`, see . -## Optional client certificates - -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). - ## Behavior with debugger attached The following timeouts and rate limits aren't enforced when a debugger is attached to a Kestrel process: @@ -82,10 +138,6 @@ ASP.NET Core project templates use Kestrel by default when not hosted with IIS. For more information on building the host, see the *Set up a host* and *Default builder settings* sections of . -## Optional client certificates - -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). - ## Additional resources diff --git a/aspnetcore/fundamentals/servers/kestrel/memory-management.md b/aspnetcore/fundamentals/servers/kestrel/memory-management.md new file mode 100644 index 000000000000..5cddb2eb603a --- /dev/null +++ b/aspnetcore/fundamentals/servers/kestrel/memory-management.md @@ -0,0 +1,43 @@ +--- +title: Memory management in Kestrel +author: tdykstra +description: Learn about memory management in Kestrel, including automatic eviction from memory pools and using memory pool metrics. +monikerRange: '>= aspnetcore-10.0' +ms.author: tdykstra +ms.date: 12/04/2025 +uid: fundamentals/servers/kestrel/memory-management +--- + +# Memory management in Kestrel + +[!INCLUDE[](~/includes/not-latest-version.md)] + +By [Tom Dykstra](https://github.com/tdykstra) + +This article provides guidance for managing memory in Kestrel, including automatic eviction from memory pools and using memory pool metrics. + +## Automatic eviction from memory pool + +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. + +This automatic eviction feature reduces overall memory usage and helps applications stay responsive under varying workloads. In versions of .NET earlier than 10, memory allocated by the pool remained reserved even when not in use. + +### Use memory pool metrics + +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"`. + +For information about metrics and how to use them, see . + +## Manage memory pools + +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) interface and its default implementation, which are available through dependency injection. + +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: + +:::code language="csharp" source="~/fundamentals/servers/snippets/10.x/my-background-service.cs"::: + +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: + +:::code language="csharp" source="~/fundamentals/servers/snippets/10.x/memory-pool-factory.cs"::: + +When you're using a memory pool, be aware of the pool's . diff --git a/aspnetcore/toc.yml b/aspnetcore/toc.yml index 5881c94e8cdb..f07b27baa166 100644 --- a/aspnetcore/toc.yml +++ b/aspnetcore/toc.yml @@ -1190,6 +1190,9 @@ items: - name: Diagnostics displayName: diagnostics uid: fundamentals/servers/kestrel/diagnostics + - name: Memory management + displayName: memory, pool, kestrel + uid: fundamentals/servers/kestrel/memory-management - name: HTTP/2 displayName: deploy, publish, server, Kestrel uid: fundamentals/servers/kestrel/http2