Limite connessioni sul client HTTP su WebServices SOAP

Share

Oggi mi è capitato un caso molto strano su cui da tempo tutti i componenti del team avevano sotto il naso una situazione che non si riuscivano a spiegare.

Una applicazione (in futuro sarà un servizio) in .NET utilizzava un servizio per processare dei dati. Vista la natura dell’elaborazione ci aspettavamo che utilizzando molti thread saremmo riusciti a lavorare un gran numero di documenti grazie a server particolarmente prestanti.

Purtroppo questo non avveniva e le macchine erano costantemente sotto il 25% di utilizzo nonostante avessimo aumentato il numero di thread dell’applicazione.

Solo grazie ad un problema uno dei componenti del team nota una singolare situazione. I thread sull’IIS in attesa di essere smistati dal servizio di elaborazione sullo stesso server sono un numero incongruente con le nostre previsioni. Anzi, un numero costante: 2

Dopo aver riprodotto in laboratorio il medesimo comportamento ci è sembrato plausibile ci fosse una limitazione da qualche parte.

IIS non poteva sicuramente essere visto che, fosse anche solo per esperienza diretta, lo abbiamo visto con diverse centinaia di thread aperti simultaneamente.

Qualche altra ricerca ci ha portato a scoprire una limitazione ben documentata:

Two-Connection Limit

The HTTP specification indicates that an HTTP client should make a maximum of two simultaneous TCP connections to any single server. This keeps a single browser from overloading a server with connection requests when it browses to a page with, say, 120 embedded thumbnail images. Instead of creating 120 TCP connections and sending an HTTP request on each, the browser will only create 2 connections and then start sending the 120 HTTP requests for the thumbnail images on those two pipes. The problem with this approach on the middle tier is that your middle tier may have 50 simultaneous users. If you have to make a MapPoint .NET Web service call for each of those users, then you will have 48 users sitting around waiting in line for one of those two pipes to free up.

 

Direttamente da una pagina di MSDN in cui sono riportate tante altre informazioni utili riguardo a considerazioni di performance riguardo i WebServices.

Una lettura consigliatissima

La soluzione di questo problema è una banale configurazione nella configurazione della vostra applicazione (MYAPP.config)o web (web.config) che includa:

<system.net>
  <connectionManagement>
     <add address="*" maxconnection="8"/>
  </connectionManagement>
</system.net>

Dove maxconnection >2 che è il default.

Non si finisce mai d’imparare.

This entry was posted in .NET Framework, Troubleshooting and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>