iis-7 - IIS7 模块 - 托管还是 native ?

标签 iis-7 module unmanaged native managed


由于旧的ISAPI过滤器迟早要消亡,我想将IIS 6中使用的旧ISAPI过滤器重写为IIS 7中使用的模块。该模块将在全局范围内使用,这意味着它将在每个站点中使用,在安装了 IIS 7.5 的 Windows Server 2008 R2 上,它将托管数千个网站并管理大约 50 个应用程序池。
我现在的问题是我应该用托管代码还是非托管代码编写该模块?我对托管代码的担忧之一是 .NET 框架开销导致的大量内存消耗。我不知道这将如何影响服务器的性能。
我已经用托管代码和非托管代码编写了模块。所以这不是困扰我的决定。但如果没有很大的缺点,我更愿意用 C# 编写模块。
关于这个问题有什么建议吗?

最佳答案

里克·斯特拉尔 offered sound advice关于这个主题,我在 learn.iis.net 的文章中看到了多次回应。

It’s also important to understand the potential for doing the wrong thing with all of this power. First keep in mind that managed code is slower than native code in the Web server. By introducing managed code into the core server you are slowing down the performance of the Web server. Specifically, the context switches between managed and unmanged code are expensive when running in Integrated Mode and with managed modules present. I’ve talked to some of the Microsoft developers, and they are taking a hard look at optimizing these context switches by trying to batch calls to managed code components as much as possible, staying in managed code as long as possible.

Managed code is optional by default-all the core modules are native code, so adding managed modules is an explicit decision you have to make. If you’re already using ASP.NET then this decision is probably a no-brainer. But if you’re running raw ISAPI extensions or modules today, you’ll probably have to take a long hard look to see whether managed code is going to be a good fit in terms of performance.

简而言之,如果所有应用程序都是 ASP.NET,那么为 IIS 编写托管模块的开销应该很少或没有开销 - 一个简单的选择。

但是,如果网站不会以其他方式加载 CLR,那么为了执行您的模块而这样做的成本将很高,您需要仔细考虑(衡量!)影响以确定性能损失是否值得开发时间生产力的提高。

关于iis-7 - IIS7 模块 - 托管还是 native ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2454719/

相关文章:

c++ - 在非托管 C/C++ 中获取已签名 EXE 的 X509 代码签名证书序列号

c# - 可以作为参数传递给 POST 方法的对象的最大大小

asp.net - IIS 7.5 32 位应用程序池以 64 位启动

html - 自定义 HTML 模块 - 不支持 joomla 3.0

python - 为什么模块不可调用

java - 如何从 2 个不同的父项创建 Maven 模块?

c# - 如何在 C# 中编码(marshal)指向一系列以 null 结尾的字符串的指针?

jestjs - 如何使用 cls Hook 的非托管事务?

IIS URL 重写模块 - 更改查询字符串参数值

javascript - 当我在 IIS7 中托管应用程序时,CSS 和 Javascripts 未加载