none
WCF concurrency and IIS process and thread management

    Question

  • Hi,

    I have this posted in IIS forum as well.

    I just wanted to know whether there is any white paper or architectural document on how IIS manage Concurrency, Thread Pool and Worker Process.

    I just give you a scenario and i wanted to understand how things are managed in IIS7

    I have a WCF service; the service is SINGLE INSTANCE and allow concurrency. WCF service is hosted in IIS.

    Now in IIS the application pool is configured to have a process model with multiple worker process.

    Now my question is when there is concurrent call in WCF service, how IIS manage those calls. Are these concurrent calls managed concurrently by IIS? How this worker processed are spawned? Are these worker process has their own memory space? If i want to share data between these worker process (like caching data) how can be that shared (i dont want session enabled WCF service) as our client is stateless?

    Thank you.

    Regards

    Tanvir


    Tanvir Huda Application Architect/Consultant
    Tuesday, July 05, 2011 4:53 AM

Answers

  • When you say the application pool has several worker processes I assume you mean a web garden, right?

    In that case you have several w3wp processes, each running the same service, and each process has its own single instance of the service - basically the wcf service is unaware that is was started on several processes.

    When a request comes in to IIS, it sends the request to the next process in the list (round-robin style).

    So if you have say 4 processes, and 4 concurrent calls from different clients, each might be handled by a different process.

    Since each worker process is a windows process, it has its own memory space of course, and its own throttling settings.

    If you want to share information between these processes you need to select a technique that enables sharing information between processes such as a memory mapped file or a distributed cache (such as appfabric cache, also know as "velocity"

     

    Some links:

    http://iisadmins.blogspot.com/2011/04/difference-between-web-farm-and-web.html

    http://technet.microsoft.com/en-us/library/cc784869(WS.10).aspx

     

    Now that you know what is a web garden, would you mind explaining why you want to use a web garden? usually it doesn't give that much performance improvements.


    Please mark posts as answers/helpful if it answers your question. Senior Consultant on WCF, ASP.NET, Siverlight, and Entity Framework. Author of Microsoft's Official WCF 4 Course. Co-author of the Microsoft HPC/Azure burst whitepaper. Visit my blog: http://blogs.microsoft.co.il/blogs/idof
    • Marked as answer by Tanvir Huda Friday, July 08, 2011 2:11 AM
    Tuesday, July 05, 2011 5:56 AM
  • Hello, as described by others, if you have more than 1 worker process, each worker process will create a service instance. But why do you need web garden? It doesn't increase the performance of your service. Even if you only have a single worker process, it can use multiple threads, so it can still take advantage of multi-cores. If your concern is to increase performance, you have to use load balance. The only advantage of web garden is: If one worker process crashes (possibly due to a bad request), other worker processes can continue to serve clients. Load balance also provides this advantage.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by Tanvir Huda Friday, July 08, 2011 2:11 AM
    Wednesday, July 06, 2011 2:57 AM
  • Hmm that's really strange ... usually MultiProcessed MultiThreaded environment should perform better than single thread multi-processed environment. This is really odd. 

    So, in conclusion, InstanceContextMode set to single in only work when it is single server and single worker process environment. 

    In Multiple worker thread, each worker thread has its own single instance.

    MultiServer it wont work - which is obvious ... as we deploying the app in different webserver.

     

    Thanks Yi-Lun for your answer. But we dont need to deploy our application in Web-Farm environment (load balancer) in all the cases. But still we want to gain the maximum performance gain from a single server environment. That's where the question of having web-garden come in.  

     

    Thanks you all for your response. 

     


    Tanvir Huda Application Architect/Consultant
    • Marked as answer by Tanvir Huda Friday, July 08, 2011 2:11 AM
    Friday, July 08, 2011 2:10 AM

All replies

  • When you say the application pool has several worker processes I assume you mean a web garden, right?

    In that case you have several w3wp processes, each running the same service, and each process has its own single instance of the service - basically the wcf service is unaware that is was started on several processes.

    When a request comes in to IIS, it sends the request to the next process in the list (round-robin style).

    So if you have say 4 processes, and 4 concurrent calls from different clients, each might be handled by a different process.

    Since each worker process is a windows process, it has its own memory space of course, and its own throttling settings.

    If you want to share information between these processes you need to select a technique that enables sharing information between processes such as a memory mapped file or a distributed cache (such as appfabric cache, also know as "velocity"

     

    Some links:

    http://iisadmins.blogspot.com/2011/04/difference-between-web-farm-and-web.html

    http://technet.microsoft.com/en-us/library/cc784869(WS.10).aspx

     

    Now that you know what is a web garden, would you mind explaining why you want to use a web garden? usually it doesn't give that much performance improvements.


    Please mark posts as answers/helpful if it answers your question. Senior Consultant on WCF, ASP.NET, Siverlight, and Entity Framework. Author of Microsoft's Official WCF 4 Course. Co-author of the Microsoft HPC/Azure burst whitepaper. Visit my blog: http://blogs.microsoft.co.il/blogs/idof
    • Marked as answer by Tanvir Huda Friday, July 08, 2011 2:11 AM
    Tuesday, July 05, 2011 5:56 AM
  • Should you want to continue a webgarden approach for your service, yes each worker process has its own memory space and you cannot share data with the other worker processes by default.

    To overcome this you can leverage Appfabric Caching or any other method which gives the caching responsibility to a 3rd process.

    Tuesday, July 05, 2011 7:43 PM
  • Thanks for your answer. Yeah App fabric is a hot cake now. Everyone is talking about this. But it is very resource intensive as well. So if you have a very dataintensive application hosted in the same machine with app-fabric, there will be a performance issue. You can question why should you put your application in the same server, because not every client effort to have multiple server for our application. I think in web-garden with persistent caching with enterprise library 5.0, it will still work but it has its limitation to. 

    Ido, if WCF instancecontextMode set to single and ConcurrencyMode set to Multiple but we have multiple worker process, does it ignore INSTANCECONTEXTMODE SINGLE. AS you said, it created instance for each worker process, it contradicts what INSTANCECONTEXTMODE.SINGLE means. 

    Thank you once again for you reply. 

     


    Tanvir Huda Application Architect/Consultant
    Wednesday, July 06, 2011 12:01 AM
  • Hello, as described by others, if you have more than 1 worker process, each worker process will create a service instance. But why do you need web garden? It doesn't increase the performance of your service. Even if you only have a single worker process, it can use multiple threads, so it can still take advantage of multi-cores. If your concern is to increase performance, you have to use load balance. The only advantage of web garden is: If one worker process crashes (possibly due to a bad request), other worker processes can continue to serve clients. Load balance also provides this advantage.
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    • Marked as answer by Tanvir Huda Friday, July 08, 2011 2:11 AM
    Wednesday, July 06, 2011 2:57 AM
  • Hmm that's really strange ... usually MultiProcessed MultiThreaded environment should perform better than single thread multi-processed environment. This is really odd. 

    So, in conclusion, InstanceContextMode set to single in only work when it is single server and single worker process environment. 

    In Multiple worker thread, each worker thread has its own single instance.

    MultiServer it wont work - which is obvious ... as we deploying the app in different webserver.

     

    Thanks Yi-Lun for your answer. But we dont need to deploy our application in Web-Farm environment (load balancer) in all the cases. But still we want to gain the maximum performance gain from a single server environment. That's where the question of having web-garden come in.  

     

    Thanks you all for your response. 

     


    Tanvir Huda Application Architect/Consultant
    • Marked as answer by Tanvir Huda Friday, July 08, 2011 2:11 AM
    Friday, July 08, 2011 2:10 AM