CPU usage calculation

Our business model requires you to charge users based on processor / usage hours.

At first I thought to just use StopWatch, and then use the elapsed time as a unit of measure.

But the problem that I see in this approach is that at a time when 5,000 users get to the server, the elapsed time for the same code fragment will be higher than at night, when only 50 users hit the server.

Another option is to charge users based on iterations performed on the data transmitted by users. There are also several problems with this approach.

  • Some functions do not require any iteration over the data.
  • CPU usage for x + ylower than y x + y * z.

What is a good way to calculate CPU usage information in C # /. Net so that it remains the same for all users for the same operation regardless of server load?

Perhaps the total amount of actual build level instructions? Is there any way to get this information in C #?

What other recommendations can you provide?

Thanks for looking at this.

+5
source share
1 answer

Do whatever your users want to run in a separate process and look for its processor time after the process is complete. This also differs from the wall time, because it only takes into account the time that the process actually ran on the processor.

, :

ProcessStartInfo psi = new ProcessStartInfo(@"C:\Blah\Foo.exe");
Process p = Process.Start(psi);
p.WaitForExit();
TimeSpan time = p.TotalProcessorTime;
p.Close();

, .

, . .

+14

All Articles