Asp.net core 2对CORS预检请求的响应速度慢 [英] Asp.net core 2 Slow response to CORS preflight requests

查看:244
本文介绍了Asp.net core 2对CORS预检请求的响应速度慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个asp.net core 2服务器. 在性能测试中,当我们有几个(例如数十个)待处理请求时,新的CORS预检请求将保持待处理状态.

We have an asp.net core 2 server. In performance tests, when we have a few (say tens of) pending requests, new CORS preflight requests stay pending.

asp.net核心似乎对管道中的并发请求数有一定的限制,并且该限制的默认值非常低.

It appears that asp.net core has a certain limit on the number of concurrent requests in pipeline, and the default value for that limit is very low.

关于这些与性能相关的主题是否有任何资源? 有办法确定请求的优先级吗?

Is there any resources about these performance related topics? Is there a way to prioritize requests?

当然,在优化其他请求之后,此问题将更难重现,因此我们希望对此有所了解.

Of course, after we optimize the other requests, this problem will get harder to reproduce, so we want to understand it well enough.

推荐答案

我回答了一个与基准测试有关的类似问题 此处.

I had answered a similar question related to benchmarking performance for ASP.NET Core Kestrel here.

简而言之,您可以删除导致瓶颈的中间件,或者至少可以帮助您诊断罪魁祸首.

In short, you could remove the middleware that is causing the bottlenecks, or at least this could help you diagnose the culprit.

订购
中间件组件在Configure方法中添加的顺序定义了在请求时调用它们的顺序,以及响应的相反顺序. 此顺序对于安全性,性能和功能至关重要.

Ordering
The order that middleware components are added in the Configure method defines the order in which they are invoked on requests, and the reverse order for the response. This ordering is critical for security, performance, and functionality.

------来源:


短路

您可以通过不调用next参数来短路请求管道以处理性能优化(或测试).例如:


Short-Circuiting

You can short-circuit the request pipeline to handle performance optimizations (or testing) by not calling the next parameter. For example:

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
    }
}

这篇关于Asp.net core 2对CORS预检请求的响应速度慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