You're viewing **Apigee Edge** documentation.  
[Go to the
**Apigee X** documentation](http://cloud.google.com/apigee/docs/api-platform/antipatterns/disable-persistent-connections). info

> [!NOTE]
> **Note:** This document is applicable for Edge Public and Private Cloud users.


This document explains how to configure the keep alive timeout for the Apigee Edge
Message Processors.


The keep alive timeout on the Message Processor allows a single TCP connection to send and
receive multiple HTTP requests/responses from/to the backend server, instead of opening a new
connection for every request/response pair.


The default value of the keep alive timeout property on the Message Processor is
`60` seconds. This timeout period is applicable to the backend servers configured
in the target endpoint configuration and in the `ServiceCallout` policy of your
API proxy.


The keep alive timeout for Message Processors can be increased or decreased from the default value
of `60` seconds based on your needs. It can be configured in the following ways:

- In the API proxy
  - In the target endpoint
  - In the `ServiceCallout` policy
- On the Message Processor


The following properties control the keep alive timeout on the Message Processors:

| Property name | Location | Description |
|---|---|---|
| `keepalive.timeout.millis` | API proxy: - Target endpoint - `ServiceCallout` policy | This is the maximum idle time for which the Message Processor allows a single TCP connection to send and receive multiple HTTP requests/responses, instead of opening a new connection for every request/response pair. By default, this property takes the value set for the `HTTPClient.keepalive.timeout.millis` property on the Message Processor, where the default value is `60` seconds. If this property is modified with a new timeout value for the target server used in the target endpoint or the `ServiceCallout` policy in the specific API proxy, then the keep alive time only for that specific target server is affected. |
| `HTTPClient.keepalive.timeout.millis` | Message Processor | This is the maximum idle time for which the Message Processor allows a single TCP connection to send and receive multiple HTTP requests/responses, instead of opening a new connection for every request/response pair. This property is used for all the API proxies running on this Message Processor. The default value of this property is `60` seconds. You can either modify this property as explained in [Configuring keep alive timeout on Message Processors](https://docs.apigee.com/how-to-guides/configuring-keep-alive-timeout-on-message-processors#configure-keep-alive-timeout-mp) below, or you can overwrite this value by setting the `keepalive.timeout.millis `property at the API proxy level. |

## Before you begin


Before you use the steps in this document, be sure you understand the following topics:

- If you aren't familiar with keep alive timeout, see the `keepalive.timeout.millis` property description in [TargetEndpoint Transport Property Specification](https://docs.apigee.com/api-platform/reference/endpoint-properties-reference#targetendpointtransportpropertyspecification).
- If you aren't familiar with configuring properties for Edge on Private Cloud, read [How to configure Edge](https://docs.apigee.com/private-cloud/v4.50.00/how-configure-edge).

> [!NOTE]
> **Note:** Ensure that you set an appropriate value for the keep alive timeout property based on your needs. Do not set very low values. For example, setting a value of zero (0) results in disabling keep alive, which is an antipattern as described in [Antipattern: Disable HTTP persistent (reusable keep alive) connections](https://docs.apigee.com/api-platform/antipatterns/disable-persistent-connections).

## Configuring keep alive timeout in API proxy


The keep alive timeout can be configured in the API proxy in the following places:

- Target endpoint
- `ServiceCallout` policy

### Configuring keep alive timeout in target endpoint of API proxy


This section explains how to configure keep alive timeout in the target endpoint of your
API proxy. The keep alive timeout can be configured through the property
`keepalive.timeout.millis`, which represents the keep alive timeout value in
milliseconds.

> [!NOTE]
> **Note:** Configuring the keep alive timeout in the target endpoint of your API proxy overrides the default value (`60` seconds) with the new value and affects only the specific API proxy where it is configured. The rest of the API Proxies continue to use the default keep alive timeout value of `60` seconds.

> [!TIP]
> **Required permissions:** To perform this task, you must have edit access permissions to the specific API proxy in which you would like to configure the keep alive timeout.

1. In the Edge UI, select the specific API proxy in which you would like to configure the new keep alive timeout value.
2. Select the specific target endpoint that you want to modify.
3.
   Add the property `keepalive.timeout.millis `with an appropriate value under the
   `<HTTPTargetConnection>` element in the `TargetEndpoint` configuration.


   For example, to change the keep alive Timeout to `30` seconds, add the
   following block of code:

   ```
   <Properties>
     <Property name="keepalive.timeout.millis">30000</Property>
   </Properties>
   ```


   Since the `keepalive.timeout.millis` property is in milliseconds, the value for
   `30` seconds is `30000`.


   The following examples show how to configure the keep alive timeout in the target endpoint
   configuration of your API proxy:


   **Example target endpoint configuration using URL for backend server**

   ```
   <TargetEndpoint name="default">
     <HTTPTargetConnection>
       <URL>https://mocktarget.apigee.net/json</URL>
       <Properties>
         <Property name="keepalive.timeout.millis">30000</Property>
       </Properties>
     </HTTPTargetConnection>
   </TargetEndpoint>
   ```


   **Example target endpoint configuration using target server**

   ```
   <TargetEndpoint name="default">
     <HTTPTargetConnection>
       <LoadBalancer>
         <Server name="target1" />
         <Server name="target2" />
       </LoadBalancer>
       <Properties>
         <Property name="keepalive.timeout.millis">30000</Property>
       </Properties>
       <Path>/test</Path>
     </HTTPTargetConnection>
   </TargetEndpoint>
   ```

   > [!NOTE]
   > **Note:**Property values can be only literals. You cannot set values using variables.

4. Save the changes made to your API proxy.

### Configuring keep alive timeout in ServiceCallout policy of API proxy


This section explains how to configure the keep alive timeout in the
`ServiceCallout` policy of your API proxy. The keep alive timeout can be
configured through` the keepalive.timeout.millis` property, which represents
the keep alive timeout value in milliseconds.

> [!NOTE]
> **Note:** Configuring the keep alive timeout in the `ServiceCallout` policy of the API proxy overrides the default value (`60` seconds) with the new value and affects only the specific `ServiceCallout` policy where it is configured. The rest of the `ServiceCallout` policies and API Proxies continue to use the default keep alive timeout value of `60` seconds.

> [!TIP]
> **Required permissions:** To perform this task, you must have edit access permissions to the specific API proxy in which you would like to configure the keep alive timeout for the `ServiceCallout` policy.


To configure the keep alive timeout in the `ServiceCallout` policy using the
`keepalive.timeout.millis` property:

1. In the Edge UI, select the specific API proxy in which you would like to configure the new keep alive timeout value for the `ServiceCallout` policy.
2. Select the specific `ServiceCallout` policy that you want to modify.
3. Add the property `keepalive.timeout.millis` with an appropriate value under the `<HTTPTargetConnection>` element in the `TargetEndpoint` configuration.


   For example to change the keep alive timeout to `30` seconds, add the
   following block of code:

   ```
   <Properties>
     <Property name="keepalive.timeout.millis">30000</Property>
   </Properties>
   ```


   Since the `keepalive.timeout.millis` property is in milliseconds, the value for
   `30` seconds is `30000`.


   The following examples show how to configure the keep alive timeout in the
   `ServiceCallout` policy of your API proxy:

   **Example ServiceCallout policy configuration using URL for backend server**

   ```
   <ServiceCallout name="Service-Callout-1">
     <DisplayName>Service Callout-1</DisplayName>
     <HTTPTargetConnection>
       <Properties>
         <Property name="keepalive.timeout.millis">30000</Property>
       </Properties>
       <URL>https://mocktarget.apigee.net/json</URL>
     </HTTPTargetConnection>
   </ServiceCallout>
   ```

   **Example ServiceCallout policy configuration using target server**

   ```
   <ServiceCallout enabled="true" name="Service-Callout-1">
     <DisplayName>Service Callout-1</DisplayName>
     <Response>calloutResponse</Response>
     <HTTPTargetConnection>
       <LoadBalancer>
         <Server name="target1" />
         <Server name="target2" />
       </LoadBalancer>
       <Properties>
         <Property name="keepalive.timeout.millis">30000</Property>
       </Properties>
       <Path>/test</Path>
     </HTTPTargetConnection>
   </ServiceCallout>
   ```

   > [!NOTE]
   > **Note:**Property values can be only literals. You cannot set values using variables.

4. Save the changes made to your API proxy.

## Configuring keep alive timeout on Message Processors


This section explains how to configure the keep alive timeout on the Message Processors. The
keep alive timeout can be configured through the property
`HTTPClient.keepalive.timeout.millis`, which represents the keep alive timeout
value in milliseconds on the Message Processor component. Since this property is commented on
the Message Processor, you need to use the special syntax
`conf/http.properties+HTTPClient.keepalive.timeout.millis` as described in the section
[Set a token that is currently commented out](https://docs.apigee.com/private-cloud/v4.50.00/how-configure-edge#settingatokenthatiscurrentlycommentedout) in
[How to configure Edge](https://docs.apigee.com/private-cloud/v4.50.00/how-configure-edge).

> [!NOTE]
> **Note:**If a change is made at the Message Processor level, it is important to note that it affects the keep alive timeout of all the API proxies associated with the organizations and environments served by the specific Message Processors.

> [!TIP]
> **Required permissions:** To perform this task, you must have the following permissions:
>
> - Access to the specific Message Processor, where you would like to configure the keep alive timeout.
> - Access to create or edit the Message Processor component properties file in the `/opt/apigee/customer/application` folder.


To configure the keep alive timeout on the Message Processors, do the following:

1. On the Message Processor machine, open the following file in an editor. If it does not already exist, then create it.

   ```
   /opt/apigee/customer/application/message-processor.properties
   ```

   For example, to open the file using
   `https://en.wikipedia.org/wiki/Vi`, enter the following:

   ```
   vi /opt/apigee/customer/application/message-processor.properties
   ```
2. Add a line in the following format to the properties file, substituting a value for <var translate="no">TIME_IN_MILLISECONDS</var>:

   ```
   conf/http.properties+HTTPClient.keepalive.timeout.millis=TIME_IN_MILLISECONDS
   ```


   For example, to change the keep alive timeout on the Message Processor to
   `30` seconds, add the following line:

   ```
   conf/http.properties+HTTPClient.keepalive.timeout.millis=30000
   ```
3. Save your changes.
4. Ensure the properties file is owned by the `apigee` user as shown below:

   ```
   chown apigee:apigee /opt/apigee/customer/application/message-processor.properties
   ```
5. Restart the Message Processor as shown below:

   ```
   /opt/apigee/apigee-service/bin/apigee-service edge-message-processor restart
   ```
6. If you have more than one Message Processor, repeat the above steps on all the Message Processors.

## Verifying keep alive timeout on Message Processors


This section explains how to verify that the keep alive timeout has been successfully modified
on the Message Processors.


Even though you use the special syntax
`conf/http.properties+HTTPClient.keepalive.timeout.millis` to set the keep alive
timeout on the Message processor, you need to verify if the actual property
`HTTPClient.keepalive.timeout.millis` has been set with the new value.

1. On the Message Processor machine, search for the property `HTTPClient.keepalive.timeout.millis` in the `/opt/apigee/edge-message-processor/conf` directory and check to see if it has been set with the new value as shown below:

   ```
   grep -ri "HTTPClient.keepalive.timeout.millis" /opt/apigee/edge-message-processor/conf
   ```
2.
   If the new keep alive timeout value is successfully set on the Message Processor, then
   the above command shows the new value in the `http.properties` file.


   The sample result from the above command after you have configured keep alive timeout
   to `30` seconds is as follows:

   ```
   /opt/apigee/edge-message-processor/conf/http.properties:HTTPClient.keepalive.timeout.millis=30000
   ```


   In the example output above, notice that the property
   `HTTPClient.keepalive.timeout.millis` has been set with the new value
   `30000` in `http.properties`. This indicates that the keep alive
   timeout is successfully configured to `30` seconds on the Message Processor.
3. If you still see the old value for the property `HTTPClient.keepalive.timeout.millis`, then verify that you have followed all the steps outlined in [Configuring keep alive timeout on Message Processors](https://docs.apigee.com/how-to-guides/configuring-keep-alive-timeout-on-message-processors#configure-keep-alive-timeout-mp) correctly. If you have missed any step, repeat all the steps again correctly.
4. If you are still not able to modify the keep alive timeout, then contact Google Cloud [Apigee Edge Support](https://docs.apigee.com/api-platform/troubleshoot/support).