George George

George George

  • NA
  • 778
  • 0

multithread performance problem for web service call

Feb 3 2009 8:41 AM

Hello everyone,

Here is my sample program for web service server side and client side. I met with a strnage performance problem, which is, even if I increase the number of threads to call web services, the performance is not improved. At the same time, the CPU/memory/network consumption from performance panel of task manager is low. I am wondering what is the bottleneck and how to improve it?

(My test experience, double the number of threads will almost double the total response time)

[Code]

Client side:

    class Program
    {
        static Service1[] clients = null;
        static Thread[] threads = null;

        static void ThreadJob (object index)
        {
            // query 1000 times
            for (int i = 0; i < 100; i++)
            {
                clients[(int)index].HelloWorld();
            }
        }
       
        static void Main(string[] args)
        {
            Console.WriteLine("Specify number of threads: ");
            int number = Int32.Parse(Console.ReadLine());
           
            clients = new Service1[number];
            threads = new Thread[number];

            for (int i = 0; i < number; i++)
            {
                clients [i] = new Service1();
                ParameterizedThreadStart starter = new ParameterizedThreadStart(ThreadJob);
                threads[i] = new Thread(starter);
            }

            DateTime begin = DateTime.Now;

            for (int i = 0; i < number; i++)
            {
                threads[i].Start(i);
            }

            for (int i = 0; i < number; i++)
            {
                threads[i].Join();
            }

            Console.WriteLine("Total elapsed time (s): " + (DateTime.Now - begin).TotalSeconds);

            return;
        }
    }


Server side:

        [WebMethod]
        public double HelloWorld()
        {
            return new Random().NextDouble();
        }
[/Code]

thanks in advance,
George