[Sentinel] The meaning of Token Server and Token Client in sentinel cluster flow control (7)

前言

Official website
https://github.com/alibaba/Sentinel/wiki/Cluster flow control
First, through 流控规则, we can already implement cluster flow control. Then the flow control cluster at the bottom of the console Token Serverand Token Clientis doing it?

Official introduction
Why use cluster flow control? Suppose we want to limit the total QPS of calling a certain API to 50 for a certain user, but the number of machines may be many (for example, there are 100). At this time, we naturally thought of finding a server to specifically count the total call volume, and other instances communicate with this server to determine whether it can be called. This is the most basic way of cluster flow control.

In addition, cluster flow control can also solve the problem of poor overall flow limiting effect caused by uneven flow. Assuming there are 10 machines in the cluster, we set the single-machine current limit threshold for each machine to 10 QPS, and ideally, the current limit threshold for the entire cluster is 100 QPS. However, in actual conditions, the flow to each machine may be uneven, which will cause some machines to start limiting the flow when the total amount is not reached. Therefore, if you only rely on the single-machine dimension to limit, it will not be able to accurately limit the overall traffic. The cluster flow control can accurately control the total number of calls of the entire cluster, and combined with the single-machine flow limiter, it can better exert the effect of flow control.

There are two kinds of identities in cluster flow control

  • Token Client: Cluster flow control client, used to request token from the Token Server to which it belongs. The cluster current limiting server will return the result to the client to decide whether to limit the current.
  • Token Server: the cluster flow control server, which processes requests from Token Client, and determines whether tokens should be issued (whether it is allowed to pass) according to the configured cluster rules.

The official demo
sentinel-demo-cluster provides examples of embedded mode and independent mode:

Achieve token-serverandtoken-client

Vernacular: For
example, there is one dubbo consumer and three dubbo servers. At this time, cluster flow control is required to implement token-server and token-client.

  • 首先,我们要把三个dubbo服务端都注册到sentinel控制台。
    Requirement: the same value of -Dproject.name can be registered in a block; or if it is not added, the name of the startup class must be the same.Here is a special note. If the project is springcloud and the -Dproject.name configuration is not added, it seems to be the service name by default. If not, you can view the configuration through the SentinelConfigLoader in sentinel-core in the source code and modify it step by step
  • 然后,添加token-server

Insert picture description here

剩余问题

  1. Cluster current limit-changes in the qps overview value in the Token Server list
  2. When the cluster current is limited, if the current service has been limited, it can automatically failover to other machines
  3. Token Server automatic management (allocation/election of Token Server)

最后

Stop writing, from getting started to giving up. Free (sentinel) and paid (ahas) are not the same. Too many problems.

备注

Tutorial 1: https://blog.csdn.net/qq_26323323/article/details/103935230

Guess you like

Origin blog.csdn.net/s1441101265/article/details/107639852