简体   繁体   中英

C# Core 2.1 Utilize 2 CPUs

I'm Currently building an application which relies heavily on running multithreaded. I'm Currently spawning as many threads as the system has cores using the environment.ProcessorCount constant, but when I run the application on our server which has 2 separate CPUs (Intel Xeon E5-2620) all threads work on the first CPU while the second CPU idles. Is it possible to utilize the second CPU in one process or do I need to split the process and force the utilisation with Processor affinity?

Edit:

I've tried to set the affinity using the IdealProcessor to split to CPU 0 and 1 but had no success.

Looks like tat your multiprocessor architecture is NUMA which implies CPUs have different access time to different memory regions. Systems with such architecture balance the load between CPUs in order to load only those processors which are "closer" (have lowest access time) to the memory area is being operated on. In case of ordinal .NET application standard memory layout implies residing in the same memory area which on NUMA architectures leads to utilizing only those CPUs which are closer to this are (in your case it can be 2 NUMA nodes with 1 CPU each and only 1 us used because it servers the memory area your applications uses).

The applications which need to get benefits from the NUMA architecture are supposed to use specific APIs which expose among other calls the calls to indicate in which NUMA node to allocate a memory (here is example of API functions provided by Windows). The .NET CLR starting from version 4.5 is able to utilize this API indirectly by specific configuration settings. On the CLR runtimes you need to set the following options in the application settings:

<configuration>
   <runtime>
      <gcServer enabled="true"/>
      <Thread_UseAllCpuGroups  enabled="true"/>
   </runtime>
</configuration>

Where gcServer mode controls the NUMA awareness for the memory allocations so that runtime can support multiple heaps for different NUMA nodes and Thread_UseAllCpuGroups controls the NUMA awareness for the tread pool.

However for .NET Core runtimes you need to turn on gcServer mode by using runtime options while Thread_UseAllCpuGroups which is part of ThreadPool settings can be passed via an environment variable according to this with prefix COMPlus_ (ie set COMPlus_Thread_UseAllCpuGroups=1 ).

Had a similar issue, it seemed one of our .NET Core application was running on only one CPU. Tired the solution above, but unfortunately it did not do the trick.

After digging around for long time, a great colleague of mine, found that all except one CPU had the state "Parked". https://blogs.technet.microsoft.com/yongrhee/2012/11/02/windows-server-2008-r2-and-core-parking-how-it-affects-you-the-administrator/ .

The suggested workaround to change the Power Plan setting to 'High Performance' worked like a charm. Maybe this could help others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM