在第一次请求时,Asp.net Core 2.2变慢

时间:2019-05-29 09:32:30

标签: angular asp.net-core-2.0 c#-3.0 typescript2.0

第一个请求要花时间才能达到服务器API方法,因为它会在启动任务中预先构建服务,有人可以建议我减少第一个请求在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";
                });
            }

需要花费100多个时间来进行预建。

2 个答案:

答案 0 :(得分:1)

对我来说,将“空闲超时”设置为更高的值可以解决问题

enter image description here

答案 1 :(得分:0)

这可能是您的IIS配置存在的问题,因为应用程序池是从不活动中回收的。

如果在高级设置下设置了ApplicationPool的启动模式,则应在每次调用时准备使用它,除非您恰好在回收时调用它发生。

可以通过以下方式找到它:

  1. 打开IIS
  2. 在服务器根目录下找到应用程序池
  3. 右键单击要更改的特定应用程序池
  4. 选择高级设置
  5. 开始模式更改为始终运行

Advanced Settings Start Mode

对于后一问题,它会在需要时(每29小时)进行回收,您可以将回收安排在一定的时间进行,以免干扰。在同一高级设置屏幕上:

  1. 找到回收标题
  2. Change Regular Time Interval (minutes)到0
  3. 展开Specific Times,然后单击显示时间跨度[]数组的...
  4. 在新对话框中,选择营业时间以外的静态时间进行刷新。

enter image description here