Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. multithread performance problem for web service call

multithread performance problem for web service call

Scheduled Pinned Locked Moved C#
databasesysadminperformancequestionwcf
35 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P PIEBALDconsult

    I don't know, I'm not a Web expert, I'm hoping someone with more knowledge will step in and answer that for both of us. You could possibly create a Web Service with two methods, one that sleeps for a minute and one that doesn't. Make a request to the one that sleeps, and while it's sleeping make a request to the other and see whether or not it waits for the sleeping one to complete.

    G Offline
    G Offline
    George_George
    wrote on last edited by
    #26

    Thanks PIEBALDconsult, I am not sure what you are going to prove. In your scenario, you have web service (say sleep) and another web service (say sleepless). If we call on a thread from client side, first call sleep web service, then call sleepless web service, since it is synchronous call in one thread from client, the client will definitely wait for the sleep web service to complete the return results until call the second sleepless web service. Please correct me if I am wrong in understanding your points. I am confused what you are going to prove -- so obvious results. :-) regards, George

    P 1 Reply Last reply
    0
    • L Lost User

      1. no, I would have to know what HelloWorld() does, and how it does it, and probably a lot more 2. well, if it weren't, threading would cause a speed-up. And it didn't.

      G Offline
      G Offline
      George_George
      wrote on last edited by
      #27

      Thanks harold, For 1, Here is my code at server side. Could you reproduce my problem?

      /// <summary>
      /// Summary description for Service1
      /// </summary>
      \[WebService(Namespace = "http://tempuri.org/")\]
      \[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1\_1)\]
      \[System.ComponentModel.ToolboxItem(false)\]
      public class Service1 : System.Web.Services.WebService
      {
      
          \[WebMethod\]
          public double HelloWorld()
          {
              return new Random().NextDouble();
          }
      }
      

      For 2, I could understand your points. But do you have any documents to prove? I think if web service could only serve requests sequentially other than simualtenaously, it is so bad and degrade performance design. I can not believe it is designed in this way. :-) regards, George

      L 1 Reply Last reply
      0
      • G George_George

        Thanks harold, For 1, Here is my code at server side. Could you reproduce my problem?

        /// <summary>
        /// Summary description for Service1
        /// </summary>
        \[WebService(Namespace = "http://tempuri.org/")\]
        \[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1\_1)\]
        \[System.ComponentModel.ToolboxItem(false)\]
        public class Service1 : System.Web.Services.WebService
        {
        
            \[WebMethod\]
            public double HelloWorld()
            {
                return new Random().NextDouble();
            }
        }
        

        For 2, I could understand your points. But do you have any documents to prove? I think if web service could only serve requests sequentially other than simualtenaously, it is so bad and degrade performance design. I can not believe it is designed in this way. :-) regards, George

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #28
        1. Alright it looks like it should be doing it sequentially, otherwise Random.NextDouble could fail, no method in System.Random is threadsafe. But it should barely take any time at all. 2) Documents... well. Take Amdahl's_law for example, in which P is the proportion of the program that has been made parallel. P would be zero, so you'd get the limit 1 / (1 - 0 + 0/n) where n goes to infinity. So as you can see, the answer is 1, independent of n, meaning: no benefit at all. But of course we knew that that already, since we made no improvement. 3?) I see no good reason for this to be slow, it should be blazingly fast - it's only generating a bunch of random numbers and sending them over right?
        G 1 Reply Last reply
        0
        • L Lost User
          1. Alright it looks like it should be doing it sequentially, otherwise Random.NextDouble could fail, no method in System.Random is threadsafe. But it should barely take any time at all. 2) Documents... well. Take Amdahl's_law for example, in which P is the proportion of the program that has been made parallel. P would be zero, so you'd get the limit 1 / (1 - 0 + 0/n) where n goes to infinity. So as you can see, the answer is 1, independent of n, meaning: no benefit at all. But of course we knew that that already, since we made no improvement. 3?) I see no good reason for this to be slow, it should be blazingly fast - it's only generating a bunch of random numbers and sending them over right?
          G Offline
          G Offline
          George_George
          wrote on last edited by
          #29

          Thanks harold, 1. "otherwise Random.NextDouble could fail, no method in System.Random is threadsafe." -- I agree it is not thread safe, but I disagree since it is not thread safe, web service will do sequentially. Since each time I creat a new instance of Random object. You can check my code. Any comments? 2. "Alright it looks like it should be doing it sequentially" -- how do you prove it? My current confusion is, web service has to do sequentially or could do in parallel? regards, George

          L 1 Reply Last reply
          0
          • G George_George

            Thanks harold, 1. "otherwise Random.NextDouble could fail, no method in System.Random is threadsafe." -- I agree it is not thread safe, but I disagree since it is not thread safe, web service will do sequentially. Since each time I creat a new instance of Random object. You can check my code. Any comments? 2. "Alright it looks like it should be doing it sequentially" -- how do you prove it? My current confusion is, web service has to do sequentially or could do in parallel? regards, George

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #30
            1. doh yes, sorry, I just woke up :laugh: 2) you can easily prove it informally by measuring the difference between doing some simultaneous calls vs some sequential calls - if there is no difference (or if the parallel calls took longer) than there are only 2 possible cases: 1: the simultaneous calls were handled sequentially. 2: the simultaneous calls were so short that the overhead of doing them simultaneously was as big as or bigger than the benefit. You can, of course, test which case it is. Just make the method that is called a good bit longer (say, generate 10k random numbers, then return the last one). If it benefits from threading then it was case 2, otherwise case 1.
            G 1 Reply Last reply
            0
            • L Lost User
              1. doh yes, sorry, I just woke up :laugh: 2) you can easily prove it informally by measuring the difference between doing some simultaneous calls vs some sequential calls - if there is no difference (or if the parallel calls took longer) than there are only 2 possible cases: 1: the simultaneous calls were handled sequentially. 2: the simultaneous calls were so short that the overhead of doing them simultaneously was as big as or bigger than the benefit. You can, of course, test which case it is. Just make the method that is called a good bit longer (say, generate 10k random numbers, then return the last one). If it benefits from threading then it was case 2, otherwise case 1.
              G Offline
              G Offline
              George_George
              wrote on last edited by
              #31

              Thanks harold, 1. I did the following test and I think the web service should work simultaneously. Here is my new code at server side, and I add an additional Sleep. I think if working sequentially, it will take 5 * 1000 seconds to complete all jobs (10 threads and each thread get 100 random number), but in my testing experience, it takes about 55 seconds. Does it prove web service works simultaneously? Any comments?

              /// <summary>
              /// Summary description for Service1
              /// </summary>
              \[WebService(Namespace = "http://tempuri.org/")\]
              \[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1\_1)\]
              \[System.ComponentModel.ToolboxItem(false)\]
              public class Service1 : System.Web.Services.WebService
              {
              
                  \[WebMethod\]
                  public double HelloWorld()
                  {
                      Thread.Sleep(500);
                      return new Random().NextDouble();
                  }
              }
              

              2. Could you reproduce my issue? I want to know whether it is my environment issue if you could not reproduce it. 3. If you could reproduce, any ideas to improve performance? regards, George

              L 1 Reply Last reply
              0
              • G George_George

                Thanks harold, 1. I did the following test and I think the web service should work simultaneously. Here is my new code at server side, and I add an additional Sleep. I think if working sequentially, it will take 5 * 1000 seconds to complete all jobs (10 threads and each thread get 100 random number), but in my testing experience, it takes about 55 seconds. Does it prove web service works simultaneously? Any comments?

                /// <summary>
                /// Summary description for Service1
                /// </summary>
                \[WebService(Namespace = "http://tempuri.org/")\]
                \[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1\_1)\]
                \[System.ComponentModel.ToolboxItem(false)\]
                public class Service1 : System.Web.Services.WebService
                {
                
                    \[WebMethod\]
                    public double HelloWorld()
                    {
                        Thread.Sleep(500);
                        return new Random().NextDouble();
                    }
                }
                

                2. Could you reproduce my issue? I want to know whether it is my environment issue if you could not reproduce it. 3. If you could reproduce, any ideas to improve performance? regards, George

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #32
                1. it would take 1000 * 500 miliseconds = 500 seconds if it were sequentially. Which is more than 55 seconds, so, by RAA, it is proven that it wasn't purely sequentially. Now that's a real breakthrough - it means the threading works but the task (without the sleep) is too short. 2) well, not directly. But it works like that without webservers being involved as well. 3) The threading will help when you let the web method do something useful.
                G 1 Reply Last reply
                0
                • L Lost User
                  1. it would take 1000 * 500 miliseconds = 500 seconds if it were sequentially. Which is more than 55 seconds, so, by RAA, it is proven that it wasn't purely sequentially. Now that's a real breakthrough - it means the threading works but the task (without the sleep) is too short. 2) well, not directly. But it works like that without webservers being involved as well. 3) The threading will help when you let the web method do something useful.
                  G Offline
                  G Offline
                  George_George
                  wrote on last edited by
                  #33

                  Thanks harold, 1. "well, not directly. But it works like that without webservers being involved as well." -- confused. Especially what do you mean "without webservers being involved"? There is web server, since I run it as web service and IIS hosts it. :-) 2. "The threading will help when you let the web method do something useful." -- confused about what you mean. Could you describe something more? regards, George

                  L 1 Reply Last reply
                  0
                  • G George_George

                    Thanks PIEBALDconsult, I am not sure what you are going to prove. In your scenario, you have web service (say sleep) and another web service (say sleepless). If we call on a thread from client side, first call sleep web service, then call sleepless web service, since it is synchronous call in one thread from client, the client will definitely wait for the sleep web service to complete the return results until call the second sleepless web service. Please correct me if I am wrong in understanding your points. I am confused what you are going to prove -- so obvious results. :-) regards, George

                    P Offline
                    P Offline
                    PIEBALDconsult
                    wrote on last edited by
                    #34

                    Not two services and one client, one service and two clients.

                    1 Reply Last reply
                    0
                    • G George_George

                      Thanks harold, 1. "well, not directly. But it works like that without webservers being involved as well." -- confused. Especially what do you mean "without webservers being involved"? There is web server, since I run it as web service and IIS hosts it. :-) 2. "The threading will help when you let the web method do something useful." -- confused about what you mean. Could you describe something more? regards, George

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #35

                      1 just means that I tested without using a webserver 2 means that new Random().NextDouble() does not take enough time to be worth multithreading it in this case

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups