Extend cpu_count() API to get sockets and NUMA nodes count
See original GitHub issueI could not find anything related in the documentation. I am currently using a “hack” working on some Intel-based systems: Messing around with temperature sensors, but it really is not clean …
len([
None for sensor in psutil.sensors_temperatures()['coretemp']
if 'Physical id' in sensor.label
])
EDIT: The above is working on Linux x86_64 for 4.4, 4.10 and 4.15 kernels.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
D71775 [ThreadPool] On Windows, extend usage to all CPU ...
The goal was to have LLD/ThinLTO use all hardware threads in the system, which isn't the case currently on multi-socket or large CPU...
Read more >How to find out the number of CPUs using python
cpu_count() answer is 4. My own open('/proc/cpuinfo').read().count('processor') also produces 4, the number of ...
Read more >Is the amount of NUMA nodes always equal to sockets?
When you have 2 socket system, each CPU (socket) has its own memory, which it can directly access. But it must also be...
Read more >Figuring out CPUs and Sockets - Updated!
Get number of CPU. Raw. grep -i "physical id" /proc/cpuinfo | sort -u | wc -l. dmidecode |grep -i cpu. Socket Designation: CPU1....
Read more >What is the num of NUMA nodes for MAXDOP calculation ...
You're seeing soft-NUMA counts. As mentioned in this MS Doc… Starting with SQL Server 2016 (13.x), during service startup if the Database ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
OK, here’s a bit of brainstorming. Currently psutil is able to return logical (hyper threading) and physical cores. The goal is to provide CPU sockets count (and possibly others). IMO, the ideal API if we were to start from scratch today would be having a single function accepting a
kind
parameter, similar topsutil.net_connections(kind='all')
. That would be simple and extensible in terms of back compatibility. It would look like this:(similarly to
os.cpu_count()
, if the value can’t be determined we’ll just return None)The current function signature unfortunately is:
What we MAY do in order to keep supporting
logical
parameter and avoid code breakage is this:If the function is invoked as such we will assume the user is asking for logical cores:
If the function is invoked as such we will assume the user is asking for physical cores:
I think calling all that cpu just makes the code more confusing, why not: numa_count(), group_count(), socket_count(), cpu_count(group=<groupnumber>, numa=<numanumber>) ?
Then you can get the number of logical/physical cpus in a group or numa node and also the numa and group count. For windows you still need to know in which group is each numa node so something like numa_group(numa=<numanumber>) is also needed.
A numa node has a group (on cpus with more than 64 logical cores in the same numa node windows actually creates virtual numa nodes for them) and an affinity mask in that group as sometimes machines with < 64 total logical cpus but more than one numa node will get their cpus as different affinity masks on the same group
eg. a 2 socket machine with two 20 logical core die will get 2 numa nodes, 1 group and an affinity mask of the first 20 logical cores for numa node 1 and the rest for numa node 2.