You can create isolation rules to control the number of concurrent threads of interfaces or dependencies to ensure the system stability. In most cases, isolation rules are applied to scenarios in which the internal processing of an application or the performance of a downstream application on which the application depends is unstable. For example, you can use isolation rules if the execution of SQL statements is slow in an application or responses from a downstream application on which the application depends have a high latency. This topic describes how to create an isolation rule.
Prerequisites
Microservices Engine (MSE) Enterprise Edition is activated.
The Microservices Governance feature of MSE is enabled for your microservices applications. For more information, see the following topics:
Background information
If a method or an interface of a strongly dependent application is unstable, you can specify the maximum number of concurrent threads to limit the number of concurrent threads of the strongly dependent application. This helps isolate exceptions. If the response time of requests becomes longer, the number of concurrent threads increases. If the number of concurrent threads exceeds the threshold, Application High Availability Service rejects the excess requests until the accumulated requests are processed and the number of concurrent threads decreases. This way, exceptions can be isolated and stability is ensured.
You can refer to the following formula to specify a threshold of concurrent threads:
Maximum number of concurrent threads = Expected QPS × Response time of a request + Number of redundant requests
For example, the expected response time for executing an SQL statement is 20 milliseconds, the expected queries per second (QPS) is 20, and the maximum number of concurrent requests is 6. In this case, we recommend that you specify the maximum number of concurrent threads based on the following logic: The value of Max(20/1000 × 20,6) is 6 and the number of redundant requests is 2. Based on the preceding formula, we recommend that you specify 8 as the maximum number of concurrent threads.
After the maximum number of concurrent threads is specified, if a deadlock or a performance issue occurs in the SQL statement and the execution of the SQL statement is slow, only eight threads are occupied and the active threads of the process are not exhausted even if more and more requests are received and the requests cannot be ended in a short period of time.
After the SQL statement becomes normal, the number of concurrent threads decreases. When the number of concurrent threads is less than the specified threshold, the system does not reject requests and the processing capability of the application is restored. This way, the number of concurrent threads is automatically adjusted based on the response time of requests and unstable applications are isolated.
In most cases, isolation rules are applied to scenarios in which strongly dependent applications need to be isolated.
Procedure
Log on to the MSE console, and select a region in the top navigation bar.
In the left-side navigation pane, choose Microservices Governance > Application Governance.
On the Application list page, click the resource card of the destination application.
On the details page of the application, create an isolation rule by using one of the following methods:
In the left-side navigation pane, click Application overview. On the page that appears, click the Through QPS TOP tab. On the Through QPS TOP tab, find the interface to which you want to apply the isolation rule and click Isolation in the Actions column.
In the left-side navigation pane, click API Details. On the WEB service tab of the page that appears, click the Concurrency Isolation tab. On the Concurrency Isolation tab, click Add isolation rule.
In the left-side navigation pane, click Traffic management. On the page that appears, click the Flow protection tab. On the Flow protection tab, click the Concurrency Isolation tab. On the Concurrency Isolation tab, click Add isolation rule.
In the Add Isolation Protection Rule or Add Rule dialog box, configure the rule parameters and click New.
NoteFor more information about the rule parameters, see the Parameters section of this topic.
Common example: Ensure sufficient resources
If the response time of requests becomes longer, the number of concurrent threads increases. If the number of concurrent threads exceeds the threshold, Application High Availability Service rejects the excess requests until the accumulated requests are processed and the number of concurrent threads decreases. This way, exceptions can be isolated and stability is ensured. For example, the execution time of an SQL statement is 20 milliseconds and the expected QPS is 20.
In the Add Isolation Protection Rule or Add Rule dialog box, configure the following parameters:
Specify the Interface name parameter.
Set the Concurrency threshold parameter to 10.
After the configuration is complete, if a deadlock or a performance issue occurs in the SQL statement and the execution of the SQL statement is slow, only 10 threads are occupied and the active threads of the process are not exhausted even if more and more requests are received and the requests cannot be ended in a short period of time. After the SQL statement becomes normal, the number of concurrent threads decreases. When the number of concurrent threads is less than the specified threshold, the system does not reject requests and the processing capability of the application is restored. This way, the number of concurrent threads is automatically adjusted based on the response time of requests and unstable applications are isolated.
Parameters
The following table describes the parameters that you must configure in the Add Isolation Protection Rule or Add Rule dialog box.
Parameter | Description |
Interface name | The name of the interface to which you want to apply the isolation rule. |
Concurrency threshold | The maximum number of concurrent threads for the interface, which indicates the maximum number of interface threads that are running. |