Skip to content

Commit e7751ce

Browse files
committed
2 parents 26668a7 + 2ba4d41 commit e7751ce

File tree

1 file changed

+21
-112
lines changed

1 file changed

+21
-112
lines changed

articles/load-balancer/load-balancer-tcp-idle-timeout.md

Lines changed: 21 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -11,142 +11,51 @@ ms.devlang: na
1111
ms.topic: article
1212
ms.tgt_pltfrm: na
1313
ms.workload: infrastructure-services
14-
ms.date: 09/25/2017
14+
ms.date: 01/09/2020
1515
ms.author: allensu
1616
---
1717

1818
# Configure TCP idle timeout settings for Azure Load Balancer
1919

20-
[!INCLUDE [load-balancer-basic-sku-include.md](../../includes/load-balancer-basic-sku-include.md)]
20+
[!INCLUDE [updated-for-az](../../includes/updated-for-az.md)]
2121

22+
[!INCLUDE [cloud-shell-try-it.md](../../includes/cloud-shell-try-it.md)]
23+
24+
If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run `Get-Module -ListAvailable Az` to find the installed version. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-Az-ps). If you're running PowerShell locally, you also need to run `Connect-AzAccount` to create a connection with Azure.
25+
26+
## TCP Idle Timeout
2227
In its default configuration, Azure Load Balancer has an idle timeout setting of 4 minutes. If a period of inactivity is longer than the timeout value, there's no guarantee that the TCP or HTTP session is maintained between the client and your cloud service.
2328

2429
When the connection is closed, your client application may receive the following error message: "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server."
2530

