I am trying to write simple client-server application that can use 100% of CPU using WCF.
Program is sending 10000 times request and is receiving string like in example below. I am sending f9b6af85-8826-49c8-9524-39511f1a241a and receiving "Hello f9b6af85-8826-49c8-9524-39511f1a241a" for 10000 times and I measure time. I tried to increase number of clients from 2 to 4, but CPU is used on 30%. Service is very simple and it is self hosted in console application. Client is web form application. I need advice: what should I do to get 100% CPU usage? Should i send more request, increase number of clients, send bigger message or do something else that I am missing?
Service:
public class HelloService : IHelloService
{
public string Hello(string name)
{
return "Hello " + name;
}
}
Host:
class Program
{
static void Main()
{
using (ServiceHost host = new ServiceHost(typeof(HelloWcf.HelloService)))
{
host.Open();
Console.WriteLine("Host started @ " + DateTime.Now.ToString());
Console.ReadLine();
}
}
}
Client:
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
label1.Text = Guid.NewGuid().ToString();
var start = DateTime.Now.TimeOfDay;
HelloServiceReference.HelloServiceClient client;
for (int i = 0; i < 10000; i++)
{
label2.Text = string.Empty;
client = new HelloServiceReference.HelloServiceClient("NetTcpBinding_IHelloService");
label2.Text = client.Hello(label1.Text);
client.Close();
}
var end = DateTime.Now.TimeOfDay;
var totalTime = end - start;
label3.Text = string.Format("Total time of execution {0}", totalTime.ToString(@"mm\:ss\.ffff"));
button1.Enabled = true;
}