2

I am building an Azure Web Role that will need to invoke a lot of external web services.

I remember for ASP.Net 1.1, there was a default maxconnection limit of 2, which you could adjust if your application needed more than that (which was pretty low, let's be honest). On ASP.Net 2.0, I believe they raised this, and the recommendation was 12 times the number of cores.

What are the limits, and the means of adjusting this, on Azure Web Roles? I will have hundreds, or thousands, of concurrent outbound requests going at once. Does this mean that I need bigger instances (more cores), or can I do this by using more "Extra Small" instances and configuring them correctly (even if that means 12 per server)?

Thank you.

Pittsburgh DBA
  • 6,672
  • 2
  • 39
  • 68

1 Answers1

2

The size of your instance will only determine the bandwidth that will be reserved for your instance (XS is 5 Mbps, more info here). What you'll need to do is simply change the DefaultConnectionLimit to more than 2:

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

Add this to your web.config if you want to allow this in your web application. Add the following to your WebRole.cs if you want to invoke services before starting your instance for example:

    public override bool OnStart()
    {
        ServicePointManager.DefaultConnectionLimit = 12;
        return base.OnStart();
    }

Keep in mind that, even if the requests are queued, you'll get a better overall performance if you call the webservices in an asynchronous way. Here is a very basic example (assuming you call a simple REST service, WCF client proxies have better support for asynchronous requests):

<%@ Page Async="true" ... %>

public partial class AsyncPage : System.Web.UI.Page
{
    private WebRequest req;

    void Page_Load (object sender, EventArgs e)
    {
        AddOnPreRenderCompleteAsync (
            new BeginEventHandler(BeginWebServiceCall),
            new EndEventHandler (EndWebServiceCall)
        );
    }

    IAsyncResult BeginWebServiceCall (object sender, EventArgs e, 
        AsyncCallback cb, object state)
    {
        req = WebRequest.Create("http://some.webs.service/rest/api");
        return req.BeginGetResponse (cb, state);
    }
    void EndWebServiceCall (IAsyncResult ar)
    {
        using (var response = req.EndGetResponse(ar))
        {
            using var reader = 
                new StreamReader(response.GetResponseStream()))
            {
                var text = reader.ReadToEnd();
        ...
            }
        }
    }
}
Sandrino Di Mattia
  • 24,739
  • 2
  • 60
  • 65
  • Thank you very much! The page that you referenced also shows how many cores we get on each instance size. At some point, with too many outbound connections, wouldn't an XS be overwhelmed? For example, a Medium, with 2 cores, would have been configured for maxconnection="24" in the past. Is this not the recommendation on Azure? I wonder how many an XS can stand. – Pittsburgh DBA Sep 14 '12 at 14:46
  • I suggest you start with 12 on an XS instance (Small would be even better since you'll get a dedicated core) and do some stress testing to see how it responds. But keep in mind that you'll get better results if you call the webservices using asynchronous requests (I updated my answer). – Sandrino Di Mattia Sep 14 '12 at 14:57
  • And this is a great resource to learn about async requests: http://stackoverflow.com/questions/9453560/why-use-async-requests-instead-of-using-a-larger-threadpool – Sandrino Di Mattia Sep 14 '12 at 15:08