高可用集群和负载均衡集群_集群中的负载平衡和粘性会话

高可用集群和负载均衡集群

As a small recap, what is clustering?

概括地说,什么是集群?

Clustering is having one endpoint shared among an identical group of service nodes to achieve high availability and scalability.

群集使一个端点在同一组服务节点之间共享,以实现高可用性和可伸缩性。

The cluster would have a set of service nodes(or servers) acts as a one service node endpoint that can complete client tasks by balancing the load. Now the question we get is how to balance the load? and which server or service node is responsible to execute the next client request that is coming to the shared endpoint?The answer is, that is the responsibility of the “Load Balancer” or in other words, there is one specific application is there to decide which request is going to get handled by which server or service node in the cluster.

集群将有一组服务节点(或服务器)充当一个服务节点终结点,可以通过平衡负载来完成客户端任务。 现在我们得到的问题是如何平衡负载? 答案是“负载均衡器”的责任,或者换句话说,有一个特定的应用程序来决定共享负载端点的下一个客户端请求。集群中的哪个服务器或服务节点将处理哪个请求。

What is Load Balancing?

什么是负载平衡?

A load balancer is the software or hardware application that acts as the traffic light or the traffic cop for the incoming traffic to the servers. It decides which request should go to which server according to a predefined algorithm that checks each server status. There are many algorithms available for different load balancers to make decisions on the incoming traffic routing. The goal is to make sure that none of the servers would get overloaded with traffic and if one goes down then reroute the incoming requests to another one.

负载均衡器是一种软件或硬件应用程序,充当到服务器的传入流量的交通信号灯或交通警察。 它根据检查每个服务器状态的预定义算法来决定将哪个请求发送到哪个服务器。 有许多算法可用于不同的负载均衡器,以对传入的流量路由做出决策。 目的是确保所有服务器都不会过载,如果其中一台服务器出现故障,则将传入的请求重新路由到另一台服务器。

As a summary, a load balancer provides below functionalities.

综上所述,负载均衡器提供以下功能。

  1. Make sure servers won't get overloaded and route requests efficiently

    确保服务器不会超载并有效地路由请求
  2. Provide high availability of the services by routing the requests to online servers by avoiding downtime

    通过将请求路由到在线服务器来避免停机,从而提供高可用性的服务
  3. Handle the scalability of servers by adding or removing servers based on the load servers get.

    通过基于负载获取的服务器添加或删除服务器来处理服务器的可伸缩性。

There are different load balancing algorithms available, and those algorithms would be a deciding factor to choose the correct load balancer depending on your needs.

有不同的负载平衡算法可用,这些算法将是根据您的需求选择正确的负载平衡器的决定因素。

Some algorithms available are

一些可用的算法是

  1. Round Robin — Requests are distributed across the group of servers sequentially.

    循环访问—请求按顺序分布在服务器组中。
  2. Least Connections — A new request is sent to the server with the fewest current connections to clients. The relative computing capacity of each server is factored into determining which one has the least connections.

    最少的连接—新请求以与客户端的当前连接最少的方式发送到服务器。 每个服务器的相对计算能力都在确定哪个服务器连接最少的因素中。
  3. Least Time — Sends requests to the server selected by a formula that combines the fastest response time and fewest active connections.

    最短时间-将请求发送到由组合了最快响应时间和最少活动连接的公式选择的服务器。
  4. Hash — Distributes requests based on a key you define, such as the client IP address or the request URL.

    哈希-根据您定义的键(例如客户端IP地址或请求URL)分配请求。
  5. IP Hash — The IP address of the client is used to determine which server receives the request.

    IP哈希-客户端的IP地址用于确定哪个服务器接收请求。
  6. Random with Two Choices — Picks two servers at random and sends the request to the one that is selected by then applying the Least Connections algorithm.

    随机选择两个选项-随机选择两个服务器,然后将请求发送到选定的服务器,然后再应用最小连接算法。

