Start Java Application using System.Diagnostics.Process

$startCount = 5;
$processors = Get-WmiObject -Class Win32_ComputerSystem | select -
ExpandProperty "NumberOfLogicalProcessors";
$perInstance = $processors / $startCount;
$affinityloop = 1;
$affinityvalue = 0;

for($i=1; $i -le $startCount; $i++) {
   $affinityvalue = 0;
   for($u=1; $u -le $perInstance ; $u++) {
     $affinityvalue = $affinityvalue + $affinityloop;
     $affinityloop = $affinityloop * 2;
   $ps = new-object System.Diagnostics.Process;
   $ps.StartInfo.Filename = "C:\jdk\bin\java.exe";
   $ps.StartInfo.Arguments = " -server -Xms10240m -Xmx10240m -XX:+UseG1GC -cp `".;*`" Worker";
   Write-Host $affinityvalue ;
   $ps.ProcessorAffinity = [Convert]::ToString($affinityvalue, 16);

I am trying to start a Windows Java application on two different NUMA nodes. Has anyone able to accomplish this with Diagnostics.Process format? This code does work fine, but all applications created are on the same numa node and hence only using 50% power.

I did create some code such as $mod = ($i % 2); to help prepare for some way to alternate the numa node but unsure how to specify it within the script.


Tried to load balance with ProcessorAffinity and I get crashes due to Double unable to convert to IntPtr


So it looks like Windows Groups the processors past 64 into Groups. Can't seem to find a way to alter that like ProcessAffinity. I bet its just not that common. You can easily do it in Task manager, just need to find a way to do it in Powershell or similar.