Threading

If used poorly, threading can consume a lot of CPU cycles needlessly. If your code is multi-threaded, consider the following ways to reduce threading overhead:

  • If you use threads to wait for off-box resources such as databases or web services, consider using asynchronous requests instead. These are described in Chapter 6,Thread Usage.
  • Do not create your own threads. This is very expensive. Instead, use ThreadPool.QueueUserWorkItem to get a thread from the thread pool.
  • Do not use threads for CPU-intensive tasks. If you have four CPUs, there is no sense in having more than four CPU-intensive tasks.
  • Thread switches are expensive. Try to reduce the number of threads running simultaneously.

To get more information about the threads currently ...

Get ASP.NET Site Performance Secrets now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.