使用全局程序集缓存提高速度

发布于 2024-07-23 06:28:49 字数 189 浏览 7 评论 0原文

如果我有 1000 个 asp.net 网站,每个网站的 /bin 文件夹中有 30 个 DLL。

因此有 30,000 个 DLL。

如果我将一组 DLL 注册到全局程序集缓存中并且每个站点都使用 GAC 中的 DLL,网站/Web 服务器/计算机是否会运行得更快?

例如,网站总共使用的内存会更少吗?

If I had a 1000 asp.net websites each with 30 DLL's in their /bin folders.

Therefore 30,000 DLL's.

Would the websites / web server / machine run faster if I registered one set of the DLL's into the Global Assembly Cache and each site used the DLL's in the GAC?

e.g. would the websites collectively use less memory?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

葬心 2024-07-30 06:28:49

即使程序集位于 GAC 中,它们仍会从 GAC 中单独加载到内存中以提供隔离。 换句话说,仅仅因为程序集位于 GAC 中并不意味着这些副本可以跨 AppDomain 共享。 我相信 mscorlib(可能还有一些 BCL 程序集)可以在 AppDomain 之间共享,但您或我编写的任何程序集都不会。

但这是一件好事:考虑一下 缓存类型在AppDomains之间共享。

Even though assemblies are in the GAC they will still be loaded from there into memory separately to provide isolation. In other words, just because assemblies are in the GAC doesn't mean that those copies are shared across AppDomains. I believe that mscorlib (and possibly a few of the BCL assemblies) can be shared across AppDomains but any assemblies you or I write will not be.

This is a good thing however: consider the implications of the Cache type being shared across AppDomains.

呆° 2024-07-30 06:28:49

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

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

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

这一点也得到了 Tess Ferrandez(微软的内存和性能专家 - https://blogs.msdn.microsoft.com/tess/2006/04/12/asp-net-memory-you-use-the-same-dll-在多个应用程序中确实有必要多次加载)。

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

我自己也通过在 x64 WebAPI 服务上进行测试(WinDbg、任务管理器和 ProcExplorer)来证实这一点。 您会发现 GAC 应用程序的私有工作集较低。 对于 NGen,您将再次看到私有工作集减少。 然而,与基线相比,NGen 应用程序中的页面错误也大大减少了(在我的测试中几乎减少了一半)。 我发现 GAC 应用程序和非 GAC 应用程序之间的页面错误没有区别。

请注意,在某些情况下,最佳解决方案是通过将 NGen 的程序集安装到 GAC 中来组合 NGen 和 GAC。 这优化了共享程序集的应用程序之间的内存使用,并在应用程序启动时提供性能提升!

Actually, the accepted answer from @AndrewHare is 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!

毁梦 2024-07-30 06:28:49

实际上,这会快得多,特别是如果它们也是 NGEN 的话。 如果您进行 NGEN 而不将它们放入全局程序集缓存中,那么您实际上会减慢速度,因为 CLR 需要执行程序集验证以确保它与本机映像匹配。 CLR 会跳过对 GAC 程序集的检查,而仅加载和使用本机映像。

NGEN 程序集还具有内存优势,因为它们可以共享代码页。

您还可以考虑尝试优化 DLL 的基址,因为如果它们都使用默认值,那么 Windows 需要变基 30,000 次!

这是一篇关于 NGEN 性能优势的精彩文章。

http://msdn.microsoft.com/en-us/magazine/cc163610。 ASPX

Actually this would be much faster, particular if they are NGEN'd as well. If you NGEN without putting them in the Global Assembly Cache then you will actually slow things down because the CLR will need to perform verification of the assembly to ensure that it matches the native image. The CLR skips this check for GAC'd assemblies and will simply load and use the native image.

There are also memory benefits to NGEN'd assemblies because they can share code pages.

You might also consider trying to optimize the base addresses of the DLL's because if they're all using the default, then Windows needs to rebase 30,000 times!

Here's a great article on performance benefits of NGEN.

http://msdn.microsoft.com/en-us/magazine/cc163610.aspx

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