我是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请求
发布评论