2013-04-13 8 views
5

Mi rendo conto che ci sono un sacco di domande relative a questo già, ma indipendentemente da ciò che provo, sembra che ci sia qualcosa di diverso sul mio problema che mantiene le altre soluzioni da riparandolo.Servizio WCF che gestisce solo 10 chiamate simultanee a prescindere da quello che faccio

Ecco il problema: ho un semplice servizio WCF. Sembra consentire solo 10 chiamate simultanee, ho bisogno di supportare più di questo. Questo a prescindere da cosa ho impostato il mio maxConcurrentCalls nella mia configurazione. In questo caso, per semplificare il problema non ho nemmeno un vero client WCF .Net che lo chiami, sto semplicemente usando il violinista su alcune macchine per emettere un mucchio di post HTTP al servizio. Lavorano tutti individualmente, ma li vedo arrivare in 10 alla volta. Come finisce # 1, inizia # 11 e così via.

Il mio servizio è un semplice "sleep per 30 secondi e restituisce una stringa" per questo esempio.

Di seguito è il mio web.config. Potete vedere che ho aumentato il mio maxConcurrentCalls e il mio maxConcurrentSessions a più dei valori predefiniti. Questo sembra non avere alcun impatto visto che vedo ancora solo 10 richieste simultanee alla volta.

Quale parte mi manca per eseguire questa operazione per consentire più richieste simultanee?

Modifica: è ospitato in IIS 7.5.

web.config:

<configuration> 
<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
</system.web> 

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    <security> 
     <authentication> 
      <anonymousAuthentication enabled="true" /> 
     </authentication> 
    </security> 
</system.webServer> 
<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior name=""> 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 
       <serviceThrottling 
        maxConcurrentCalls="32" 
        maxConcurrentInstances="2147483647" 
        maxConcurrentSessions="20"/> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 
</configuration> 

Servizio:

using System; 
using System.ServiceModel; 

namespace WCFTestService 
{ 
    using System.Diagnostics; 
    using System.Threading; 

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)] 
    public class TestService : ITestService 
    { 

     public string RequestIdentifier { get; set; } 

     public int i; 

     public string DoWork(string id) 
     { 
      var secondsBeforeResponding = 20; 

      i++; 

      this.RequestIdentifier = id; 

      Debug.WriteLine("Request: " + id + " Instance:" + i.ToString() + " Thread:" + Thread.CurrentThread.ManagedThreadId.ToString() + " Time:" + DateTime.Now.ToString()); 

      Thread.Sleep(secondsBeforeResponding * 1000); 

      Debug.WriteLine("               Done with request: " + this.RequestIdentifier); 

      return "Done with request: " + this.RequestIdentifier; 
     } 
    } 
} 

ITestService:

[ServiceContract(SessionMode = SessionMode.NotAllowed)] 
public interface ITestService 
{ 
    [OperationContract] 
    string DoWork(string requestIdentifier); 
} 

uscita:

Request: b3 Instance:1 Thread:54 Time:4/13/2013 1:50:31 PM <!--- this is the first 10, they all start at pretty much the same time 
Request: b4 Instance:1 Thread:47 Time:4/13/2013 1:50:31 PM 
Request: b1 Instance:1 Thread:48 Time:4/13/2013 1:50:31 PM 
Request: b2 Instance:1 Thread:45 Time:4/13/2013 1:50:31 PM 
Request: b5 Instance:1 Thread:44 Time:4/13/2013 1:50:31 PM 
Request: b6 Instance:1 Thread:42 Time:4/13/2013 1:50:31 PM 
Request: b7 Instance:1 Thread:41 Time:4/13/2013 1:50:32 PM 
Request: b8 Instance:1 Thread:39 Time:4/13/2013 1:50:32 PM 
Request: b9 Instance:1 Thread:40 Time:4/13/2013 1:50:33 PM 
Request: b10 Instance:1 Thread:38 Time:4/13/2013 1:50:34 PM 
                  Done with request: b3 
                  Done with request: b4 
                  Done with request: b1 
                  Done with request: b2 
Request: b11 Instance:1 Thread:35 Time:4/13/2013 1:50:51 PM <--- this request only starts after the first one finishes 
Request: b13 Instance:1 Thread:45 Time:4/13/2013 1:50:51 PM 
Request: b14 Instance:1 Thread:54 Time:4/13/2013 1:50:51 PM 
Request: b12 Instance:1 Thread:37 Time:4/13/2013 1:50:51 PM 
                  Done with request: b5 
Request: b15 Instance:1 Thread:44 Time:4/13/2013 1:50:51 PM 
                  Done with request: b6 
Request: b16 Instance:1 Thread:42 Time:4/13/2013 1:50:51 PM 
                  Done with request: b7 
Request: b17 Instance:1 Thread:41 Time:4/13/2013 1:50:52 PM 
                  Done with request: b8 
Request: b18 Instance:1 Thread:39 Time:4/13/2013 1:50:52 PM 
                  Done with request: b9 
Request: b19 Instance:1 Thread:40 Time:4/13/2013 1:50:53 PM 
                  Done with request: b10 
Request: b20 Instance:1 Thread:38 Time:4/13/2013 1:50:54 PM 
... 
... 
... 
+0

Questo servizio è ospitato in IIS (quale versione?) O stai facendo auto-hosting? –

+0

Ospitato in IIS. IIS versione 7.5. –

+0

Che legame stai usando? Inoltre, il valore predefinito per 'maxConcurrentCalls' è 16, non 10. Il valore predefinito per' maxConcurrentSesions' è 10. Suggerirei di scrivere una semplice app per console per creare un client (che crea un canale) per testare la massima sicurezza: non lo farei essere sorpreso di vederlo funzionare in quel caso. – Tim

risposta

5

È possibile che si stiano verificando limitazioni del sistema operativo. Prova a distribuire il tuo servizio su un server e riproduci il comportamento da lì.

+1

Questo è esattamente quello che era. Ho distribuito la mia applicazione di test dalla mia casella di sviluppo di Windows 7 a un server 2008 e tutto ha funzionato come dovrebbe. Ciò significa che il 'maxConcurrentCalls' nella configurazione ha controllato correttamente quante connessioni in ingresso potrei gestire.[Link a una spiegazione migliore qui] (http://stackoverflow.com/questions/7822477/wcf-max-instance-seems-to-be-limited-to-10) –

Problemi correlati