gpt4 book ai didi

angular - Asp.net core 2.2 在第一次请求时变慢

转载 作者:太空狗 更新时间:2023-10-29 18:00:14 25 4
gpt4 key购买 nike

第一个请求需要时间才能到达服务器 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";
});
}

需要注入(inject) 100 多个服务,需要时间进行预构建。

最佳答案

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

如果你在Advanced Settings下设置了ApplicationPool的Start Mode,它应该可以在你调用它的任何时候使用,除非你碰巧在回收时调用它正在发生。

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

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

Advanced Settings Start Mode

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

  1. 找到回收标题
  2. 将常规时间间隔(分钟)更改为 0
  3. 展开 Specific Times 并单击显示 TimeSpan[] Array 的 ...
  4. 在新对话框中选择营业时间以外的静态时间进行刷新。

enter image description here

关于angular - Asp.net core 2.2 在第一次请求时变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56357377/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com