Click here to Skip to main content
Licence 
First Posted 30 Oct 2002
Views 65,809
Bookmarked 21 times

Determining Threading Limits For Multi-Threaded Network Applications

By | 30 Oct 2002 | Article
This article will explain a method of benchmarking a W9X/W2K/XP based computer to determine the maximum safe level of thread usage while keeping the system able to process other input without entering into a freeze condition.

Disclaimer

This article will explain a method of benchmarking a W9X/W2K/XP based computer to determine the maximum safe level of thread usage while keeping the system able to process other input without entering into a freeze condition. Please be aware that the concepts and methods contained in this article are simply the author's interpretation of available material on the subject and should not be considered the only way to perform this type of test. Additionally, the author will accept no claims of liability arising from system damage, loss of data, or any other adverse effects caused as a result from the readers' implementation of any of the methods described within this article.

Introduction

As a programmer, it is often important to know the system/resource needs of your software applications. This is especially important if you are writing a multithreaded network application. Often you need to know how many client threads your typical target system is capable of supporting. The reason this is important is that most, if not all of the time, our application should be well behaved and not claim too many of the systems resources. We all know that there is nothing worse than an unresponsive application that uses up so many system resources processing information, that we're unable to do any actions until the program is finished. The problem is that too often, we can't be sure what the target system is capable of supporting. Fortunately, I have developed a method to give a reasonable estimate of the thread amount that can safely be run on a target machine without bogging down the system. With a reasonably small amount of math, we can determine this value.

The Concept and Methodology

First, we need to obtain the following values:

  1. The CPU speed in MHZ
  2. CPU usage with OS loaded
  3. Total available memory
  4. Total memory with OS loaded
  5. Typical CPU usage of a single thread
  6. Typical memory usage of a single thread

With these values, we have a template on which to base our calculations. We will start by subtracting the CPU Usage with the OS loaded from the CPU Default Speed. We then subtract 25% from this value. The reason for this operation is to give us some indication of the total amount of CPU time slices that we have to work with, and provide some latitude to allow other applications to run in concert with the server without impacting the target machine to an extreme degree. The operation would be notated like this:

(CPU_TotalAvailable - CPU_UsageWithOS) - 25% = CPU_TotalAvailableForThreads

CPU_TotalAvailableForThreads is the maximum amount that can be used to execute threads for our application. It assumes that the program will want to use no more than 25% of the total remaining CPU to run our process. This is a reasonable assumption since it's generally considered rude for an application to use all available resources. Nobody likes a hog :-)

In order to determine the amount of memory we have to work with, we perform the same procedure that we used to determine the available CPU. Ideally, we would like to run entirely in memory to avoid paging, which can also cause system slowdown. The operation would notate as this:

(Mem_TotalAvailable - Mem_UsageWithOS) - 25% = Mem_TotalAvailableForThreads

Mem_TotalAvailableForThreads is the maximum amount that can be used to execute threads for our application. This also assumes that the program will want to use no more than 25% of the total remaining memory to run our process.

Now comes the fun part. Create your thread and profile it in such a way as to determine how much CPU and memory it uses in a single instance. This will give you a baseline value to work with. For purposes of this example, let's say that one thread uses 512 KB of memory and .5% of the CPU. Now using these values against the values we obtained earlier, you can divide the memory and CPU usage values into the Mem_TotalAvailableForThreads and CPU_TotalAvailableForThreads to determine two new values CPU_ThreadsMaxAllowable, like this:

CPUTotalAvailable / .5% = CPU_ThreadsMaxAllowable

and

MemTotalAvailableForThreads / 512KB = Mem_ThreadsMaxAllowable

Alone, neither of these two values will do us much good as they are fairly ambiguous, so we add them together and divide by two, to give us MaxAllowableThreads which is a balance between the CPU and Mem.

In Closing

All said and done, I think this is a reasonable way to determine a self level for thread usage in multithreaded network applications. This could be done from inside the application, to determine it's thread usage at runtime, or on a test system that closely mimics the intended installation platform. Good luck, and I hope you find this article useful.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

John Aldrich

Web Developer

United States United States

Member

My name is John Aldrich. I have pursued programming as a hobby for the past 6 years and currently have experience in Perl (basic / intermediate), HTML (advanced), and I have recently begun to learn C/C++. I also have a profound interest in all things graphics related and and constantly working to improve my knowledge in all areas of computing. I run a home based web software company named Professional Design Resources. If you are interested in any custom programming or would be interested in collaberating on a joint project, please feel free to contact me via email, where I'll be happy to discuss such things. Serious projects only please.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralIt depends on context of application. PinsussAnonymous7:36 1 Nov '02  
GeneralRe: It depends on context of application. PinmemberDaniel Turini7:57 1 Nov '02  
GeneralRe: It depends on context of application. PinmemberIan Griffiths3:51 5 Nov '02  
GeneralRe: I don't understand... PinmemberJohn Aldrich10:13 31 Oct '02  
GeneralThis would be a lot more interesting... PinmemberMarc Clifton9:03 31 Oct '02  
GeneralRe: This would be a lot more interesting... PinmemberJohn Aldrich10:16 31 Oct '02  
QuestionHave you used this method yourself? PinmemberRohit Sinha8:41 31 Oct '02  
AnswerRe: Have you used this method yourself? PinmemberJohn Aldrich10:18 31 Oct '02  
AnswerRe: Have you used this method yourself? PinmemberDaniel Turini10:23 31 Oct '02  
GeneralRe: Have you used this method yourself? PinmemberRohit Sinha10:48 31 Oct '02  
GeneralRe: Have you used this method yourself? PinmemberDaniel Turini23:23 31 Oct '02  
Question2 times the number of processors ? PinmemberDaniel Turini8:35 31 Oct '02  
AnswerRe: 2 times the number of processors ? PinmemberJohn Aldrich10:19 31 Oct '02  
GeneralRe: 2 times the number of processors ? PinmemberDaniel Turini10:38 31 Oct '02  
GeneralRe: 2 times the number of processors ? PinmemberTim Smith12:50 31 Oct '02  
GeneralRe: 2 times the number of processors ? PinmemberDaniel Turini23:21 31 Oct '02  
GeneralRe: 2 times the number of processors ? PinmemberTim Smith7:47 1 Nov '02  
AnswerRe: 2 times the number of processors ? PinmemberJustin Hallet1:47 1 Nov '02  
GeneralRe: 2 times the number of processors ? PinmemberJohn Aldrich4:45 1 Nov '02  
GeneralRe: 2 times the number of processors ? PinmemberTim Smith7:49 1 Nov '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 31 Oct 2002
Article Copyright 2002 by John Aldrich
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid