ASP.NET MVC为什么我的应用程序会继续重启?

时间:2022-04-29 20:57:53

I have an ASP.NET MVC website that gets about 6500 hits a day, on a shared hosting platform at Server Intellect. I keep seeing app restarts in the logs and I cannot figure out why.

我有一个ASP.NET MVC网站,每天在Server Intellect的共享主机平台上获得大约6500次点击。我一直在日志中看到app重启,我无法弄清楚原因。

I've read Scott Gu's article here: http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx and implemented the technique, and here's what shows up in my log:

我在这里阅读了Scott Gu的文章:http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx并实现了这项技术,以下是我日志中显示的内容:

Application Shutdown: 
_shutDownMessage=HostingEnvironment initiated shutdown 
HostingEnvironment caused shutdown    
_shutDownStack=at
System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)     at 
System.Environment.get_StackTrace()     at 
System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()     at 
System.Web.Hosting.HostingEnvironment.InitiateShutdown()     at 
System.Web.Hosting.PipelineRuntime.StopProcessing()

It seems to occur about every five minutes.

它似乎每五分钟发生一次。

Are there any other ways to debug this?

有没有其他方法来调试这个?

UPDATE: Here are the application pool settings mentioned by Softion:

更新:以下是Softion提到的应用程序池设置:

CPU

*处理器

  • Limit : 0
  • 限制:0
  • Limit Action : no action
  • 限制行动:不采取行动
  • Limit Interval : 5 Minutes
  • 限制间隔:5分钟

Process Model

过程模型

  • Idle Timeout : 20 Minutes
  • 空闲超时:20分钟
  • Ping Maximum Response Time : 90 Seconds
  • Ping最长响应时间:90秒
  • Startup Time Limit : 90 Seconds
  • 启动时间限制:90秒

Rapid-Fail Protection

快速失败保护

  • Enabled : True
  • 启用:True
  • Failure Interval : 5 Minutes
  • 故障间隔:5分钟

Recycling

回收

  • Private Memory Limit : 100 MB
  • 专用内存限制:100 MB
  • Regular Time Interval : 1740 Minutes (29 Hours)
  • 常规时间间隔:1740分钟(29小时)
  • Request Limit : 0
  • 请求限制:0
  • Specific Times : none
  • 具体时间:没有
  • Virtual Memory Limit : 0
  • 虚拟内存限制:0

4 个解决方案

#1


29  

You can easily grab the reason of the shutdown by HostingEnvironment. You read Scott Gu article, but you missed its comments.

您可以通过HostingEnvironment轻松获取关闭的原因。您阅读了Scott Gu的文章,但您错过了它的评论。

     var shutdownReason = HostingEnvironment.ShutdownReason;

ASP.NET MVC为什么我的应用程序会继续重启?

If the reason is HostingEnvironment, check the IIS application pool parameters controlling recycling. I've put a red dot near each one. Check the description in the bottom help box in your own copy for full info.

如果原因是HostingEnvironment,请检查控制回收的IIS应用程序池参数。我在每个附近放了一个红点。请查看您自己副本底部帮助框中的说明以获取完整信息。

You can ask your provider to give you the applicationHost.config file where all these parameters are set. They find it in C:\Windows\System32\inetsrv\config. I'm sure you can also get them using some .NET api.

您可以要求您的提供商为您提供applicationHost.config文件,其中设置了所有这些参数。他们在C:\ Windows \ System32 \ inetsrv \ config中找到它。我相信你也可以使用一些.NET API来获取它们。

ASP.NET MVC为什么我的应用程序会继续重启?

For 6500 hits a day, which is a very low hit rate, i'm betting the "Idle time-out" is set to 5mn.

对于每天6500次点击,这是一个非常低的命中率,我打赌“空闲超时”设置为5mn。

Update (moved comments to here //jgauffin)

  • CPU Limit 0 = disabled.
  • CPU Limit 0 =禁用。
  • Process Model Idle Timeout : 20 Minutes (20mn without a request recycles your app).
  • 进程模型空闲超时:20分钟(没有请求的20分钟回收您的应用程序)。
  • Rapid-Fail Protection enabled (5mn). You need to know the maximum failures count. If your app throws more than this exception count in 5mn it will we recycled.
  • 启用快速失效保护(5mn)。您需要知道最大故障数。如果您的应用程序在5mn内引发超过此异常计数,我们将进行回收。
  • Private Memory Limit : 100 MB. Yes you should profile, this is a low limit.
  • 专用内存限制:100 MB。是的你应该描述,这是一个下限。
  • Regular Time Interval : 1740 Minutes (29 Hours): it will recycle every 29h.
  • 常规时间间隔:1740分钟(29小时):每29小时回收一次。
  • Request Limit : 0 (disabled).
  • 请求限制:0(禁用)。
  • Virtual Memory Limit : 0 (disabled).
  • 虚拟内存限制:0(禁用)。
  • Rapid-Fail Protection enabled (5mn). You need the maximum failures count. If your app throws more than this exception count in 5mn it recycles. If it recycles every 5mn this should be the thing to check. There should be 0 unhandled exception in secondary worker threads. Wrap your code into a try catch there.
  • 启用快速失效保护(5mn)。您需要最大的故障数。如果您的应用程序在5mn内投掷超过此异常计数,则会进行回收。如果它每隔5百万回收一次,这应该是要检查的东西。在辅助工作线程中应该有0个未处理的异常。将代码包装到try catch中。

#2


3  

re update:

重新更新:

The settings asked to the provider help, but is way better to ask for information on the reason of the restarts like I mentioned on my original answer i.e. the actual log entries of the restarts like I mentioned on my orig answer. From those you can know specifically what was triggered, I've seen happen one hitting different limits.

设置要求提供者帮助,但是更好地询问有关重启原因的信息,就像我在原始答案中提到的那样,即我在orig答案中提到的重启的实际日志条目。从那些你可以特别知道被触发的东西,我看到发生了一个达到不同的限制。

You really have to:

你真的必须:

profile your application with a realistic amount of test data

使用实际数量的测试数据来分析您的应用程序


My money is on hitting resource limits set by your hosting provider.

我的钱是在达到您的托管服务提供商设置的资源限制。

Before going crazy with optimization without a target, contact your provider and ask them to give you information on the restarts.

在没有目标的情况下进行优化之前,请联系您的提供商并要求他们为您提供有关重启的信息。

Typical recycles:

典型的回收:

  • idle x amount of time / like 15 mins
  • 闲置x时间/ 15分钟
  • more than x amount of memory / like 200 MB
  • 超过x内存量/ 200 MB
  • more than x % processor over y time / like 70 over 1 minute
  • 超过x%处理器超过y时间/喜欢70超过1分钟
  • a daily recycle
  • 每日回收

Once you know the case, you have to find out what's taking those resources. For this you have to profile your application with a realistic amount of test data. Knowing if it is memory or processor can help on knowing what to look for.

一旦你知道了这个案例,你就必须找出那些资源。为此,您必须使用实际数量的测试数据来分析您的应用程序。知道它是内存还是处理器有助于了解要查找的内容。

#3


1  

Is IIS set to recycle the app pool frequently?

IIS是否设置为经常回收应用程序池?

Is there some kind of runaway memory leak in the app pool?

应用程序池中是否存在某种失控的内存泄漏?

#4


1  

It requires a bit of know how on what your app does here's a list of things that can cause the app to restart/reset or even shut down

它需要一些知道你的应用程序在这里做什么的列表,可以导致应用程序重新启动/重置甚至关闭

  • *Exception
  • *Exception
  • OutOfMemoryException
  • OutOfMemoryException异常
  • Any unhandled exception that crashes a thread
  • 任何崩溃线程的未处理异常
  • CodeContracts use Environment.FailFast when a contract violation occurs
  • CodeContracts在发生合同违规时使用Environment.FailFast

Exceptions are quite easy to track if you can reproduce the issue with a debugger attached you can go into Visual Studio and enable all exceptions when they are thrown not caught by user code. It will sometimes reveal intresting stuff that otherwise is hidden away.

如果您可以使用附加的调试器重现问题,则可以很容易地跟踪异常,您可以进入Visual Studio并在抛出未被用户代码捕获的所有异常时启用它们。它有时会揭示有趣的东西,否则就会隐藏起来。

#1


29  

You can easily grab the reason of the shutdown by HostingEnvironment. You read Scott Gu article, but you missed its comments.

您可以通过HostingEnvironment轻松获取关闭的原因。您阅读了Scott Gu的文章,但您错过了它的评论。

     var shutdownReason = HostingEnvironment.ShutdownReason;

ASP.NET MVC为什么我的应用程序会继续重启?

If the reason is HostingEnvironment, check the IIS application pool parameters controlling recycling. I've put a red dot near each one. Check the description in the bottom help box in your own copy for full info.

如果原因是HostingEnvironment,请检查控制回收的IIS应用程序池参数。我在每个附近放了一个红点。请查看您自己副本底部帮助框中的说明以获取完整信息。

You can ask your provider to give you the applicationHost.config file where all these parameters are set. They find it in C:\Windows\System32\inetsrv\config. I'm sure you can also get them using some .NET api.

您可以要求您的提供商为您提供applicationHost.config文件,其中设置了所有这些参数。他们在C:\ Windows \ System32 \ inetsrv \ config中找到它。我相信你也可以使用一些.NET API来获取它们。

ASP.NET MVC为什么我的应用程序会继续重启?

For 6500 hits a day, which is a very low hit rate, i'm betting the "Idle time-out" is set to 5mn.

对于每天6500次点击,这是一个非常低的命中率,我打赌“空闲超时”设置为5mn。

Update (moved comments to here //jgauffin)

  • CPU Limit 0 = disabled.
  • CPU Limit 0 =禁用。
  • Process Model Idle Timeout : 20 Minutes (20mn without a request recycles your app).
  • 进程模型空闲超时:20分钟(没有请求的20分钟回收您的应用程序)。
  • Rapid-Fail Protection enabled (5mn). You need to know the maximum failures count. If your app throws more than this exception count in 5mn it will we recycled.
  • 启用快速失效保护(5mn)。您需要知道最大故障数。如果您的应用程序在5mn内引发超过此异常计数,我们将进行回收。
  • Private Memory Limit : 100 MB. Yes you should profile, this is a low limit.
  • 专用内存限制:100 MB。是的你应该描述,这是一个下限。
  • Regular Time Interval : 1740 Minutes (29 Hours): it will recycle every 29h.
  • 常规时间间隔:1740分钟(29小时):每29小时回收一次。
  • Request Limit : 0 (disabled).
  • 请求限制:0(禁用)。
  • Virtual Memory Limit : 0 (disabled).
  • 虚拟内存限制:0(禁用)。
  • Rapid-Fail Protection enabled (5mn). You need the maximum failures count. If your app throws more than this exception count in 5mn it recycles. If it recycles every 5mn this should be the thing to check. There should be 0 unhandled exception in secondary worker threads. Wrap your code into a try catch there.
  • 启用快速失效保护(5mn)。您需要最大的故障数。如果您的应用程序在5mn内投掷超过此异常计数,则会进行回收。如果它每隔5百万回收一次,这应该是要检查的东西。在辅助工作线程中应该有0个未处理的异常。将代码包装到try catch中。

#2


3  

re update:

重新更新:

The settings asked to the provider help, but is way better to ask for information on the reason of the restarts like I mentioned on my original answer i.e. the actual log entries of the restarts like I mentioned on my orig answer. From those you can know specifically what was triggered, I've seen happen one hitting different limits.

设置要求提供者帮助,但是更好地询问有关重启原因的信息,就像我在原始答案中提到的那样,即我在orig答案中提到的重启的实际日志条目。从那些你可以特别知道被触发的东西,我看到发生了一个达到不同的限制。

You really have to:

你真的必须:

profile your application with a realistic amount of test data

使用实际数量的测试数据来分析您的应用程序


My money is on hitting resource limits set by your hosting provider.

我的钱是在达到您的托管服务提供商设置的资源限制。

Before going crazy with optimization without a target, contact your provider and ask them to give you information on the restarts.

在没有目标的情况下进行优化之前,请联系您的提供商并要求他们为您提供有关重启的信息。

Typical recycles:

典型的回收:

  • idle x amount of time / like 15 mins
  • 闲置x时间/ 15分钟
  • more than x amount of memory / like 200 MB
  • 超过x内存量/ 200 MB
  • more than x % processor over y time / like 70 over 1 minute
  • 超过x%处理器超过y时间/喜欢70超过1分钟
  • a daily recycle
  • 每日回收

Once you know the case, you have to find out what's taking those resources. For this you have to profile your application with a realistic amount of test data. Knowing if it is memory or processor can help on knowing what to look for.

一旦你知道了这个案例,你就必须找出那些资源。为此,您必须使用实际数量的测试数据来分析您的应用程序。知道它是内存还是处理器有助于了解要查找的内容。

#3


1  

Is IIS set to recycle the app pool frequently?

IIS是否设置为经常回收应用程序池?

Is there some kind of runaway memory leak in the app pool?

应用程序池中是否存在某种失控的内存泄漏?

#4


1  

It requires a bit of know how on what your app does here's a list of things that can cause the app to restart/reset or even shut down

它需要一些知道你的应用程序在这里做什么的列表,可以导致应用程序重新启动/重置甚至关闭

  • *Exception
  • *Exception
  • OutOfMemoryException
  • OutOfMemoryException异常
  • Any unhandled exception that crashes a thread
  • 任何崩溃线程的未处理异常
  • CodeContracts use Environment.FailFast when a contract violation occurs
  • CodeContracts在发生合同违规时使用Environment.FailFast

Exceptions are quite easy to track if you can reproduce the issue with a debugger attached you can go into Visual Studio and enable all exceptions when they are thrown not caught by user code. It will sometimes reveal intresting stuff that otherwise is hidden away.

如果您可以使用附加的调试器重现问题,则可以很容易地跟踪异常,您可以进入Visual Studio并在抛出未被用户代码捕获的所有异常时启用它们。它有时会揭示有趣的东西,否则就会隐藏起来。