Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net core 2.2 slow upon first request

The first request takes time to hit the server API method because it pre-building the services in a start-up task can anyone suggest me to reduce the initial latency of my first request after published in IIS

 // This method gets called by the runtime. 
            // Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
               services.AddTransient<IContactService, ContactService>();
               services.AddTransient<IPersonService, PersonService>();
               services.AddTransient<IDashboardService, DashboardService>();
               services.AddTransient<IEmployeeService, EmployeeService>();
               services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

                // In production, the React files will be served from this directory
                services.AddSpaStaticFiles(configuration =>
                {
                    configuration.RootPath = "ClientApp/build";
                });
            }

Need to inject more than 100 services its taking time to prebuilding.

like image 656
Gautham Srinivasan Avatar asked May 29 '19 09:05

Gautham Srinivasan


People also ask

Why is my ASP.NET site so slow?

An IIS or ASP.NET hang can cause your website to have slow page loads, timeouts, or 503 Service Unavailable errors. Hangs can be caused by blocked ASP.NET threads, bad configuration, or request queueing.

Is .NET Core faster than node JS?

NET Core has an easier time working with CPU-intensive tasks and rendering static pages since the in-built IIS server kernel caching makes this process very straightforward. Therefore, . NET core vs node. js performance offers different advantages for various projects.

How many requests per second can ASP.NET Core handle?

7+ Million HTTP requests per second from a single server.


2 Answers

This might be an issue with your IIS configuration as the Application Pool is recycled from inactivity.

If you set the ApplicationPool's Start Mode under Advanced Settings it should be ready to be used whenever you call it, unless you happen to call it just as the recycling is happening.

This can be found by:

  1. Open IIS
  2. Locate Application Pools under your server root
  3. Right-click the specific Application Pool you want to change
  4. Choose Advanced Settings
  5. Change Start Mode to AlwaysRunning

Advanced Settings Start Mode

For the latter issue of it recycling whenever it wants to (every 29 hours), you can schedule the recycle to happen at a set time to be unobtrusive. On the same Advanced Settings screen:

  1. Location the Recycling heading
  2. Change Regular Time Interval (minutes) to 0
  3. Expand Specific Times and click the ... where it says TimeSpan[] Array.
  4. In the new dialog choose a static time outside of operating hours for the refresh.

enter image description here

like image 132
Jeff Avatar answered Oct 22 '22 16:10

Jeff


for me setting Idle Timeout to a higher value solved the problem

enter image description here

like image 2
mrapi Avatar answered Oct 22 '22 16:10

mrapi