针对共享 Web 承载优化Optimization for Shared Web Hosting

如果是通过托管多个小型网站进行共享的服务器的管理员,可以将下列 gcTrimCommitOnLowMemory 设置添加到 .NET 目录中 Aspnet.config 文件内的 runtime 节点,从而优化性能和增加网站容量:If you are the administrator for a server that is shared by hosting several small Web sites, you can optimize performance and increase site capacity by adding the following gcTrimCommitOnLowMemory setting to the runtime node in the Aspnet.config file in the .NET directory:

<gcTrimCommitOnLowMemory enabled="true|false"/>

备注

此建议设置仅适用于共享 Web 托管方案。This setting is recommended only for shared Web hosting scenarios.

由于垃圾回收器保留内存以供将来分配,因此它提交的空间可能会超过真正所需。Because the garbage collector retains memory for future allocations, its committed space can be more than what is strictly needed. 可以减少此空间来适应系统内存负载过重的情况。You can reduce this space to accommodate times when there is a heavy load on system memory. 减少提交的此空间可提升性能,并将容量扩展为托管更多网站。Reducing this committed space improves performance and expands the capacity to host more sites.

如果启用 gcTrimCommitOnLowMemory 设置,垃圾回收器会计算系统内存负载,并在负载达到 90% 时进入修整模式。When the gcTrimCommitOnLowMemory setting is enabled, the garbage collector evaluates the system memory load and enters a trimming mode when the load reaches 90%. 除非负载下降到不到 85%,否则会一直处于修整模式。It maintains the trimming mode until the load drops under 85%.

如果条件允许,垃圾回收器可以决定 gcTrimCommitOnLowMemory 设置对当前应用没有帮助并忽略它。When conditions permit, the garbage collector can decide that the gcTrimCommitOnLowMemory setting will not help the current application and ignore it.

示例Example

下面的 XML 片段展示了如何启用 gcTrimCommitOnLowMemory 设置。The following XML fragment shows how to enable the gcTrimCommitOnLowMemory setting. 省略号表示 runtime 节点中会有其他设置。Ellipses indicate other settings that would be in the runtime node.

<?xml version="1.0" encoding="UTF-8"?>  
<configuration>  
    <runtime>  
    . . .  
    <gcTrimCommitOnLowMemory enabled="true"/>  
    </runtime>  
    . . .  
</configuration>  

请参阅See also