DLL 部署到 GAC 中 100 个共享时是否会减少内存使用量?网络应用程序?

发布于 2024-11-08 08:04:08 字数 200 浏览 0 评论 0原文

我有一个为许多域托管的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

诗笺 2024-11-15 08:04:08

将 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.

隔岸观火 2024-11-15 08:04:08

正如 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.

谷夏 2024-11-15 08:04:08

实际上,@Oded 和 @LarsTruijens 接受的答案都是
不正确。将程序集放置在 GAC 中确实有助于减少内存使用。

Jeffrey Richter(来自 Wintellect,与 .NET 团队一起帮助设计 CLR)在他的书中证实了这一点通过 C# 的 CLR

将程序集安装到 GAC 中可以带来多种好处。 GAC 使许多应用程序能够共享程序集,总体上减少物理内存使用....

这一点也得到了 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 -需要多次加载)。

只要有可能,对多个 ASP.NET 应用程序使用的任何程序集都进行强命名并安装到全局程序集缓存 (GAC) 中。 这将减少内存消耗。

我自己也通过在 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#:

Installing assemblies into the GAC offers several benefits. The GAC enables many applications to share assemblies, reducing physical memory usage on the whole....

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).

Wherever possible strong name and install to the global assembly cache (GAC) any assemblies that are used by more than one ASP.NET application. This will reduce memory consumption.

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文