What are the benefits of Load balancing?

负载平衡的好处是什么?

Scalability — When there is a load balancer it can decide when to add or remove servers or service nodes from the cluster.

可伸缩性—如果有负载均衡器,它可以决定何时在集群中添加或删除服务器或服务节点。

Availability — Achieve this by reducing the downtime of the servers and re-routing the requests to the online servers.

可用性—通过减少服务器的停机时间并将请求重新路由到在线服务器来实现。

High efficiency — By making it possible to execute a set of tasks parallel.

高效—通过使并行执行一组任务成为可能。

There are some other advantages as well when it comes to Load balancing but above are the major advantages.

在负载均衡方面,还有其他一些优点,但是以上是主要优点。

Image for post
Clustering using Load balancing
使用负载平衡进行集群

What are Sticky sessions in Load balancing?

负载均衡中的粘性会话是什么?

Sometime when executing tasks we need to persist the state of the current user session. As an example think of a shopping cart application, where we need to manage the state of the user session throughout all the requests that the user is sending to that application.

有时在执行任务时,我们需要保持当前用户会话的状态。 例如,以一个购物车应用程序为例,在该应用程序中,我们需要在用户向该应用程序发送的所有请求中管理用户会话的状态。

What happens if a Load balancer routes one request to one server/service node in a cluster and sends the other request to another server/service node in the same cluster? Some of the user information will be lost or there has to be a mechanism to share that information. These scenarios can cause transaction failures or data losses.

如果负载均衡器将一个请求路由到群集中的一个服务器/服务节点,然后将另一个请求发送到同一群集中的另一个服务器/服务节点,会发生什么情况? 一些用户信息将丢失,或者必须有一种共享该信息的机制。 这些情况可能导致事务失败或数据丢失。

In that case, we need to tell the Load balancer to send all the following requests coming from a particular user session to one server to process. To inform that to the load balancer we use a technique called sticky sessions or in other words session persistence.

在这种情况下,我们需要告诉负载均衡器将来自特定用户会话的以下所有请求发送到一台服务器进行处理。 为了告知负载均衡器,我们使用了一种称为粘性会话或换句话说会话持久性的技术。

Image for post
Image for post

Why a Load balancer should be able to add or remove servers on demand?

为什么负载均衡器应该能够按需添加或删除服务器?

This is important when it comes to the payment model because most of the time and most of the payment schemes are based on the amount of load that is being handled, it can be a number of requests or it can be a number of servers which cater to the load. In that case, the load balancer should be able to add or remove servers based on the demand that it gets. Which enables the user to pay for the computing capacity it actually uses.

对于支付模型而言,这一点很重要,因为在大多数情况下,大多数支付方案都是基于要处理的负载量,它可以是许多请求,也可以是许多可以满足需求的服务器负载。 在这种情况下,负载均衡器应该能够根据其需求添加或删除服务器。 这使用户能够为其实际使用的计算能力付费。

Hardware vs Software Load balancing

硬件与软件负载平衡

The two ways of load balancing are Hardware and Software, it depends on the nature of the business you are having and the nature of the application that you are using to cater to those business needs. Usually, hardware-based load balancers use their own proprietary applications and processors with servers to facilitate Load balancing which requires more infrastructure and which can be costly. Compared to that, Software Load balancing is easier and less expensive.

负载平衡的两种方式是硬件和软件,它取决于您所拥有的业务的性质以及用于满足这些业务需求的应用程序的性质。 通常,基于硬件的负载均衡器将自己专有的应用程序和处理器与服务器配合使用,以促进负载均衡,这需要更多的基础架构并且成本很高。 相比之下,软件负载平衡更容易且更便宜。

翻译自: https://medium.com/@lakshitha.uom/load-balancing-and-sticky-sessions-in-clustering-c6f8d546a29c

高可用集群和负载均衡集群

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值