I’ve noticed something really strange recently and decided to set up a test project to show you the problem:
Windows fails to balance processes correctly when using a Unity standalone build with the “-batchmode” option.
From the article:
"The number that follows the start /affinity command is called the affinity mask and is defined as a hexadecimal number. However, the CPU core number can be calculated more easily using binary numbers. For instance, the command
C:\Windows\System32\cmd.exe /C start /affinity 3 dfrgui.exe
will launch Disk Defragmenter on both CPU 0 and CPU 1. If you convert 3 into a binary number you will get 0011. Under the affinity mask system, processors are numbered from the right to left beginning with 0 and since there are 1’s in the first two places, this indicates CPU 0 and CPU 1.
Suppose you have a Quad core processor. If so and you use an affinity mask of 4, that will convert into binary 0100, which indicates CPU 2. If you use an affinity mask of 9, that will convert into binary 1001, which indicates CPU 0 and CPU 3."
I tried to start it with the “start” command but I had the same results.
In fact, I’m aware of the core affinity trick, that’s the solution I first choose for my game servers.
But I have CPU peaks every time the server loads a map, so limiting my servers to one core isn’t a viable solution because every CPU peak will impact the other game servers on the same core (yes, that’s a bit tricky to explain).
I want windows to handle the core balancing so I can use the whole cpu capacity.
Several windows administrators also firmly discouraged me from using core affinity, saying windows should be the one handling all this…
There is no other option cause Unity still has not fixed the bug in there yet.
We already reported that bug back when batchmode was finally working correctly as a mode to be used, no idea what version that was in the Unity 2.x days.
If you know that there is something else going on on the system too, then the easiest thing is to declare one core as ‘loader core’ where also the other non gaming stuff happens (I guess you have some kind of a cron job / server master app running that starts and stops instances or alike basing on need which it gets from some backend place) where newly loaded applications are set to affinity wise through above line and once they are loaded they change their affinity to the real core they are meant to use (you can provide that through the command line or a config or whatever) through Win32.