Click here to Skip to main content
13,044,705 members (64,038 online)
Click here to Skip to main content
Add your own
alternative version

Stats

72.4K views
23 bookmarked
Posted 30 Oct 2002

Determining Threading Limits For Multi-Threaded Network Applications

, 30 Oct 2002
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

John Aldrich
Web Developer
United States United States
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.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralIt depends on context of application. Pin
Anonymous1-Nov-02 7:36
sussAnonymous1-Nov-02 7:36 
GeneralRe: It depends on context of application. Pin
Daniel Turini1-Nov-02 7:57
memberDaniel Turini1-Nov-02 7:57 
GeneralRe: It depends on context of application. Pin
Ian Griffiths5-Nov-02 3:51
memberIan Griffiths5-Nov-02 3:51 
GeneralRe: I don't understand... Pin
John Aldrich31-Oct-02 10:13
memberJohn Aldrich31-Oct-02 10:13 
GeneralThis would be a lot more interesting... Pin
Marc Clifton31-Oct-02 9:03
memberMarc Clifton31-Oct-02 9:03 
GeneralRe: This would be a lot more interesting... Pin
John Aldrich31-Oct-02 10:16
memberJohn Aldrich31-Oct-02 10:16 
QuestionHave you used this method yourself? Pin
Rohit Sinha31-Oct-02 8:41
memberRohit Sinha31-Oct-02 8:41 
AnswerRe: Have you used this method yourself? Pin
John Aldrich31-Oct-02 10:18
memberJohn Aldrich31-Oct-02 10:18 
AnswerRe: Have you used this method yourself? Pin
Daniel Turini31-Oct-02 10:23
memberDaniel Turini31-Oct-02 10:23 
GeneralRe: Have you used this method yourself? Pin
Rohit Sinha31-Oct-02 10:48
memberRohit Sinha31-Oct-02 10:48 
GeneralRe: Have you used this method yourself? Pin
Daniel Turini31-Oct-02 23:23
memberDaniel Turini31-Oct-02 23:23 
Question2 times the number of processors ? Pin
Daniel Turini31-Oct-02 8:35
memberDaniel Turini31-Oct-02 8:35 
AnswerRe: 2 times the number of processors ? Pin
John Aldrich31-Oct-02 10:19
memberJohn Aldrich31-Oct-02 10:19 
GeneralRe: 2 times the number of processors ? Pin
Daniel Turini31-Oct-02 10:38
memberDaniel Turini31-Oct-02 10:38 
GeneralRe: 2 times the number of processors ? Pin
Tim Smith31-Oct-02 12:50
memberTim Smith31-Oct-02 12:50 
GeneralRe: 2 times the number of processors ? Pin
Daniel Turini31-Oct-02 23:21
memberDaniel Turini31-Oct-02 23:21 
GeneralRe: 2 times the number of processors ? Pin
Tim Smith1-Nov-02 7:47
memberTim Smith1-Nov-02 7:47 
AnswerRe: 2 times the number of processors ? Pin
Justin Hallet1-Nov-02 1:47
memberJustin Hallet1-Nov-02 1:47 
GeneralRe: 2 times the number of processors ? Pin
John Aldrich1-Nov-02 4:45
memberJohn Aldrich1-Nov-02 4:45 
GeneralRe: 2 times the number of processors ? Pin
Tim Smith1-Nov-02 7:49
memberTim Smith1-Nov-02 7:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 31 Oct 2002
Article Copyright 2002 by John Aldrich
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid