Per-Core Licensing for .NET Server Software: Counting Cores Correctly and Binding the Entitlement
Per-core licensing is how a lot of server software is sold: a price that scales with the CPU capacity the customer runs you on, because a database engine or analytics service on a 64-core box delivers far more value than the same binary on a 4-core VM. The model is simple to state and surprisingly easy to get wrong, because the hard part is not the policy — it is answering, correctly and…
Per-core licensing is a common model for selling server software, where the price scales with the CPU capacity the customer runs the software on. However, determining the correct number of cores to license can be tricky. Environment.ProcessorCount, the obvious API in .NET, often returns the wrong answer. It counts logical processors, not the actual capacity being sold, and can be affected by hyperthreading, affinity settings, and container quotas.
To avoid licensing bugs, developers must decide which core count to use as the licensing unit: physical cores, logical processors, or container CPU quota. Once chosen, this number must be measured accurately. For physical cores on Windows, sum the NumberOfCores across sockets using the Management Object Searcher. On Linux, count unique physical ID and core ID pairs from the /proc/cpuinfo file.
For container CPU quota, read the quota value from the cgroup v2 or v1 directories. By measuring the right number of cores consistently, developers can avoid incorrect licensing and ensure customers are billed fairly.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.