I am curious as to what the .NET property Environment.ProcessorCount
actually returns. Does it return the number of cores, the number of processors or both? If my computer had 2 processors, each with 4 cores, would Environment.ProcessorCount
return 2, 4, or 8?
Have Environment.ProcessorCount return a value that represents an appropriate level of parallelism that may be used in the process based on affinitization and CPU resource limits Have the property return a consistent value in comparable relevant configuration between Windows and Linux
Current behavior: Environment.ProcessorCount returns the rounded up decimal value presented via --cpus. For example --cpus 0.4 will result in a return value of 1. Proposed OPT-IN behavior: Environment.ProcessorCount returns the value specified by an environment variable.
It does not reflect changes in the environment settings while the process is running. For more information about processor groups and logical processors, see Processor Groups. Defines a lock that supports single writers and multiple readers.
On Windows, the property returns the number of processors configured in the system and ignores the affinity mask. The property is often used to determine the amount of parallelism to use in the process, and it has been observed that not limiting the property's value based on affinitization can lead to worse performance.
It will return the NUMBER_OF_PROCESSORS environment variable. (see MSDN)
This will equal the number of logical cores - i.e. if you have a HT enabled single core processor, it will return 2.
In your case, it should return 8.
It will be the same number as the number of CPU utilization graphs you will see in task manager.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With