Skip to content

Instantly share code, notes, and snippets.

@Digiover
Created February 22, 2024 09:19
Show Gist options
  • Save Digiover/446df93ff8ddcd28d3f0dea4827b02f2 to your computer and use it in GitHub Desktop.
Save Digiover/446df93ff8ddcd28d3f0dea4827b02f2 to your computer and use it in GitHub Desktop.
Add gcTrimCommitOnLowMemory runtime Aspnet configuration
# https://www.saotn.org/aspnet-performance-what-to-keep-in-mind/#highdensitywebhosting
$bitness = @("64", "")
foreach ($bits in $bitness) {
$xml = New-Object xml
$xml.Load("C:\Windows\Microsoft.NET\Framework${bits}\v4.0.30319\Aspnet.config")
# Check whether the runtime control gcTrimCommitOnLowMemory is already registered
$nodeGcTrimCommitOnLowMemory = $xml.SelectSingleNode("configuration/runtime/gcTrimCommitOnLowMemory")
# Not registered, let's add gcTrimCommitOnLowMemory
if ($nodeGcTrimCommitOnLowMemory -eq $null) {
$parentNode = $xml.SelectSingleNode("configuration/runtime")
$childNode = $xml.CreateElement("gcTrimCommitOnLowMemory")
$childNode.SetAttribute("enabled", "true")
$parentNode.AppendChild($childNode)
}
$xml.Save("C:\Windows\Microsoft.NET\Framework${bits}\v4.0.30319\Aspnet.config")
}
@Digiover
Copy link
Author

Don't forget to reset IIS afterwards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment