asp.net核心如何停止锁定的HTTP请求 [英] asp.net core how can I stop http request from locking
问题描述
我是asp.net Core的新手,到目前为止,我还是喜欢它.我有一个非常简单的操作,该操作仅返回字符串"Hello World".我的问题是,我认为http请求正在锁定,这实际上在减慢速度,就像
I am new to asp.net 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": "http://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": "http://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: "http://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请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!