asp.net核心如何停止锁定的HTTP请求

编程入门 行业动态 更新时间:2024-10-27 03:40:04
本文介绍了asp核心如何停止锁定的HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是asp Core的新手,到目前为止,我还是喜欢它.我有一个非常简单的操作,该操作仅返回字符串"Hello World".我的问题是,我认为http请求正在锁定,这实际上在减慢速度,就像 ASP.NET应用程序可以处理来自单个进程的多个请求.我正在做负载测试,我的第一个请求是967毫秒,但是我的第100个请求却需要10927毫秒或10秒,这对于返回一个简单的字符串来说是非常长的.这是在发布模式下完成的.

I am new to asp Core and so far I like it . I have a very simple action that just returns a string "Hello World" . My problem is that I think that http request are locking which is really slowing things down essentially just like this ASP.NET application to serve multiple requests from a single process . I am doing load testing my first request is 967 milliseconds however my 100th request takes 10927 milliseconds or 10 seconds which is incredibly long to return a simple string . This is being done in release mode .

public string HomeStream() { return "Hello World"; }

我认为某些东西正在锁定http请求,因为第100个请求应该更快返回.任何建议将是巨大的.这是我的启动设置

I am thinking that something is locking http requests because the 100th request should return much sooner . Any suggestions would be great. This is my launch settings

{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "localhost:55556/", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "MyApp": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "localhost:5002/" } } }

我正在使用 5002 网址.

推荐答案

如果您要做的只是尝试返回一个简单的字符串并对基础主机进行负载测试,那么我建议您删除所有中间件和服务

If all you are doing is trying to return a simple string and load testing the underlying host then I would suggest you remove all the middleware and services

using System.Net; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; public static void Main(string[] args) { IWebHost host = new WebHostBuilder() .UseKestrel() .Configure(app => { // notice how we don't have app.UseMvc()? app.Map("/hello", SayHello); // <-- ex: "localhost/hello" }) .Build(); host.Run(); } private static void SayHello(IApplicationBuilder app) { app.Run(async context => { // implement your own response await context.Response.WriteAsync("Hello World!"); }); }

更多推荐

asp.net核心如何停止锁定的HTTP请求

本文发布于:2023-11-16 18:07:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606606.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:核心   asp   net   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!