26-
A common practice is to use a TCP keep-alive. This practice keeps the connection active for a longer period. For more information, see these [.NET examples](https://msdn.microsoft.com/library/system.net.servicepoint.settcpkeepalive.aspx). With keep-alive enabled, packets are sent during periods of inactivity on the connection. These keep-alive packets ensure that the idle timeout value is never reached and the connection is maintained for a long period.
31+
A common practice is to use a TCP keep-alive. This practice keeps the connection active for a longer period. For more information, see these [.NET examples](https://msdn.microsoft.com/library/system.net.servicepoint.settcpkeepalive.aspx). With keep-alive enabled, packets are sent during periods of inactivity on the connection. Keep-alive packets ensure the idle timeout value isn't reached and the connection is maintained for a long period.
2732

28-
This setting works for inbound connections only. To avoid losing the connection, you must configure the TCP keep-alive with an interval less than the idle timeout setting or increase the idle timeout value. To support such scenarios, we've added support for a configurable idle timeout. You can now set it for a duration of 4 to 30 minutes.
33+
The setting works for inbound connections only. To avoid losing the connection, configure the TCP keep-alive with an interval less than the idle timeout setting or increase the idle timeout value. To support these scenarios, support for a configurable idle timeout has been added. You can now set it for a duration of 4 to 30 minutes.
2934

30-
TCP keep-alive works well for scenarios where battery life is not a constraint. It is not recommended for mobile applications. Using a TCP keep-alive in a mobile application can drain the device battery faster.
35+
TCP keep-alive works for scenarios where battery life isn't a constraint. It isn't recommended for mobile applications. Using a TCP keep-alive in a mobile application can drain the device battery faster.
3136

3237
![TCP timeout](./media/load-balancer-tcp-idle-timeout/image1.png)
3338

34-
The following sections describe how to change idle timeout settings in virtual machines and cloud services.
39+
The following sections describe how to change idle timeout settings for public IP and load balancer resources.
3540

3641
## Configure the TCP timeout for your instance-level public IP to 15 minutes
3742

38-
```powershell
39-
Set-AzurePublicIP -PublicIPName webip -VM MyVM -IdleTimeoutInMinutes 15
40-
```
41-
42-
`IdleTimeoutInMinutes` is optional. If it is not set, the default timeout is 4 minutes. The acceptable timeout range is 4 to 30 minutes.
43-
44-
## Set the idle timeout when creating an Azure endpoint on a virtual machine
45-
46-
To change the timeout setting for an endpoint, use the following:
47-
48-
```powershell
49-
Get-AzureVM -ServiceName "mySvc" -Name "MyVM1" | Add-AzureEndpoint -Name "HttpIn" -Protocol "tcp" -PublicPort 80 -LocalPort 8080 -IdleTimeoutInMinutes 15| Update-AzureVM
43+
```azurepowershell-interactive
44+
$publicIP = Get-AzPublicIpAddress -Name MyPublicIP -ResourceGroupName MyResourceGroup
45+
$publicIP.IdleTimeoutInMinutes = "15"
46+
Set-AzPublicIpAddress -PublicIpAddress $publicIP
5047
```
5148

52-
To retrieve your idle timeout configuration, use the following command:
53-
54-
PS C:\> Get-AzureVM -ServiceName "MyService" -Name "MyVM" | Get-AzureEndpoint
55-
VERBOSE: 6:43:50 PM - Completed Operation: Get Deployment
56-
LBSetName : MyLoadBalancedSet
57-
LocalPort : 80
58-
Name : HTTP
59-
Port : 80
60-
Protocol : tcp
61-
Vip : 65.52.xxx.xxx
62-
ProbePath :
63-
ProbePort : 80
64-
ProbeProtocol : tcp
65-
ProbeIntervalInSeconds : 15
66-
ProbeTimeoutInSeconds : 31
67-
EnableDirectServerReturn : False
68-
Acl : {}
69-
InternalLoadBalancerName :
70-
IdleTimeoutInMinutes : 15
71-
72-
## Set the TCP timeout on a load-balanced endpoint set
73-
74-
If endpoints are part of a load-balanced endpoint set, the TCP timeout must be set on the load-balanced endpoint set. For example:
75-
76-
```powershell
77-
Set-AzureLoadBalancedEndpoint -ServiceName "MyService" -LBSetName "LBSet1" -Protocol tcp -LocalPort 80 -ProbeProtocolTCP -ProbePort 8080 -IdleTimeoutInMinutes 15
78-
```
79-
80-
## Change timeout settings for cloud services
49+
`IdleTimeoutInMinutes` is optional. If it isn't set, the default timeout is 4 minutes. The acceptable timeout range is 4 to 30 minutes.
8150

82-
You can use the Azure SDK to update your cloud service. You make endpoint settings for cloud services in the .csdef file. Updating the TCP timeout for deployment of a cloud service requires a deployment upgrade. An exception is if the TCP timeout is specified only for a public IP. Public IP settings are in the .cscfg file, and you can update them through deployment update and upgrade.
51+
## Set the TCP timeout on a load-balanced rule to 15 minutes
8352

84-
The .csdef changes for endpoint settings are:
85-
86-
```xml
87-
<WorkerRole name="worker-role-name" vmsize="worker-role-size" enableNativeCodeExecution="[true|false]">
88-
<Endpoints>
89-
<InputEndpoint name="input-endpoint-name" protocol="[http|https|tcp|udp]" localPort="local-port-number" port="port-number" certificate="certificate-name" loadBalancerProbe="load-balancer-probe-name" idleTimeoutInMinutes="tcp-timeout" />
90-
</Endpoints>
91-
</WorkerRole>
92-
```
53+
To set the idle timeout for a load balancer, the 'IdleTimeoutInMinutes' is set on the load-balanced rule. For example:
9354

94-
The .cscfg changes for the timeout setting on public IPs are:
95-
96-
```xml
97-
<NetworkConfiguration>
98-
<VirtualNetworkSite name="VNet"/>
99-
<AddressAssignments>
100-
<InstanceAddress roleName="VMRolePersisted">
101-
<PublicIPs>
102-
<PublicIP name="public-ip-name" idleTimeoutInMinutes="timeout-in-minutes"/>
103-
</PublicIPs>
104-
</InstanceAddress>
105-
</AddressAssignments>
106-
</NetworkConfiguration>
55+
```azurepowershell-interactive
56+
$lb = Get-AzLoadBalancer -Name "MyLoadBalancer" -ResourceGroup "MyResourceGroup"
57+
$lb | Set-AzLoadBalancerRuleConfig -Name myLBrule -IdleTimeoutInMinutes 15
10758
```
108-
109-
## REST API example
110-
111-
You can configure the TCP idle timeout by using the service management API. Make sure that the `x-ms-version` header is set to version `2014-06-01` or later. Update the configuration of the specified load-balanced input endpoints on all virtual machines in a deployment.
112-
113-
### Request
114-
115-
POST https://management.core.windows.net/<subscription-id>/services/hostedservices/<cloudservice-name>/deployments/<deployment-name>
116-
117-
### Response
118-
119-
```xml
120-
<LoadBalancedEndpointList xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="https://www.w3.org/2001/XMLSchema-instance">
121-
<InputEndpoint>
122-
<LoadBalancedEndpointSetName>endpoint-set-name</LoadBalancedEndpointSetName>
123-
<LocalPort>local-port-number</LocalPort>
124-
<Port>external-port-number</Port>
125-
<LoadBalancerProbe>
126-
<Path>path-of-probe</Path>
127-
<Port>port-assigned-to-probe</Port>
128-
<Protocol>probe-protocol</Protocol>
129-
<IntervalInSeconds>interval-of-probe</IntervalInSeconds>
130-
<TimeoutInSeconds>timeout-for-probe</TimeoutInSeconds>
131-
</LoadBalancerProbe>
132-
<LoadBalancerName>name-of-internal-loadbalancer</LoadBalancerName>
133-
<Protocol>endpoint-protocol</Protocol>
134-
<IdleTimeoutInMinutes>15</IdleTimeoutInMinutes>
135-
<EnableDirectServerReturn>enable-direct-server-return</EnableDirectServerReturn>
136-
<EndpointACL>
137-
<Rules>
138-
<Rule>
139-
<Order>priority-of-the-rule</Order>
140-
<Action>permit-rule</Action>
141-
<RemoteSubnet>subnet-of-the-rule</RemoteSubnet>
142-
<Description>description-of-the-rule</Description>
143-
</Rule>
144-
</Rules>
145-
</EndpointACL>
146-
</InputEndpoint>
147-
</LoadBalancedEndpointList>
148-
```
149-
15059
## Next steps
15160

15261
[Internal load balancer overview](load-balancer-internal-overview.md)

0 commit comments

Comments
 (0)