我无法理解如何为工作角色设置 gcAllowVeryLargeObjectsruntime 参数。我在 app.config 中设置了这个婴儿车。但它不起作用。据我了解,我需要以某种方式在 wotker 主机的配置文件中对其进行配置。
更新:基于答案的最终解决方案
服务定义.csdef
<WorkerRole name="XXX" vmsize="Standard_D4">
<Startup>
<Task commandLine="myStartup.cmd" executionContext="elevated" taskType="simple" >
<Environment>
<Variable name="yyy" value="yyy" />
</Environment>
</Task>
</Startup>
下一个文件应作为内容添加到工作项目,并始终复制本地
启动.ps1
#Configure Server GC and Background GC settings
Function ChangeGCSettings
{
param ([string]$filename,[bool]$enableServerGC,[bool]$enableBackgroundGC,[bool]$enableVeryLargeGC)
$xml = New-Object XML
if (Test-Path ($filename))
{
$xml.Load($filename)
}
else
{
#config file doesn't exist create a now one
[System.Xml.XmlDeclaration]$xmlDeclaration = $xml.CreateXmlDeclaration("1.0","utf-8",$null)
$xml.AppendChild($xmlDeclaration)
}
# Check if we already have a configuration section - if not create it
$conf = $xml.configuration
if ($conf -eq $null)
{
$conf = $xml.CreateElement("configuration")
$xml.AppendChild($conf)
}
# Check if we already have a runtime section - if not create it
$runtime = $conf.runtime
if ($runtime -eq $null)
{
#runtime element doesn't exist
$runtime = $xml.CreateElement("runtime")
$conf.AppendChild($runtime)
}
# configure ServerGC
$gcserver = $runtime.gcServer
if ($gcserver -eq $null)
{
$gcserver = $xml.CreateElement("gcServer")
$gcserver.SetAttribute("enabled",$enableServerGC.ToString([System.Globalization.CultureInfo]::InvariantCulture).ToLower())
$runtime.AppendChild($gcserver);
}
else
{
$gcserver.enabled=$enableServerGC.ToString([System.Globalization.CultureInfo]::InvariantCulture).ToLower()
}
# configure gcAllowVeryLargeObjectsruntime
$gcAllowVeryLargeObjects = $runtime.gcAllowVeryLargeObjects
if ($gcAllowVeryLargeObjects -eq $null)
{
$gcAllowVeryLargeObjects = $xml.CreateElement("gcAllowVeryLargeObjects")
$gcAllowVeryLargeObjects.SetAttribute("enabled",$enableVeryLargeGC.ToString([System.Globalization.CultureInfo]::InvariantCulture).ToLower())
$runtime.AppendChild($gcAllowVeryLargeObjects);
}
else
{
$gcAllowVeryLargeObjects.enabled=$enableVeryLargeGC.ToString([System.Globalization.CultureInfo]::InvariantCulture).ToLower()
}
# configure Background GC
# .NET 4.5 is required for Bacground Server GC
# since 4.5 is an in-place upgrade for .NET 4.0 the new Background Server GC mode is available
# even if you target 4.0 in your application as long as the .NET 4.5 runtime is installed (Windows Server 2012 or higher by default)
#
# See http://blogs.msdn.com/b/dotnet/archive/2012/07/20/the-net-framework-4-5-includes-new-garbage-collector-enhancements-for-client-and-server-apps.aspx
$gcConcurrent = $runtime.gcConcurrent
if ($gcConcurrent -eq $null)
{
$gcConcurrent = $xml.CreateElement("gcConcurrent")
$gcConcurrent.SetAttribute("enabled",$enableBackgroundGC.ToString([System.Globalization.CultureInfo]::InvariantCulture).ToLower())
$runtime.AppendChild($gcConcurrent);
}
else
{
$gcConcurrent.enabled=$enableBackgroundGC.ToString([System.Globalization.CultureInfo]::InvariantCulture).ToLower()
}
$xml.Save($filename)
}
# Enable Background Server GC
ChangeGCSettings "${env:RoleRoot}\base\x64\WaWorkerHost.exe.config" $true $true $true
我的启动.cmd
REM Attempt to set the execution policy by using PowerShell version 2.0 syntax.
REM PowerShell version 2.0 isn't available. Set the execution policy by using the PowerShell version 1.0 calling method.
PowerShell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog1.txt" 2>&1
PowerShell .\startup.ps1 >> "%TEMP%\StartupLog2.txt" 2>&1
REM If an error occurred, return the errorlevel.
EXIT /B %errorlevel%