加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – .NET中的堆栈溢出将IIS发送到100%的CPU使用率 – 为

发布时间:2020-12-15 23:34:55 所属栏目:asp.Net 来源:网络整理
导读:我在Server 2008 R2 IIS 7.5上运行的ASP.NET应用程序中有一些代码.每当我加载一个特定页面,它将永久挂起,并将IIS发送到100%的CPU使用率.我最终跟踪了这个问题. public string Comments{ get { return this.Comments; }} 糟糕 – 应该已经返回this.Photo.Com
我在Server 2008 R2 IIS 7.5上运行的ASP.NET应用程序中有一些代码.每当我加载一个特定页面,它将永久挂起,并将IIS发送到100%的CPU使用率.我最终跟踪了这个问题.
public string Comments
{
    get { return this.Comments; }
}

糟糕 – 应该已经返回this.Photo.Comments.所以我的问题是,为什么.NET不会生成一个StackOverflowException,而是让IIS以100%的CPU运行的时间远远超过了应用程序的时间.在我使用.NET编程的经验中,在执行上述操作时,需要几秒甚至更少的时间才能获得StackOverflowException.那么在IIS上还能运行几乎30分钟呢?

解决方法

可能的JIT编译器优化了一个方法调用YourClass :: get_Comments()(这是IL将是什么样子),并内联代码与jmp(或任何x86汇编程序将是)循环构造,因为没有任何值被传递.只是一个想法.

这篇旧文章值得一看:

07000

“A typical example of a really good
candidate for inlining is a property
getter/setter. These are usually
really small methods that usually just
do a memory fetch or store,so it’s
usually a size and speed win to inline
them.”

正如:

07001

我也用一个简单的控制台应用程序来转载:

class Program
{
  static void Main(string[] args)
  {
    MyClass mc = new MyClass();
    string s = mc.Comments;
  }
}

public class MyClass
{
  public string  Comments
  {
    get { return this.Comments; }
  }
}

在关闭优化的调试模式下,我收到一个堆栈溢出异常.打开Jit Optimisations并编译发布版本后,该应用程序将永远运行.这表明可能发生了一个循环的内联.

C#2.0,3.0和4.0也是如此.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读