Compare microservice memory settings with memory use - TridionPractice/tridion-practice GitHub Wiki

If you are tuning the memory allocations of your content delivery microservices, it's handy to be able to get a quick summary of how much memory each of the services is using, compared with the amounts specified in the JVM parameters. This PowerShell script is intended to provide this information.

$services = service SD*
[System.Collections.ArrayList]$list = @()
foreach ($service in $services) { 
    $output = New-Object PSObject
    $name = $service.Name
    Add-Member -InputObject $output -NotePropertyName 'Name' -NotePropertyValue $name

    $procId = (Get-WmiObject -Query "select ProcessId from win32_service where name='$name'" | select ProcessId).ProcessId
    Add-Member -InputObject $output -NotePropertyName 'ProcessId' -NotePropertyValue $procId 
    $process = Get-Process -Id $procId 
    Add-Member -InputObject $output -NotePropertyName 'PM' -NotePropertyValue ("{0:n0}m" -f ($process.PrivateMemorySize / 1Mb))

    $serviceKey = Get-Item "HKLM:SYSTEM\CurrentControlSet\Services\$name"
    $java = gi "HKLM:SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\$name\Parameters\Java"
    Add-Member -InputObject $output -NotePropertyName 'JvmOptions' -NotePropertyValue $java.GetValue('Options') 

    $list.Add($output) | Out-Null
}

$list | ft -AutoSize

If you run this, you will see output that looks something like this:

Name                          ProcessId PM   JvmOptions                                                         
----                          --------- --   ----------                                                         
SDLDXAModelService                 7388 373m {-Xrs, -Xms256m, -Xmx512m}                                         
SDLDXAStagingModelService          9148 373m {-Xrs, -Xms256m, -Xmx512m}                                         
SDLStagingContextService           2988 419m {-Xrs, -Xms256m, -Xmx512m, -Dspring.profiles.active=performance...}
SDLWebContentService               9680 677m {-Xrs, -Xms512m, -Xmx1536m}                                        
SDLWebDeployerService              9904 673m {-Xrs, -Xms512m, -Xmx1024m, -Dfile.encoding=UTF-8}                 
SDLWebDiscoveryService             6476 340m {-Xrs, -Xms128m, -Xmx128m}                                         
SDLWebSessionPreviewService        9760 441m {-Xrs, -Xms256m, -Xmx384m}                                         
SDLWebStagingContentService        7576 691m {-Xrs, -Xms512m, -Xmx1536m}                                        
SDLWebStagingDeployerService        252 674m {-Xrs, -Xms512m, -Xmx1024m, -Dfile.encoding=UTF-8}                 
SDLWebStagingDiscoveryService      6084 289m {-Xrs, -Xms128m, -Xmx128m}  

The above output is from running the script on a developer's "all in one" image, which is probably the situation in which you're most likely to be aggressively tuning the memory settings.