Threads are limited by physical constraints

Key Knowledge

  • The number of threads that can be created is constrained by physical CPU and memory.
  • Applications that run into physical limits should rethink the scalability of the design.
  • Scalable design principles include keeping the number of running threads equal to the number of CPUs and to use asynchronous I/O completion ports to minimize the number of running threads.
    • ASP.NET AuthorizeAttribute is executed without async-await pattern. High load can cause thread starvation. Consider moving authentication to DelegatingHandler that can implement async-await pattern. [Write a test to show this].
  • Avoid common problems with timeslicing.
    • Thrashing the CPU and memory
    • Convoying on locks
  • Scale shared resources by replicating or partitioning.
  • Use backoff with randomization to avoid livelocks and Thundering herd problem.

Works Cited

“fixed size page file so when the box run out of commit limit (Page file + RAM) windows will not be able to create additional threads for any processes because memory needed for stack space will not be available and system will freeze.”

WindowsEventLogSystemEvents
| where ProviderName contains "Microsoft-Windows-Resource-Exhaustion-Detector"

Log Name:      System
Source:        Microsoft-Windows-Resource-Exhaustion-Detector
Task Category: Resource Exhaustion Diagnosis Events
Level:         Warning
Keywords:      Events related to exhaustion of system commit limit (virtual memory).
Description:
Windows successfully diagnosed a low virtual memory condition. The following programs consumed the most virtual memory: X.exe consumed 78804631552 bytes, Y.exe consumed 71854399488 bytes, and Z.exe consumed 16489115648 bytes.

Pushing the Limits of Windows: Processes and Threads

https://blogs.technet.microsoft.com/markrussinovich/2009/07/05/pushing-the-limits-of-windows-processes-and-threads/

Avoiding Classic Threading Problems

http://www.drdobbs.com/tools/avoiding-classic-threading-problems/231000499

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: