Gautham Srinivasan
Gautham Srinivasan

Reputation: 308

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.

Upvotes: 13

Views: 7580

Answers (2)

mrapi
mrapi

Reputation: 6023

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

enter image description here

Upvotes: 2

Jeff
Jeff

Reputation: 1727

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

Upvotes: 6

Related Questions