ASP.NET MVC - 初始加载缓慢 [英] ASP.NET MVC - Slow initial load

查看:22
本文介绍了ASP.NET MVC - 初始加载缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近创建了一个 asp.net mvc Web 应用程序并在线发布.

I've recently created an asp.net mvc web application and published it online.

当第一次加载网站时,您应该会发现它实际显示大约需要 10-15 秒,但是在单击一次后,它的加载速度与我预期的第二次一样快.我只是想知道是否有人知道为什么网站需要这么长时间?

When first loading the website you should find that it takes around 10-15 seconds for it to actually show, however after it's clicked once, it loads as quickly as I expect the second time round. I'm just wondering if anyone may have an idea of why the website is taking so long?

推荐答案

通常情况下,应用程序域启动时,应用程序总是需要一些额外的时间来加载.

Typically an application will always take a little extra time to load as the application domain starts up.

从糟糕的代码(IE:Application_Start)到您可能正在使用的某些库(例如 ORM),可能会加剧这种情况.您加载了多少个模块?

Things helping exacerbate this could be anything from poorly written code (IE: Application_Start) to certain libraries you may be using (ORMs for example). How many modules do you have loaded?

首先检查你的 web.config 是否有臭名昭著的 <compilation debug="true">.这可能会对生产设置产生重大的性能影响.将其设置为假"!

For starters check your web.config for the infamous <compilation debug="true">. That can have significant performance ramifications in a production setup. Set it to "false"!

建议按照改善应用程序启动时间"的方式在谷歌上搜索一些内容,并寻找可能与您的特定应用程序相关的内容.

Recommend googling something along the lines of "improving application startup time" and looking for things that may relate to your particular application.

从您的第一条评论更新:

如果您看到应用程序在 30 分钟后再次启动(挂起几秒钟),这可能与您在 IIS 中的应用程序池回收设置有关.

If you're seeing the application start up again (hangs for a few seconds) after 30 minutes consistently this is likely related to your Application Pool Recycling settings in IIS.

进入 IIS 管理器(假设 v7+):

Go into IIS Manager (this assumes v7+):

  1. 应用程序池
  2. 右键单击用于您的应用程序的池
  3. 选择回收",会出现一个标有回收"的窗口条件"
  4. 检查这些设置,因为它们将决定何时自动终止您的应用程序池并让它重新启动.
  1. Application Pools
  2. Right click the pool being used for your application(s)
  3. Select "Recycling", a window will come up labeled "Recycling Conditions"
  4. Inspect those settings since they will determine when to automatically kill your app pool and have it restart.

就一般性能而言,您可能想尝试:

In terms of general performance you may want to try:

  1. 添加一些调试语句,在您的Application_Start() 方法或任何其他适用的位置尝试捕捉耗时最长的事情.
  2. 创建一个完全干净的演示项目并部署它.看看有没有遇到同样的问题.如果它不尝试引入更多以及更多真实代码,直到您发现速度变慢.

如果你真的难倒#2 可能是你最好的选择,即使它可能是最慢的选择.

If you're really stumped #2 may be your best bet even though it will be probably be the slowest option.

这篇关于ASP.NET MVC - 初始加载缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