Competition WebServices ASMX with Ajax

2

I noticed that when called by XHR, ASMX webservices can handle very few concurrent requests. Consider the following scenario:

ASPX Page:

 <asp:ScriptManager ID="scrManager" runat="server">
     <Services>
         <asp:ServiceReference Path="~/WebService.asmx" />
     </Services>
 </asp:ScriptManager>

WebService Method:

[WebMethod]
public string HelloWorld()
{
   Thread.Sleep(1000);
   return "Hello World";
}

And the Javascript code that calls it:

$(document).ready(function () {
    var ws = new WebApplication1.WebService();

    for (var i = 0; i < 100; i++) {
        var start = new Date().getTime();
        function sucesso() {
            var end = new Date().getTime();
            var time = end - start;
            console.log('Duração: ' + time);
        }

        ws.HelloWorld(sucesso, function () { alert("erro"); });
    }
});

And the result is more or less this:

Iexpectedeachrequesttotakeapproximately1s,butforevery5ormorerequests,thewaitingtimeincreases.Thatis,therequestwasputonholdastherewereotheropenconnections.Myquestionis:howtoincreasethenumberofsimultaneousrequests,sothatmorecallstakethesametime.Iknowitwouldnotbegoodifthe100requestswereopenedatonetime,butIfindthenumberveryfewthatIcurrentlyhave.

Searchingaround,Ifoundthefollowingconfiguration(web.config)butitdidnotwork:

<system.net><connectionManagement><addaddress="*" maxconnection="40"/>
  </connectionManagement>
 </system.net>

Note: I know that web services made with asmx are a legacy technology, but I have a whole large system that uses them on the front end, similarly to the one exposed here. It is not an option now to change the technology.

    
asked by anonymous 28.05.2015 / 14:01

1 answer

2

One possible way to address the problem is to declare [WebMethod] in two parts - one of type IAsyncResult that initiates the call and one of type string that ends it. I am not accessing an IIS server to test, but I relied on this post: link

In addition, if you are using ASP 2.0 integrated with IIS7, you need to set the MaxConcurrentRequestsPerCPU setting to deal with threading. Source: link

    
31.05.2015 / 18:17