DLL 部署到 GAC 中 100 个共享时是否会减少内存使用量?网络应用程序?
我有一个为许多域托管的 ASP.NET 应用程序,并且所有域都映射到相同的根文件夹,即代码库。如果我将当前位于 bin 文件夹中的 DLL 加载到 GAC 中,会占用更少的内存吗?将 DLL 加载到 GAC 中进行共享(安全方面除外)时需要考虑哪些特殊代码注意事项?
有什么方法可以使 DLL 在 .NET 环境中共享吗?
谢谢克里斯
I have an ASP.NET app hosted for many domains and all are mapped to the same root folder, i.e., code-base. Will it take less memeory if I load the DLLs currently located in bin folder into GAC? Any special code considerations to take to load DLLs into GAC for sharing (other than security aspect)?
Is there any way of making DLLs sharable in .NET environment?
Thank you
Kris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将 DLL 放入 GAC 对内存使用没有帮助。 DLL 仍然需要加载到每个应用程序域中,并且它们不会位于共享内存中。
使用 GAC 的目的是集中程序集的分发 - 因此可以在一个地方管理更改。听起来您仍然可以从中受益。
Putting the DLLs in the GAC will not help with memory usage. The DLLs still need to be loaded into each app domain, and they will not be in shared memory.
The point of using the GAC is to centralize distribution of assemblies - so changes can be managed in one place. Sounds like this is something that you could still benefit from.
正如 Oded 所解释的,仅仅将它们放入 GAC 中是没有帮助的。可能有帮助的是将它们放入 GAC 和 NGEN 程序集中。请参阅此处和此处。请务必测量不同的内存使用情况、加载时间和整体性能,因为这些可能会受到 NGEN 的负面影响。请参阅此处 和 此处。
As Oded explained just putting them in the GAC won't help. What might help is putting them into the GAC and NGEN the assemblies. See here and here. Be sure to measure the different memory usages, load times and overall performance, because those can be negatively influenced by NGEN. See here and here.
实际上,@Oded 和 @LarsTruijens 接受的答案都是
不正确。将程序集放置在 GAC 中确实有助于减少内存使用。
Jeffrey Richter(来自 Wintellect,与 .NET 团队一起帮助设计 CLR)在他的书中证实了这一点通过 C# 的 CLR:
这一点也得到了 Tess Ferrandez(Microsoft 的内存和性能专家 - https://blogs.msdn.microsoft.com/tess/2006/04/12/asp-net-memory-you-use-the-same-dll-in-multiple-applications-is-it-really -需要多次加载)。
我自己也通过在 x64 WebAPI 服务上进行测试(WinDbg、任务管理器和 ProcExplorer)来证实这一点。您会发现 GAC 应用程序的私有工作集较低。对于 NGen,您将再次看到私有工作集减少。然而,与基线相比,NGen 应用程序中的页面错误也大大减少了(在我的测试中几乎减少了一半)。我发现 GAC 应用程序和非 GAC 应用程序之间的页面错误没有区别。
请注意,在某些情况下,最佳解决方案是通过将 NGen 的程序集安装到 GAC 中来组合 NGen 和 GAC。这优化了共享程序集的应用程序之间的内存使用,并在应用程序启动时提供性能提升!
Actually, the accepted answer from @Oded and the other from @LarsTruijens are both
incorrect. Placing assemblies in the GAC DOES help reduce memory usage.
This is confirmed by Jeffrey Richter (from Wintellect who helped design the CLR with the .NET team) in his book CLR via C#:
It is also confirmed by Tess Ferrandez (Memory and Performance Guru from Microsoft's - https://blogs.msdn.microsoft.com/tess/2006/04/12/asp-net-memory-you-use-the-same-dll-in-multiple-applications-is-it-really-necessary-to-load-it-multiple-times).
I've also confirmed this myself by testing (WinDbg, Task Manager, and ProcExplorer) on a x64 WebAPI service as an example. You'd see that the Private Working Set is lower with the GAC'd app. In the case of NGen, you would again see the Private Working Set decreased. However, the Page Faults are also greatly reduced in the NGen'd app compared to the baseline (almost by half in my test). I saw no difference in Page Faults between the GAC'd app and non-GAC'd app.
Note that the best solution in some cases is to combine NGen and the GAC by installing NGen'd assemblies into the GAC. This optimizes memory usage between apps that share assemblies as well as providing a performance boost at application startup!