asp.net core how can I stop http request from locking

寵の児 提交于 2019-12-20 03:19:32

问题


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

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

I am using the 5002 url .


回答1:


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!");
    });
}


来源:https://stackoverflow.com/questions/46627679/asp-net-core-how-can-i-stop-http-request-from-locking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!