All Products
Search
Document Center

Microservices Engine:Graceful shutdown

Last Updated:Oct 14, 2024

When you update an online application, you must ensure service continuity during the period of time in which the application is stopped and restarted. If you want to deploy, stop, roll back, scale in, or reset an application, you can configure the graceful shutdown feature provided by Microservices Engine (MSE) Microservices Governance to ensure that the application is shut down without affecting your business. This topic describes the usage notes and benefits of the graceful shutdown feature and how to use the feature in the MSE console.

Background information

If the application instance that serves as the provider is directly shut down in high concurrency scenarios, the application instance that serves as the consumer cannot perceive the status of the downstream provider in real time due to the calling characteristics of microservice applications. The consumer continues to forward requests to the provider that is shut down. As a result, a request error is reported and traffic loss occurs.

How graceful shutdown works

When Provider A is shut down, Microservices Registry is notified of the shutdown event. However, Consumer B may not become aware of the shutdown event in real time. As a result, Consumer B continues to call Provider A after Provider A is shut down. The graceful shutdown feature is introduced to resolve this issue. After Provider A receives a shutdown command, Provider A waits to be shut down and adds a special tag to the responses to the requests that are received during the waiting period. After Consumer B receives the responses to which special tags are added, Consumer B proactively obtains the application instance information from Microservices Registry. This allows Consumer B to perceive the status of Provider A in real time and become aware of the shutdown of Provider A. Provider A also waits for a period of time to ensure that all in-transit requests are executed before it is shut down.

Note

If MSE Microservices Governance is enabled for an application, the graceful shutdown feature is automatically enabled for the application. However, if you want to use the proactive notification capability of graceful shutdown, you must manually enable this capability for graceful shutdown. The graceful start and shutdown features of MSE also provide observability that helps you determine whether an application is gracefully shut down.

Observe graceful shutdown

If the graceful shutdown feature is enabled for an application and the application is shut down, you can observe that the traffic of the application becomes unavailable within a short period of time and the queries per second (QPS) value drops to zero on the application governance page.

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Governance > Application Governance. On the page that appears, click the resource card of the application that you want to manage.

  3. On the application details page, click Traffic management in the left-side navigation pane, and click the Lossless up and down line tab.

In the middle part of the page, you can view the events that occurred during the graceful start and shutdown of the application in the recent period. In the left-side View Node section, find and click a successful shutdown event of the application that is recently shut down. The displayed information shows that the traffic of the application quickly drops to zero when the event occurs.

image

Important

If the QPS data does not quickly drop to zero after a successful shutdown event occurs, check for non-microservice request calls that may consume traffic, such as local calls.

Enable the proactive notification capability

Definition

The proactive notification capability is an advanced capability provided by graceful shutdown. By default, the proactive notification capability is disabled. You can use the graceful shutdown capability provided by MSE to resolve issues in most scenarios. However, if an application to be shut down uses the Spring Cloud framework, a consumer call error may occur. In this case, you can enable the proactive notification capability. After the proactive notification capability is enabled, the provider proactively notifies the consumer during the shutdown phase. After the notification is received, the consumer no longer forwards requests to the provider.

Prerequisites

Usage notes

Microservices Governance does not support graceful shutdown of the following applications:

  • Non-Java applications.

  • Non-WebFlux applications or non-Spring MVC applications.

  • Downstream provider applications whose consumer applications are not microservice applications.

  • Consumer applications and provider applications for which Microservices Governance is disabled.

Note

The graceful shutdown feature requires a specific amount of time to execute all in-transit requests before the application is shut down. You must set the terminationGracePeriodSeconds parameter to a value greater than 30 in the ACK console. We recommend that you set this parameter to 90. The default value of this parameter is 30. If you use the default value 30, the shutdown hook of the application may fail to be executed. As a result, specific resources cannot be released when the application is shut down.

Enable proactive notification for graceful shutdown

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Governance > Application Governance. On the page that appears, click the resource card of the application that you want to manage.

  3. On the application details page, click Traffic management in the left-side navigation pane, and click the Lossless up and down line tab.

  4. In the Graceful Shutdown section, turn on proactive notification.

References