将一些零散的知识点进行整理, 以便加深理解,方便查阅,也希望能帮到大家。
使用系统随机功能根据后端服务器列表的大小随机选择一个服务器。根据概率统计理论,随着呼叫量的增加,实际效果更接近每个后端服务器的平均流量分布,即轮询效果。
[En]
Use the system random function to randomly select one of the servers according to the size of the backend server list. According to the probability statistics theory, with the increase of the call amount, the actual effect is closer to the average distribution of traffic to each back-end server, that is, the polling effect.
先将后端服务器列表(如:按照地址IP)计算出哈希值,然后映射到HASH环上(如果服务器实例节点较少可以增加虚拟节点),当接收请求时,根据请求的信息(如请求的客户端IP、用户ID等)计算出哈希值,最后将请求信息的哈希值映射到HASH环上,按顺时针方向,确定落在哪个区间中,则选择区间的下一个服务器节点作为处理此次请求的服务器。
因为后端服务器的配置不同,所以请求的处理可能很快也可能很慢。根据后端服务器的当前连接情况,动态选择当前积压连接最少的服务器来处理当前请求,以尽可能提高后端服务器的利用效率,并将负载合理分配给每台机器。
[En]
Because the configuration of back-end servers is different, the processing of requests can be fast or slow. According to the current connection situation of back-end servers, dynamically select the server with the least number of current backlogged connections to process the current request, so as to improve the utilization efficiency of back-end servers as much as possible, and distribute the load to each machine reasonably.
计数器算法使用计数器来累积一个周期中的访问时间,并在达到设置的电流限制值时触发电流限制策略。在下一个循环开始时,清除并再次计数。
[En]
The counter algorithm uses the counter to accumulate the access times in a cycle, and triggers the current limiting strategy when the set current limiting value is reached. At the beginning of the next cycle, clear and count again.
滑动窗口算法是将时间周期分为N个小周期,分别记录每个小周期内访问次数,并且根据时间滑动删除过期的小周期。
令牌桶算法是程序以r(r=时间周期/限流值)的速度向令牌桶中增加令牌,直到令牌桶满,请求到达时向令牌桶请求令牌,如获取到令牌则通过请求,否则触发限流策略。
可参见网上文章:
先进先出,删除第一个缓存数据,最迟删除新添加的缓存数据,这与队列完全一致。
[En]
First in first out, the first cached data is eliminated, and the newly added cached data is eliminated at the latest, which is completely consistent with the queue.
最近使用次数最少的缓存数据消除了在特定时间段内访问次数最少的高速缓存数据。次数用作参考。
[En]
The least recently used cache data eliminates the cache data that has been accessed the least in a certain period of time. The number of times is used as a reference.