-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Caching per-request objects on reused HttpContexts #6895
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
Comments
Could have a cache that drops any object from the pool if it wasn't requested during that request; so it would only live on for 1 request (or a parameterised number e.g. if not used for x Requests then drop) |
I think resettable features is the feature here. A feature can opt into controlling creation and reset. |
That's a clever idea. Rather than putting that logic in Kestrel it could be something a feature could track internally e.g. each time the feature is reset it could increment an "unused" counter by 1. When it is used then "unused" counter goes back to zero. If counter exceeds a certain number then as part of the reset the heavy objects are culled (or could a feature remove itself from its HttpContext?).
What happens to features when the HttpContext is reused today? I don't know if this is a thing to worry about but imagine a web app that uses lots of middleware and app frameworks. Eventually there would be a lot of resettable features in the mix on the |
@JamesNK is there anything left here that we'd consider caching or does most of the perf work we did in 3.1/5.0 cover this? |
This is still useful IMO |
ASP.NET Core 3 adds HttpContext reuse - Reuse HttpContext object per HTTP/1 connection and HTTP/2 stream
App frameworks and middleware often have their own objects that are allocated every request. Instead of app frameworks/middleware caching with a shared object pool (creating thread contention), what opportunities are there for to cache lightweight per-request objects on
HttpContext
?Because cached objects would eventually be on every HttpContext this functionality should only be used for lightweight objects, and not something large like buffers.
e.g. generated gRPC methods have objects passed to them like a stream reader, stream writer and context -
Task SayHellos(HelloRequest request, IServerStreamWriter<HelloReply> responseStream, ServerCallContext context)
. These objects are mostly wrappers over the underlying HttpContext.HttpContext
. App framework will create and cache them if they don't exist, or reset the existing instances for the currentHttpContext
.The text was updated successfully, but these errors were encountered: