My goal is to develop a mini-benchmark tool, so I can test the performance of a Web Api.
I want to create the performance counters programmatically using a simple console application. As part of my research, I created the main method below. This is just a simple test. So basically, I need HttpClient in order to forward an x-number of requests and then to view some metrics (i.e % Processor Time ) for this operation.
Is my logic correct?
Hide Copy Code
static void Main(string[] args)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var theCPUCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName);
Console.WriteLine(theCPUCounter.NextValue());
System.Threading.Thread.Sleep(1000);
for (int i = 0; i <= 5; i++)
{
HttpResponseMessage response = client.GetAsync("http://www.google.co.uk/").Result;
}
Console.WriteLine(theCPUCounter.NextValue());
}
I am aware that there are performance counters that make more sense, but for the time being, I just want to see if I understand it correctly.
If the above is correct then my plan is :
1)Create various throughput scenarios with concurrent requests using HttpClient and TPL(i.e send 1000 concurrent requests, but create different scenarios for every 100 in order to utilize various resources in the Web Api). As soon as I have those scenarios executed, then
2)I will be releasing the performance counters for measuring CPU and Memory.
That's the plan.
Can you please advise?
Thanks!!