All Products
Search
Document Center

API Gateway:Configure an alert rule for an outbound connection pool

Last Updated:Jan 10, 2025

What is an outbound connection pool?

Data is transmitted serially in a persistent connection over HTTP. This means that the sender must wait for the previous request to be acknowledged before they can send the next request. An outbound connection pool provides connection resources for an API Gateway instance to access a backend service.

Assume that you purchased a dedicated instance of the api.s1.small type, whose outbound connection pool size is 1,200, and your backend service requires one second to respond to each request, the maximum outbound requests per second (RPS) supported by the instance is then 1,200. As a result, if your instance sends more than 1,200 requests to the backend service in a second, the excess requests wait in a queue because the connection pool is fully occupied. If the requests fail to obtain connection resources in 500 milliseconds, the Backend service connect failed 'Connection lease request time out error is returned. To prevent such errors, you can configure Simple Log Service to send alerts before connection resources are used up. This way, you can handle the resource insufficiency at the earliest opportunity.

Prerequisites

API Gateway logs are recorded. For more information, see Use Log Service to manage logs of API calls.

Configure an alert rule for the connection pool

Simple Log Service allows you to specify a check frequency and trigger conditions to configure an alert rule, and triggers alerts when the conditions are met. This section describes how to configure an alert rule for outbound connection pools of API Gateway.

If a connection pool is fully occupied, API Gateway returns the Backend service connect failed 'Connection lease request time out' error to the client for excess requests. This error is recorded by the errorMessage field in logs. You can use this error message to configure an alert rule. For more information, see Configure an alert monitoring rule in Log Service.

In Step 2 of the referenced topic, you can configure an alert rule based on the instance ID, error ID, and error message. The following sample code provides a query and analysis statement.

instanceId: apigateway-cn-XXXXX  and errorId : D504CO and '`Connection lease request time out`' 

image.png

Handle a connection resource insufficiency

  • Upgrade the API Gateway instance.

    • If the instance is a shared or serverless instance, you can purchase a dedicated instance and migrate your API group to the new instance. For more information, see Migrate API groups between instances.

    • If the instance is a dedicated instance, you can upgrade the instance specifications in the API Gateway console. For more information, see Change instance specifications.

  • Check the response time required by the backend service. This metric (unit: ms) is recorded by the serviceLatency field in the logs. It refers to the time between the point in time when API Gateway sends a request to the backend service to the point in time when API Gateway receives the last packet of the response from the backend service. Slow responses contribute to the insufficiency of outbound connection resources. Therefore, we recommend that you configure an alert rule for the serviceLatency value as well. If the serviceLatency value remains large, connection resource insufficiency is prone. In this case, you can optimize the backend response to prevent issues.