1

For example the SQL Server license model is limited to the number of cpu sockets/cores:

https://learn.microsoft.com/en-us/sql/sql-server/compute-capacity-limits-by-edition-of-sql-server?view=sql-server-2017

SQL Server edition
Maximum compute capacity for a single instance ( SQL Server Database Engine)
Enterprise Edition: Core-based Licensing*
Operating system maximum
Developer
Operating system maximum
Standard
Limited to lesser of 4 sockets or 24 cores
Express
Limited to lesser of 1 socket or 4 cores

How do you limit the number of sockets or cores for an application or windows service in C#/.NET?

Is setting the processor affinity/threadaffinity the only way (which can easily be bypassed via task manager (ctrl+shift+esc))

(P.S.: The question is not if it is a good idea to do this or not, as seen a lot in other questions).

juFo
  • 17,849
  • 10
  • 105
  • 142

1 Answers1

1

When you write a simple "hello world" c# program, this runs on one OS thread and one core.

If you want to stick to a single core, just don't spawn any threads or use any tasks.

You can limit the paralellism of the standard worker ThreadPool by using ThreadPool.SetMaxThreads. Some libraries might create their own thread pools, or their own worker threads. So you need to be more specific about your program in order to get a more complete answer.

If you want to limit yourself to a specific processor, you must also tweak the processor affinity of your process and threads. See this question for how to do that. I don't know if you can tweak the affinity of the ThreadPool threads.

gnud
  • 77,584
  • 5
  • 64
  • 78