Competition Webservices ASMX with Ajax

Asked

Viewed 291 times

2

I realized that when called by XHR, the ASMX webservices can handle few simultaneous requests. Consider the following scenario:

Page ASPX:

 <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:

enter image description here

I expected each request to take approximately 1s, but with each more or less 5 requests, the waiting time increases. That is, the request was on hold, because there were other connections open. My question is: how to increase the number of simultaneous requests, so that more calls take the same time. I know it would not be good if the 100 requests were opened at once, but I find very little the number I currently have.

Searching around, I found the following configuration (web.config) but it didn’t work:

<system.net>
  <connectionManagement>
    <add address="*" 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, in a similar way to the one exposed here. It is not an option now to change the technology.

  • Good question, I do not understand why Asp.net here is little visited.

  • Since you changed the server-side order limit and did not produce the expected results, is it possible that "Bottleneck" is on the client side? There may be an order limit on the customer?

  • I don’t think it’s from the client’s side, so I remember if I made the call from the webservice via c# the result was the same. I think the config that I explained here that is not the correct one, I need to find out what it is, if it exists. I will do the call tests via . NET and post the result here to take the web of a possible bottleneck in the customer.

  • Try to implement your method and your calls asynchronously, this should improve your results.

  • Can you give an example?

1 answer

2

One possible way to address the problem is to declare the [WebMethod] in two parts - one of type IAsyncResult initiating the call and a string that concludes it. I am without access to an IIS server to test, but I based on that post: http://chroniclesofnojo.blogspot.com.br/2011/06/asynchronous-asmx-web-services.html

Also, if you are using ASP 2.0 integrated into IIS7, you need to set the configuration of MaxConcurrentRequestsPerCPU to deal with threading. Source: http://www.iis.net/learn/application-frameworks/building-and-running-aspnet-applications/aspnet-20-breaking-changes-on-iis

  • It does not solve for me this solution for two reasons: one because this approach only works when the service is referenced via Web Reference in Visual Studio. Then the serializer turns to call these two methods as if they were one. I am calling the Webservice via Javascript, so I have no way to deal with it. Otherwise, I am obliged to return in the first method a IAsyncResult, and this will not always be possible in my scenario. As for the MaxConcurrentRequestsPerCPU, I’m using . NET 4.5 and it already resolves it for me.

  • As you call it is not important; the implementation of IAsyncResult is on the server, not the client.

  • It makes a difference yes. There’s no way to make this call using IAsyncResult using Javascipt, because one method ends up turning into two. It is specific for when making the reference via Add Web Reference in Visual Studio.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.