️ Pic by Alibaba Tech on Facebook

Cluster flow limiting can limit the total QPS that a resource invokes in a cluster, and solve the problem of poor overall flow control effect caused by uneven single-node flow, which is a sharp tool to ensure service stability.

Sentinel provides cluster flow control since version 1.4.0, but using Sentinel cluster flow limiting requires configuration of a number of dynamic data sources and some modifications to the open source console, which has a certain usage cost. To better understand and quickly use cluster flow control, we have provided an example of Sentinel cluster flow limiting console in the cloud version. Just a few simple steps to quickly access the AHAS Sentinel cluster stream limiting console without manually configuring dynamic data sources.

Note: This console example is located in the cloud environment, you need to use ali Cloud account to log in.

1. Introduce dependencies

We just need to introduce the following dependencies in Maven:

< the dependency > < groupId > com. Alibaba. CSP < / groupId > < artifactId > ahas sentinel - client < / artifactId > < version > 1.1.0 < / version > </dependency>Copy the code

Ahas-sentinel-client will contain necessary dependencies such as Sentinel-Core and cluster flow limiting (based on Sentinel 1.4.1 version), as well as modules (authentication, communication, etc.) required to connect to aHAS Sentinel console of Ali Cloud. At the same time, ahS-Sentinel-Client implements push mode data source and automatically registers all rule configuration and cluster configuration data source, which can take effect in real time when pushed on the console:

If you were previously connected to the open source Sentinel console, you need to replace the associated communication dependencies (such as Sentinel-transport-simple-HTTP or Sentinel-transport-netty-http) with this dependency. Otherwise the AHAS Sentinel console will not connect properly. If you want to switch from the AHAS Sentinel console to the open source Sentinel console, simply replace the dependencies back and modify the startup parameters.

Note: AHAS-Sentinel-client 1.1.x is only compatible with Sentinel 1.4.1 and later versions.

2. Enable AHAS and obtain startup parameters

After introducing dependencies, we need to open AHAS function (free) on ali Cloud console. You can follow the instructions in the AHAS documentation and Sentinel Flow Control Downgrading Demo Quick Start. Notice If the application runs in a non-Aliyun ECS environment or local environment, select switch to the public network environment in the upper left corner.

Once enabled, we can click on the flow Control Downgrade in the left sidebar to enter the Sentinel Console application overview page. In the upper right corner of the page, click Application Access, select the Java SDK access TAB, go to the Config Startup Parameters TAB to get the required JVM startup parameters (for details, refer to SDK access documentation), similar to:

-Dproject.name=AppName -Dahas.license=<License>Copy the code

In the command, project.name indicates the application name (displayed on the console), and ahas.license indicates the authorization license.

Note: If the application is running in a non-Aliyun ECS environment or local, you need to switch to the public network environment in the upper left corner.

For detailed access procedures, refer to the AHAS Sentinel console documentation.

3. Start the application instance

Then we can start the application locally, with the startup parameters we received. Experience in local cluster current limiting function, need to be in the machine start multiple application examples, and extra – Dcsp. Sentinel. Log. Use the pid = true parameter (used to distinguish the same application multiple instances). After startup, we can see the connected machine in the machine list page of the corresponding application:

4. Assign the Token Server

Cluster traffic limiting has two identities:

  • A Token Client is a cluster flow control Client that communicates with the owning Token Server to request a Token. The cluster traffic limiting server returns the result to the client to determine whether to limit traffic. The Sentinel cluster flow control communication layer is implemented by Netty.
  • The Token Server is the flow control Server of the cluster. It processes the requests from the Token Client and determines whether to issue the Token according to the configured cluster rules.

In this example, the Token Server mode is embedded, that is, as a built-in Token Server, the application is started in the same process without independent deployment:

We need a specific URL to access the AHAS cluster flow control Demo page (where the parameter after appName is replaced by our application name) :

Ahas.console.aliyun.com/#/SystemGua…

Then we enter the cluster flow control Token Server list page:

We can click the New Token Server button in the upper right corner to add the Token Server and perform the allocation. First, select a Token Server in the New Token Server dialog box, and configure the port of the Token Server and the maximum QPS quota (to limit resource usage and prevent the application from being affected in embedded mode). Next we assign the Token Client to the Token Server in the following selection box. In the example in the figure above, there are two instances of our application, one of which is specified as Token Server and the other as Token Client. Click the “Save” button to save the allocation.

After the Token Server is saved successfully, we can see the Token Server in the Token Server list page:

Click the drop-down button on the left to view real-time information about the Token Server and managed Token clients:

5. Configure the rule and view the result

Next we go to the flow rules page to configure flow rules for our application. Configure a common flow control rule for a resource and set the single-node QPS threshold to 10.

Then the corresponding resources of the two machines are continuously requested, and the total QPS is 20 (QPS of each single machine is 10) as can be seen from the monitoring page:

Next, we edit the newly created rule and enable the cluster mode. The threshold mode is set to “Total Threshold”, indicating that the total number of calls in the cluster for this resource is 10. Save rule:

After waiting for some time, we can see on the monitoring page that the total QPS of the resource is limited to 10:

For more features and uses of Sentinel cluster flow control, refer to the Sentinel cluster flow control documentation and the previous cluster flow control article. We also provide a Demo for configuring cluster flow control configuration sources in embedded mode, for reference: Sentinel-Demo-cluster-Embedded.

The author:

Chu He, nicknamed Sczyh30 in the community, is a development engineer of Alibaba’s high availability architecture group. Currently, he is mainly responsible for the development and community maintenance of Sentinel open source project.

More information about Sentinel:

  • Sentinel releases another milestone release after entering GA
  • Analysis of resource call chain principle of Sentinel
  • Technology selection: Sentinel vs Hystrix
  • Alibaba’s lightweight flow control component Sentinel is included in the CNCF cloud native panorama atlas

Yq.aliyun.com/articles/69…