Generating CPU load with a C# app?

G

Greg

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.
 
A

Andreas Mueller

Greg said:
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
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Greg said:
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().TotalProcessorTime.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
 
G

Greg

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Process being throttled every 5 minutes, why? 0
CPU load generator 2
Windows 7 Problem with Services 4
C#/Mono namespaces 3
c# 2008 install feedback takes too much CPU load 9
C# App Profiling 7
CPU bottleneck 4
App Domain CPU Utilization 1

Top