473,544 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating CPU load with a C# app?

I need to build or buy an application that will allow me to generate a
specific CPU load and memory usage. Ideally I could throttle this up and
down to simulate different load conditions. This for application testing -
we'd like to see how the app performs under certain load conditions.

I'd prefer to build it myself with C#, mostly just for the learning
experience and because I have the time.

Has anyone done something like this? I'm looking for suggestions, links,
and info to help me start investigating the namespaces I might need or the
approaches I might take since I'm not exactly sure where to start.

I know I can use the System.Diagnost ics namespace for monitoring cpu load
and mem usage, but I'm not really sure how to approach loading the CPU and
memory so that I can throttle it up and down.

Thanks in advance for any thoughts.
Sep 6 '06 #1
4 11441
Greg wrote:
I need to build or buy an application that will allow me to generate a
specific CPU load and memory usage. Ideally I could throttle this up and
down to simulate different load conditions. This for application testing -
we'd like to see how the app performs under certain load conditions.

I'd prefer to build it myself with C#, mostly just for the learning
experience and because I have the time.

Has anyone done something like this? I'm looking for suggestions, links,
and info to help me start investigating the namespaces I might need or the
approaches I might take since I'm not exactly sure where to start.

I know I can use the System.Diagnost ics namespace for monitoring cpu load
and mem usage, but I'm not really sure how to approach loading the CPU and
memory so that I can throttle it up and down.

Thanks in advance for any thoughts.

Here is what I use:
http://tinyurl.com/elvz7

HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gm xNOSPAm.netNOSPAm
Sep 6 '06 #2
Greg wrote:
I need to build or buy an application that will allow me to generate a
specific CPU load and memory usage. Ideally I could throttle this up and
down to simulate different load conditions. This for application testing -
we'd like to see how the app performs under certain load conditions.

I'd prefer to build it myself with C#, mostly just for the learning
experience and because I have the time.

Has anyone done something like this? I'm looking for suggestions, links,
and info to help me start investigating the namespaces I might need or the
approaches I might take since I'm not exactly sure where to start.

I know I can use the System.Diagnost ics namespace for monitoring cpu load
and mem usage, but I'm not really sure how to approach loading the CPU and
memory so that I can throttle it up and down.
Some quick code:

public static int Fac(int n)
{
if(n 1)
{
return n * Fac(n -1);
}
else
{
return 1;
}
}
public static int CpuTime()
{
return
(int)Process.Ge tCurrentProcess ().TotalProcess orTime.TotalMil liseconds;
}
public static long WallTime()
{
return DateTime.Now.Ti cks / 10000;
}
public static void Load(double target)
{
int n = 1000000;
int cpu = CpuTime();
long wall = WallTime();
int dcpu;
long dwall;
for(;;)
{
for(int i = 0; i < n; i++)
{
if(Fac(10) != 3628800)
{
Environment.Exi t(1);
}
}
Thread.Sleep(10 0);
int cpu2 = CpuTime();
long wall2 = WallTime();
dcpu = cpu2 - cpu;
dwall = wall2 - wall;
n = (int)(n * ((target * dwall) / dcpu));
Console.WriteLi ne(dcpu + " " + dwall);
cpu = cpu2;
wall = wall2;
}
}

Arne
Sep 7 '06 #3
Arne Vajhøj wrote:
Console.WriteLi ne(dcpu + " " + dwall);
Drop that line.

It was just for verifying stability.

Arne
Sep 7 '06 #4
That may do it, thanks for the replies. I'll be working on it this week, so
I'll give it a try.

Thanks,
Greg
"Andreas Mueller" <me@privacy.net wrote in message
news:4m******** ****@individual .net...
Greg wrote:
>I need to build or buy an application that will allow me to generate a
specific CPU load and memory usage. Ideally I could throttle this up and
down to simulate different load conditions. This for application
testing - we'd like to see how the app performs under certain load
conditions.

I'd prefer to build it myself with C#, mostly just for the learning
experience and because I have the time.

Has anyone done something like this? I'm looking for suggestions, links,
and info to help me start investigating the namespaces I might need or
the approaches I might take since I'm not exactly sure where to start.

I know I can use the System.Diagnost ics namespace for monitoring cpu load
and mem usage, but I'm not really sure how to approach loading the CPU
and memory so that I can throttle it up and down.

Thanks in advance for any thoughts.

Here is what I use:
http://tinyurl.com/elvz7

HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gm xNOSPAm.netNOSPAm

Sep 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2117
by: flupke | last post by:
Hi, i create my GUIs mainly via wxGlade. However when you start of to program and want to do some rearranging to the gui, wxglade overwrites your file and you've got to put your own code back in. I think i can work around that (at least a bit) by making a second file that imports the gui generated by wxglade and make classes that extend...
2
1944
by: Ryan | last post by:
We have an MIS system which has approx 100 reports. Each of these reports can take up to several minutes to run due to the complexity of the queries (hundreds of lines each in most cases). Each report can be run by many users, so in effect we have a slow system. I want to seperate the complex part of the queries into a process that is...
4
1984
by: sidd | last post by:
Hi all, please see if some one can suggest a better approach for this. i need to move 5 million rows from one table to another. LoanID is the only clumn in Source table Source table structure =========--> ============================== loanID 1 1
1
7582
by: Matik | last post by:
Hello, I need to change collation in my database (more databases acctualy). Therefore, I wanted to make a script, which will do it at one more time. I already have a cursor, updating collation on all tables (fields) in database. The problem is, before I will to update the collations, I need to drop all constrains and pk's.
0
1098
by: Mark | last post by:
Hi, I am trying to create a "print preview" window for a web site using asp.net. I have got a long way down the road to the solution but the problem I have now is that the text and lines on the printed page are fuzzy. The following code sample will illustrate the point: Start of page load code sample '=========================
7
7253
by: eric.gagnon | last post by:
In a program randomly generating 10 000 000 alphanumeric codes of 16 characters in length (Ex.: "ZAZAZAZAZAZAZ156"), what would be an efficient way to ensure that I do not generate duplicates? STL set, map? Could you give me a little code example? Thank you.
0
2013
by: utkarsh | last post by:
Hi All, I have a DLL contains two classes, first one which is to be serialized and other one is a UserControl class have code to serialize as below:- class XYZ: System.Windows.Forms.UserControl { public XYZ() {
1
3004
by: idletask | last post by:
Hello, I have an XML file that is on my file system. I want to read the file into memory and call a web service with it. When I do, the VB complains: "there was an error generating the XML document". I see a lot of posts regarding serialization of classes. I am not that familiar with serialization. Can I not just send the object to...
0
25901
SammyB
by: SammyB | last post by:
These are some "random" thoughts about generating random numbers in Visual Basic. Wikipedia will give a better introduction than I, see http://en.wikipedia.org/wiki/Random_number_generator. The key point is that you need to start the random number generator with a seed. Doing it in the form load with the number of milliseconds since...
0
7417
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7361
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7601
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7763
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5901
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4908
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3404
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1834
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
983
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.