473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.Diagnostics 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 11425
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.Diagnostics 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**********@gmxNOSPAm.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.Diagnostics 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.GetCurrentProcess().TotalProcessorTim e.TotalMilliseconds;
}
public static long WallTime()
{
return DateTime.Now.Ticks / 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.Exit(1);
}
}
Thread.Sleep(100);
int cpu2 = CpuTime();
long wall2 = WallTime();
dcpu = cpu2 - cpu;
dwall = wall2 - wall;
n = (int)(n * ((target * dwall) / dcpu));
Console.WriteLine(dcpu + " " + dwall);
cpu = cpu2;
wall = wall2;
}
}

Arne
Sep 7 '06 #3
Arne Vajhøj wrote:
Console.WriteLine(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.netwrote 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.Diagnostics 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**********@gmxNOSPAm.netNOSPAm

Sep 12 '06 #5

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

Similar topics

17
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...
2
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...
4
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...
1
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...
0
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...
7
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? ...
0
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:...
1
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...
0
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. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.