AppService TCP connections

AzureUser-9588 141 Reputation points
2020-12-01T06:47:52.857+00:00

There is a limitation on number of TCP connections for an AppService instance depending on its pricing tier. Currently to achieve the higher number of TCP connections for applications, increasing the number of AppService instances. Doing this doesn't look like a cost optimal solution, as most of the other AppService resources are pretty much underutilized. Is there any workaround/solution to handle this in a better way? Anything coming up sooner or later?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,874 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anand 6 Reputation points Microsoft Employee
    2022-10-10T16:44:42.37+00:00

    How is these TCP limits documented in App Service plan Limit? I did not see Max Connection limit in the Azure Subscription limit document for App Service.

    1 person found this answer helpful.
    0 comments No comments

  2. SnehaAgrawal-MSFT 18,286 Reputation points
    2020-12-01T12:02:40.387+00:00

    Thanks for asking question! Yes you are correct there is a limitation on number of TCP connections for an AppService instance depending on its pricing tier.

    The maximum connection limits are the following:
    • 1,920 connections per B1/S1/P1 instance
    • 3,968 connections per B2/S2/P2 instance
    • 8,064 connections per B3/S3/P3 instance
    • 64K max upper limit per App Service Environment

    Applications that “leak” connections invariably run into these connection limits and will start intermittently failing because calls to remote endpoints fail, with the failures sometimes correlating closely to periods of higher application load.

    The likelihood of running into this problem can be substantially mitigated with a few best practices:

    1. For .NET applications using ADO.NET/EF, use database connection pooling.
    2. For php/mySql, use persistent database connections.
    3. For Node.js applications making outbound HTTP/HTTPS calls, configure keep-alives so that outbound connections are reused.
      Check: My node application is making excessive outbound calls
    4. For .NET applications making outbound HTTP/HTTPS calls, pool and reuse instances of System.Net.Http.HttpClient or use Keep-alive connections with System.Net.HttpWebRequest.

    Note: Remember to increase the System.Net.ServicePointManager.DefaultConnectionLimit because you’ll otherwise be limited to two concurrent outbound connections to the same endpoint.

    Check article which is helpful in minimizing the number of outbound connections using HttpClient

    To add avoiding the outbound TCP limits is easier to solve, as the limits are set by the size of your worker. You can see the limits in Sandbox Cross VM Numerical Limits - TCP Connections To avoid outbound TCP limits, you can either increase the size of your workers, or scale out horizontally.

    You can also refer to blog on How to deal with the limits of Azure SQL Database maximum logins

    Refer: Deep Dive into TCP Connections in App Service Diagnostics

    Also, Check out the TCP Connections added to App Service diagnostics for analyzing unhealthy TCP connections.

    Let us know how it goes.