我们有一个 asp.net core 2 服务器。
在性能测试中,当我们有几个(例如数十个)待处理请求时,新的 CORS 预检请求将保持待处理状态。
看来asp.net core对管道中的并发请求数有一定的限制,并且该限制的默认值非常低。
是否有关于这些性能相关主题的资源?
有没有办法对请求进行优先级排序?
当然,在我们优化其他请求之后,这个问题会变得更难重现,所以我们想要充分理解它。
我曾经回答过一个类似的问题 https://stackoverflow.com/a/46627920/3645638与 ASP.NET Core Kestrel 的基准测试性能相关here https://stackoverflow.com/a/46627920/3645638.
简而言之,您可以删除导致瓶颈的中间件,或者至少这可以帮助您诊断罪魁祸首。
Ordering
中间件组件添加的顺序Configure
方法定义了它们在请求时调用的顺序,以及响应的相反顺序。此顺序对于安全性、性能和功能至关重要。
- - - 来源:Microsoft 文档:ASP.NET Core 中间件 https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware?tabs=aspnetcore2x#ordering
短路
您可以通过不调用来短路请求管道以处理性能优化(或测试)next
范围。例如:
public class Startup
{
public void Configure(IApplicationBuilder app)
{
// make sure you place this at the top
// the request pipeline will go in sequence
app.Use(async (context, next) =>
{
// do work for your special case, performance tests, etc
// in order to short-circuit the pipeline, do NOT call the next parameter
// so, you could place some kind of conditional here that will allow only
// specific requests to continue down/up the pipeline
if (!true)
{
await next.Invoke();
}
});
// the rest of the pipeline
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)