If I had a 1000 asp.net websites each with 30 DLL's in their /bin folders.
如果我有一个1000个asp.net网站,每个网站的/ bin文件夹中有30个DLL。
Therefore 30,000 DLL's.
因此有30,000个DLL。
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?
如果我将一组DLL注册到全局程序集缓存中并且每个站点在GAC中使用了DLL,那么网站/ Web服务器/机器会运行得更快吗?
e.g. would the websites collectively use less memory?
例如网站会集体使用更少的内存吗?
3 个解决方案
#1
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.
即使程序集在GAC中,它们仍然会从那里单独加载到内存中以提供隔离。换句话说,仅仅因为程序集在GAC中并不意味着这些副本在AppDomains之间共享。我相信mscorlib(可能还有一些BCL程序集)可以在AppDomains之间共享,但是你或我编写的任何程序集都不会。
This is a good thing however: consider the implications of the Cache type being shared across AppDomains.
但这是一件好事:考虑在AppDomains之间共享Cache类型的含义。
#2
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.
实际上这会更快,特别是如果它们也是NGEN的话。如果您没有将它们放入全局程序集缓存中,那么您实际上会减慢速度,因为CLR需要执行程序集的验证以确保它与本机映像匹配。 CLR跳过此检查以获取GAC程序集,并将简单地加载和使用本机映像。
There are also memory benefits to NGEN'd assemblies because they can share code pages.
NGEN程序集也有内存优势,因为它们可以共享代码页。
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!
您可能还会考虑尝试优化DLL的基地址,因为如果它们都使用默认值,那么Windows需要重新设置30,000次!
Here's a great article on performance benefits of NGEN.
这是关于NGEN性能优势的精彩文章。
#3
Actually, the accepted answer from @AndrewHare is incorrect. Placing assemblies in the GAC DOES help reduce memory usage.
实际上,来自@AndrewHare的接受答案是错误的。将程序集放置在GAC DOES中有助于减少内存使用量。
This is confirmed by Jeffrey Richter (from Wintellect who helped design the CLR with the .NET team) in his book CLR via C#:
Jeffrey Richter(来自Wintellect帮助设计CLR与.NET团队)在他的书CLR中通过C#证实了这一点:
Installing assemblies into the GAC offers several benefits. The GAC enables many applications to share assemblies, reducing physical memory usage on the whole....
将组件安装到GAC中可提供多种好处。 GAC使许多应用程序可以共享程序集,从而减少整体的物理内存使用量....
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).
Tess Ferrandez(微软的内存和性能大师)确认了这一点 - https://blogs.msdn.microsoft.com/tess/2006/04/12/asp-net-memory-you-use-the-same-dll -in-多的应用程序,是-IT-真的,有必要对负载-IT-多倍)。
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.
尽可能强名称并将全局程序集缓存(GAC)安装到多个ASP.NET应用程序使用的任何程序集中。这将减少内存消耗。
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.
我也通过在x64 WebAPI服务上测试(WinDbg,任务管理器和ProcExplorer)来证实这一点。您会看到GAC应用程序的私人工作集较低。在NGen的情况下,您将再次看到私人工作集减少。但是,与基线相比,NGen应用程序的页面错误也大大减少(在我的测试中几乎减少了一半)。我发现GAC应用和非GAC应用之间的页面错误没有区别。
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!
请注意,在某些情况下,最佳解决方案是通过将NGen'd程序集安装到GAC中来合并NGen和GAC。这可以优化共享程序集的应用程序之间的内存使用,并在应用程序启动时提供性能提升!
#1
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.
即使程序集在GAC中,它们仍然会从那里单独加载到内存中以提供隔离。换句话说,仅仅因为程序集在GAC中并不意味着这些副本在AppDomains之间共享。我相信mscorlib(可能还有一些BCL程序集)可以在AppDomains之间共享,但是你或我编写的任何程序集都不会。
This is a good thing however: consider the implications of the Cache type being shared across AppDomains.
但这是一件好事:考虑在AppDomains之间共享Cache类型的含义。
#2
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.
实际上这会更快,特别是如果它们也是NGEN的话。如果您没有将它们放入全局程序集缓存中,那么您实际上会减慢速度,因为CLR需要执行程序集的验证以确保它与本机映像匹配。 CLR跳过此检查以获取GAC程序集,并将简单地加载和使用本机映像。
There are also memory benefits to NGEN'd assemblies because they can share code pages.
NGEN程序集也有内存优势,因为它们可以共享代码页。
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!
您可能还会考虑尝试优化DLL的基地址,因为如果它们都使用默认值,那么Windows需要重新设置30,000次!
Here's a great article on performance benefits of NGEN.
这是关于NGEN性能优势的精彩文章。
#3
Actually, the accepted answer from @AndrewHare is incorrect. Placing assemblies in the GAC DOES help reduce memory usage.
实际上,来自@AndrewHare的接受答案是错误的。将程序集放置在GAC DOES中有助于减少内存使用量。
This is confirmed by Jeffrey Richter (from Wintellect who helped design the CLR with the .NET team) in his book CLR via C#:
Jeffrey Richter(来自Wintellect帮助设计CLR与.NET团队)在他的书CLR中通过C#证实了这一点:
Installing assemblies into the GAC offers several benefits. The GAC enables many applications to share assemblies, reducing physical memory usage on the whole....
将组件安装到GAC中可提供多种好处。 GAC使许多应用程序可以共享程序集,从而减少整体的物理内存使用量....
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).
Tess Ferrandez(微软的内存和性能大师)确认了这一点 - https://blogs.msdn.microsoft.com/tess/2006/04/12/asp-net-memory-you-use-the-same-dll -in-多的应用程序,是-IT-真的,有必要对负载-IT-多倍)。
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.
尽可能强名称并将全局程序集缓存(GAC)安装到多个ASP.NET应用程序使用的任何程序集中。这将减少内存消耗。
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.
我也通过在x64 WebAPI服务上测试(WinDbg,任务管理器和ProcExplorer)来证实这一点。您会看到GAC应用程序的私人工作集较低。在NGen的情况下,您将再次看到私人工作集减少。但是,与基线相比,NGen应用程序的页面错误也大大减少(在我的测试中几乎减少了一半)。我发现GAC应用和非GAC应用之间的页面错误没有区别。
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!
请注意,在某些情况下,最佳解决方案是通过将NGen'd程序集安装到GAC中来合并NGen和GAC。这可以优化共享程序集的应用程序之间的内存使用,并在应用程序启动时提供性能提升!