none
WCF Throttling feature not working RRS feed

  • Question

  • I'm trying to implement a CMD.EXE/Cygwin-bash execution queue where I can submit dozens of commands and my WCF/MSMQ service will spawn a child process to execute them one at a time.

    Everything seems to be working fine except the throttling. When I submit my commands (each of which redirects std output and std error to a log file in %LOGS%) I see that multiple log files are created simultaneously and they grow simultaneously indicating that my WCF Service has successfully created multiple simultaneous threads that create multiple processes running CMD.EXD or (Cygwin bash).

    This is not what I want! I want a maximum of one active/growing log file at a time indicating the other CMD.EXE commands have been queued and a single CMD.EXE command has been removed and sent to a single process executing CMD.EXE. And when that is done the next command is removed from the queue sent to a new child process running CMD.EXE.  

    After some Bing/Google searching on WCF throttling I added the following code:

    namespace MSMQNoSecurityService {
        [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single,InstanceContextMode=InstanceContextMode.Single)]
        public class MSMQService : IMSMQService {

    The appconfig also contains these statements:

        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="True" />
              <serviceDebug includeExceptionDetailInFaults="False" />
            <!-- Specify throttling behavior -->
            <serviceThrottling maxConcurrentCalls="1" maxConcurrentInstances="1" maxConcurrentSessions="1"/>
          </behavior>
        </serviceBehaviors>
        </behaviors>

    So what am I missing? Why is my WCF MSMQ service still spawning multiple child processes to execute my CMD.EXE commands simultaneously?

    Most recently I've been using this article as a guide:  http://www.codeproject.com/Articles/33362/WCF-Throttling

    Thanks!

    Siegfried


    siegfried heintze



    • Edited by siegfried_ Monday, December 28, 2015 10:11 PM
    Monday, December 28, 2015 9:49 PM

Answers

  • Hi Siegfried,

    According to your description, you want to use one child  processes to execute

    your CMD.EXE commands simultaneously? If I miss understand your question,

    please let me know.

    I refer to that link which you post as a guide article. I create a test project. And add

    the following code to my service:

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession,ConcurrencyMode=ConcurrencyMode.Single)]Then set the configuration file as below:Then set the configuration file as below:

    And set the configuration file as below:

     <serviceThrottling maxConcurrentCalls="1" maxConcurrentSessions="1"/>Next, I run the project, it just one thread running.

    Then, I will see that just one process running.

    For your issue, in my opinion, you need to try set the InstanceContextMode as Persession.

    Because, the single mode with a session and one InstanceContex for all calls.

    the persession mode with a session and one InstanceContex for each channel.

    When it create the channel, for every channel, it created by one process and disposed by same process.

    For more information, please refer to the following articles:

    1.Sessions, Instancing, and Concurrency

    If you have any question, please let me know.

    Best Regards,

    Wanjun Dong


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    Tuesday, January 5, 2016 3:20 AM
    Moderator

All replies

  • Hi  Siegfried,

    I do this sample in my machine. That worked fine, so I will suggest you need to check the config

    is correctly.

    I just set the  maxConcurrentCalls="5" maxConcurrentInstances ="5" in my app.config file.

    Best Regards,

    Vince Li,

    Wednesday, December 30, 2015 2:39 AM
  • I'm confused.

    (1) Is there something wrong with the fragment of the config I posted? Did I post too small of a fragment?

    (2) What do you mean when you say it worked fine? Where you able to confirm that no two  WCF worker (or dispatch -- what are they called?) threads were executing concurrently? It looks like you should have many concurrent threads with that config and that is not what I want. How did you confirm they were not running concurrently?

    Thanks!

    Siegfried

    Here is my entire App.config for your reading pleasure:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <compilation debug="true" />
      </system.web>
    
      <system.serviceModel>
        <services>
          <service name="MSMQNoSecurityService.MSMQService">
            <host>
              <baseAddresses>
                <add baseAddress="http://km:8080/Design_Time_Addresses/MSMQNoSecurityService/MSMQService/"/>
              </baseAddresses>
            </host>
            <endpoint address="net.msmq://km/private/TestQueue"
                      binding="netMsmqBinding" bindingConfiguration="MyBinding"
                      contract="MSMQNoSecurityService.IMSMQService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="True" />
              <serviceDebug includeExceptionDetailInFaults="False" />
            <!-- Specify throttling behavior -->
            <serviceThrottling maxConcurrentCalls="1" maxConcurrentInstances="1" maxConcurrentSessions="1"/>
          </behavior>
        </serviceBehaviors>
        </behaviors>
    
        <bindings>
          <netMsmqBinding>
            <binding name="MyBinding"  >
              <security mode="None"/>
            </binding>
          </netMsmqBinding>
        </bindings>
      </system.serviceModel>
      <system.diagnostics>
        <!--
        <sources>
          <surce name="System.ServiceModel"
                switchValue="Critical,Information,ActivityTracing"
                    propagateActivity="true">
            <listeners>
              <add name="messages"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="c:\Users\siegfried\Documents\logs\wcftrace.log" />
            </listeners>
          </source>
        </sources>
        -->
        <trace autoflush="true" />
        <!--
        <sources>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
              <add name="messages"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="c:\Users\siegfried\Documents\logs\wcflog.log" />
            </listeners>
          </source>
        </sources>-->
      </system.diagnostics>
    
      <system.serviceModel>
        <diagnostics>
          <messageLogging
                  logEntireMessage="false"
                  logMalformedMessages="true"
                  logMessagesAtServiceLevel="true"
                  logMessagesAtTransportLevel="false"
                  maxMessagesToLog="500"
                  maxSizeOfMessageToLog="5000"/>
        </diagnostics>
      </system.serviceModel>
    
    
    </configuration>
    


    siegfried heintze

    Wednesday, December 30, 2015 8:57 PM
  • Hi Siegfried,

    According to your description, you want to use one child  processes to execute

    your CMD.EXE commands simultaneously? If I miss understand your question,

    please let me know.

    I refer to that link which you post as a guide article. I create a test project. And add

    the following code to my service:

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession,ConcurrencyMode=ConcurrencyMode.Single)]Then set the configuration file as below:Then set the configuration file as below:

    And set the configuration file as below:

     <serviceThrottling maxConcurrentCalls="1" maxConcurrentSessions="1"/>Next, I run the project, it just one thread running.

    Then, I will see that just one process running.

    For your issue, in my opinion, you need to try set the InstanceContextMode as Persession.

    Because, the single mode with a session and one InstanceContex for all calls.

    the persession mode with a session and one InstanceContex for each channel.

    When it create the channel, for every channel, it created by one process and disposed by same process.

    For more information, please refer to the following articles:

    1.Sessions, Instancing, and Concurrency

    If you have any question, please let me know.

    Best Regards,

    Wanjun Dong


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    Tuesday, January 5, 2016 3:20 AM
    Moderator
  • Thank you. As per your link, this did the trick:

        [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single,InstanceContextMode=
        InstanceContextMode.PerSession
        //InstanceContextMode.Single
        )]


    siegfried heintze

    Tuesday, January 5, 2016 5:28 AM