Online applications undergo routine operations such as release, scale-out, scale-in, and restart. Microservices Engine (MSE) provides the graceful start and shutdown features to protect applications when you perform the preceding operations. The graceful start features include service prefetching and delayed registration. This topic describes how to configure graceful start.
Prerequisites
Microservices Governance is activated. For more information, see Activate Microservices Governance.
Microservices Governance is enabled for microservices applications in a Container Service for Kubernetes (ACK) cluster. For more information, see Enable Microservices Governance for microservice applications in an ACK cluster.
Usage notes
You can enable the service prefetching feature for Spring Cloud applications that use the Nacos or ZooKeeper registry.
The service prefetching feature is implemented for Spring Cloud applications based on the default load balancer class ZoneAwareLoadBalancer of the Spring Cloud framework. If you change this class for your Spring Cloud application, the service prefetching feature becomes ineffective.
The low-traffic prefetching feature is implemented for Dubbo applications by using mse-loadbalance as the load balancer. If you have configured a load balancer for a Dubbo application, you must disable the load balancer. Otherwise, the low-traffic prefetching feature provided by MSE is ineffective for the Dubbo application.
In most cases, gateways are not called by using registries but called by using APIs. Therefore, the low-traffic prefetching feature provided by MSE is ineffective for gateways.
Configure low-traffic prefetching
If a cold-started application receives a large number of requests immediately after the application starts, issues such as request blocking and errors may occur due to incomplete initialization of internal resources. To address these issues, you can use the service prefetching feature to send a small number of requests to the application after it starts to help ensure that the internal resources are completely initialized.
Log on to the MSE console, and select a region in the top navigation bar.
In the left-side navigation pane, choose . On the page that appears, click the resource card of the application that you want to manage.
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 Graceful Start section on the Graceful Start/Shutdown tab, click the icon next to the Preheating duration (seconds) field. In the lossless online dialog box, configure the Preheating duration (seconds) parameter. Then, click OK.
Prefetching duration: Set the amount of time required for prefetching at the next startup of application instances. Default value: 120. Unit: seconds. Valid values: 0 to 86400. The value 86400 equals 24 hours.
NoteWe recommend that you use the default value of this parameter when you use the service prefetching feature for your application for the first time. If traffic loss occurs when you use the default value of this parameter for service prefetching, you can adjust the value of this parameter to optimize the prefetching performance.
Turn on the switch in the upper-right corner of the Graceful Start section. In the Prompt message dialog box, click OK.
The Graceful Start switch must be turned on for both the service consumer and the service provider for the low-traffic prefetching feature to take effect.
Configure delayed registration
If the initialization process of an application is complex, the application may be registered and initialized at the same time. The application may have been registered with a registry before the application is completely initialized. In this case, if the application is called by a consumer, an error may be returned. The delayed registration feature helps ensure that an application registers with a registry only after the application is completely initialized.
Log on to the MSE console, and select a region in the top navigation bar.
In the left-side navigation pane, choose . On the page that appears, click the resource card of the application that you want to manage.
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 Graceful Start section on the Graceful Start/Shutdown tab, set the Delayed registration time (seconds) parameter to a value that ranges from 0 to 3600. The value 3600 equals an hour. Then, click the icon.
Turn on the switch in the upper-right corner of the Graceful Start section. In the Prompt message dialog box, click OK.
The delayed registration feature takes effect after the application restarts.