CN114928615A - Load balancing method, device, equipment and readable storage medium - Google Patents
Load balancing method, device, equipment and readable storage medium Download PDFInfo
- Publication number
- CN114928615A CN114928615A CN202210555137.8A CN202210555137A CN114928615A CN 114928615 A CN114928615 A CN 114928615A CN 202210555137 A CN202210555137 A CN 202210555137A CN 114928615 A CN114928615 A CN 114928615A
- Authority
- CN
- China
- Prior art keywords
- load balancing
- host
- load
- balancing system
- load balancer
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/1001—Protocols in which an application is distributed across nodes in the network for accessing one among a plurality of replicated servers
- H04L67/1031—Controlling of the operation of servers by a load balancer, e.g. adding or removing servers that serve requests
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
本申请公开了一种负载均衡方法、装置、设备及可读存储介质,负载均衡系统中新增主机时,负载均衡器接收到数据包,倘若映射表中不存在该数据包的五元组,则从负载均衡系统包含的各主机的RS中确定出用于负载均衡的生效RS,从生效RS中选择出目标RS并将数据包发送给目标RS,从而完成第二次负载均衡。采用该种方案,每次新增主机后,负载均衡器从已生效的RS中确定出目标RS并发送数据包,确保新增主机上的负载均衡器的有充足的时间针对已有业务生成映射表,映射表中记录已有业务的五元组和RS的映射关系,避免负载均衡器将已有业务的数据包发送给不正确的RS,实现提高业务质量的目的。
The present application discloses a load balancing method, device, device and readable storage medium. When a new host is added to the load balancing system, the load balancer receives a data packet. If the quintuple of the data packet does not exist in the mapping table, Then, the effective RS for load balancing is determined from the RSs of each host included in the load balancing system, and the target RS is selected from the effective RS and the data packet is sent to the target RS, thereby completing the second load balancing. With this solution, after each new host is added, the load balancer determines the target RS from the valid RSs and sends data packets, ensuring that the load balancer on the newly added host has sufficient time to generate mappings for existing services The mapping table records the mapping relationship between the quintuple of the existing service and the RS, so as to prevent the load balancer from sending the data packet of the existing service to the incorrect RS, and achieve the purpose of improving the service quality.
Description
技术领域technical field
本申请涉及负载均衡技术领域,特别涉及一种负载均衡方法、装置、设备及可读存储介质。The present application relates to the technical field of load balancing, and in particular, to a load balancing method, apparatus, device, and readable storage medium.
背景技术Background technique
随着云技术的发展,服务器面对的访问数量快速增加,服务器需要具备处理大规模并发服务访问的能力。对于大负载的服务器而言,CPU、I/O处理能力很快成为瓶颈,而单台服务器的性能总是有限的,简单的提高硬件性能并不能真正解决问题。因此,必须采用多服务器和负载均衡(Load Balance,LB)技术才能满足大规模并发服务访问的需要。With the development of cloud technology, the number of accesses faced by servers increases rapidly, and servers need to have the ability to handle large-scale concurrent service accesses. For heavily loaded servers, CPU and I/O processing capabilities quickly become bottlenecks, and the performance of a single server is always limited. Simply improving hardware performance cannot really solve the problem. Therefore, multi-server and load balancing (Load Balance, LB) technology must be adopted to meet the needs of large-scale concurrent service access.
负载均衡是指:利用负载均衡器将大量的并发访问或数据流量分担到多台真实服务器上,由真实服务器进行处理,减少用户等待响应的时间。在云平台中,负载均衡器通常采用Linux虚拟服务器(Linux Virtual Server,LVS)架构,由前端的负载均衡器(LoadBalancer,LB)和后台真实服务器(Real Server,RS)群组成。LB接收到来自客户端的业务请求后,根据预设的调度转发策略及负载均衡调度算法将业务请求调度转发给RS,RS处理业务请求并返回应答结果。然而,LVS负载均衡技术存在性能开销大、LB容易受负载突增的影响的弊端。Load balancing refers to: using a load balancer to share a large amount of concurrent access or data traffic to multiple real servers, which are processed by the real servers, reducing the time for users to wait for a response. In a cloud platform, a load balancer usually adopts a Linux virtual server (Linux Virtual Server, LVS) architecture, which consists of a front-end load balancer (LoadBalancer, LB) and a background real server (Real Server, RS) group. After receiving the service request from the client, the LB schedules and forwards the service request to the RS according to the preset scheduling forwarding policy and load balancing scheduling algorithm, and the RS processes the service request and returns a response result. However, LVS load balancing technology has the disadvantages of high performance overhead and LB is easily affected by sudden load increase.
为克服LVS负载均衡技术的问题,业界引入快速数据路径(eXpress Data Path,XDP)的负载均衡架构。然而,基于XDP架构,当在集群中新增主机时,集群内正在进行的业务的连接会异常断开,且该异常与新增主机的数量成正比,导致正在进行的业务异常。To overcome the problem of the LVS load balancing technology, the industry introduces a load balancing architecture of eXpress Data Path (XDP). However, based on the XDP architecture, when a new host is added to the cluster, the connection of the ongoing business in the cluster will be abnormally disconnected, and the abnormality is proportional to the number of newly added hosts, resulting in abnormal ongoing business.
发明内容SUMMARY OF THE INVENTION
本申请提供一种负载均衡方法、装置、设备及可读存储介质,通过对负载均衡器进行改进,以解决基于XDP的架构新增主机时对已有业务的影响,实现提高业务可靠性的目的。The present application provides a load balancing method, device, device and readable storage medium. By improving the load balancer, the impact on existing services when a new host is added based on the XDP architecture can be solved, and the purpose of improving service reliability can be achieved. .
第一方面,本申请实施例提供一种负载均衡方法,应用于负载均衡系统中的主机上的负载均衡器,所述方法包括:In a first aspect, an embodiment of the present application provides a load balancing method, which is applied to a load balancer on a host in a load balancing system, and the method includes:
确定负载均衡系统中存在新增主机,所述负载均衡器是所述负载均衡系统包含的多个主机中的任意一个主机上的负载均衡器,所述多个主机中的每个主机上均部署负载均衡器和真实服务器RS;Determine that there is a new host in the load balancing system, the load balancer is a load balancer on any one of the multiple hosts included in the load balancing system, and each host in the multiple hosts is deployed on Load Balancer and Real Server RS;
接收数据包;receive packets;
从所述负载均衡系统包含的各主机的RS中确定出生效RS,所述生效RS是新增主机之前所述负载均衡器对已有业务的数据包进行负载均衡时涉及的RS,所述已有业务是新增主机之前所述负载均衡系统正在提供给用户的业务;The effective RS is determined from the RSs of each host included in the load balancing system, and the effective RS is the RS involved when the load balancer performs load balancing on the data packets of the existing services before the new host is added. There is a business that the load balancing system is providing to the user before the new host is added;
从所述生效RS中确定出目标RS;Determine the target RS from the valid RS;
向所述目标RS发送所述数据包。The data packet is sent to the target RS.
第二方面,本申请实施例提供一种负载均衡方法,应用于负载均衡系统中的查询设备,所述方法包括:In a second aspect, an embodiment of the present application provides a load balancing method, which is applied to a query device in a load balancing system, and the method includes:
接收所述负载均衡系统中新增主机上的RS发送的通告请求,所述通告请求用于指示所述RS的虚拟IP地址VIP;receiving a notification request sent by an RS on a newly added host in the load balancing system, where the notification request is used to indicate the virtual IP address VIP of the RS;
记录所述VIP以及通告时间点,所述通告时间点是所述查询设备接收到所述通告请求的时间点,所述VIP和所述通告时间点用于确定所述新增主机上的RS是否转变为生效RS,所述负载均衡系统中的生效RS是所述负载均衡系统中的负载均衡器对已有业务的数据包进行负载均衡时涉及的RS,所述已有业务是新增主机之前所述负载均衡系统正在提供给用户的业务。Record the VIP and the notification time point, the notification time point is the time point when the query device receives the notification request, and the VIP and the notification time point are used to determine whether the RS on the newly added host is It is transformed into an effective RS, and the effective RS in the load balancing system is the RS involved when the load balancer in the load balancing system performs load balancing on the data packets of the existing service, and the existing service is before the new host is added. The service that the load balancing system is providing to the user.
第三方面,本申请实施例提供一种负载均衡装置,集成在负载均衡系统中的主机上的负载均衡器,所述装置包括:In a third aspect, an embodiment of the present application provides a load balancing device, a load balancer integrated on a host in a load balancing system, the device comprising:
确定模块,用于确定负载均衡系统中存在新增主机,所述负载均衡器是所述负载均衡系统包含的多个主机中的任意一个主机上的负载均衡器,所述多个主机中的每个主机上均部署负载均衡器和真实服务器RS;The determining module is configured to determine that a new host exists in the load balancing system, the load balancer is a load balancer on any one of the multiple hosts included in the load balancing system, and each of the multiple hosts A load balancer and a real server RS are deployed on each host;
接收模块,用于接收数据包;A receiving module for receiving data packets;
处理模块,用于从所述负载均衡系统包含的各主机的RS中确定出生效RS,所述生效RS是新增主机之前所述负载均衡器对已有业务的数据包进行负载均衡时涉及的RS,所述已有业务是新增主机之前所述负载均衡系统正在提供给用户的业务,从所述生效RS中确定出目标RS;A processing module, configured to determine an effective RS from the RSs of each host included in the load balancing system, where the effective RS is involved when the load balancer performs load balancing on the data packets of existing services before the new host is added RS, the existing service is the service that the load balancing system is providing to the user before the new host is added, and the target RS is determined from the valid RS;
发送模块,用于向所述目标RS发送所述数据包。A sending module, configured to send the data packet to the target RS.
第四方面,本申请实施例提供一种负载均衡装置,集成在负载均衡系统中的查询设备上,所述装置包括:In a fourth aspect, an embodiment of the present application provides a load balancing device integrated on a query device in a load balancing system, the device comprising:
收发模块,用于接收所述负载均衡系统中新增主机上的RS发送的通告请求,所述通告请求用于指示所述RS的虚拟IP地址VIP;a transceiver module, configured to receive a notification request sent by an RS on a newly added host in the load balancing system, where the notification request is used to indicate the virtual IP address VIP of the RS;
处理模块,用于记录所述VIP以及通告时间点,所述通告时间点是所述查询设备接收到所述通告请求的时间点,所述负载均衡系统中的生效RS是所述新增主机之前,所述负载均衡系统中的负载均衡器对已有业务的数据包进行负载均衡时涉及的RS,所述已有业务是新增主机之前所述负载均衡系统正在提供给用户的业务。A processing module, configured to record the VIP and the notification time point, the notification time point is the time point when the query device receives the notification request, and the effective RS in the load balancing system is before the newly added host , the RS involved when the load balancer in the load balancing system performs load balancing on the data packets of the existing service, and the existing service is the service that the load balancing system is providing to the user before the new host is added.
第五方面,本申请实施例提供一种电子设备,包括:处理器、存储器及存储在所述存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时使得所述电子设备实现如上第一方面或第一方面各种可能的实现方式所述的方法。In a fifth aspect, an embodiment of the present application provides an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor, where the processor executes the computer program so that all The electronic device implements the method described in the first aspect or various possible implementation manners of the first aspect.
第六方面,本申请实施例提供一种电子设备,包括:处理器、存储器及存储在所述存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时使得所述电子设备实现如上第二方面或第二方面各种可能的实现方式所述的方法。In a sixth aspect, an embodiment of the present application provides an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor, where the processor executes the computer program so that all The electronic device implements the method described in the second aspect or various possible implementation manners of the second aspect.
第七方面,本申请实施例提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机指令,所述计算机指令在被处理器执行时用于实现如上第一方面或第一方面各种可能的实现方式所述的方法。In a seventh aspect, embodiments of the present application provide a computer-readable storage medium, where computer instructions are stored in the computer-readable storage medium, and when executed by a processor, the computer instructions are used to implement the first aspect or the first aspect above. The method described in various possible implementations of the aspect.
第八方面,本申请实施例提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机指令,所述计算机指令在被处理器执行时用于实现如上第二方面或第二方面各种可能的实现方式所述的方法。In an eighth aspect, embodiments of the present application provide a computer-readable storage medium, where computer instructions are stored in the computer-readable storage medium, and when executed by a processor, the computer instructions are used to implement the second aspect or the second aspect above. The method described in various possible implementations of the aspect.
第九方面,本申请实施例提供一种负载均衡系统,包括交换机、多个主机和查询设备,所述交换机与所述多个主机中的各主机建立网络连接,所述查询设备与所述多个主机中的各主机建立网络连接,其中:In a ninth aspect, an embodiment of the present application provides a load balancing system, including a switch, multiple hosts, and a query device, the switch establishes a network connection with each of the multiple hosts, and the query device is connected to the multiple hosts. Each of the hosts establishes a network connection, where:
所述交换机,用于执行负载均衡以从所述多个主机包含的负载均衡器中确定出目标负载均衡器并发送数据包;the switch, configured to perform load balancing to determine a target load balancer from the load balancers included in the plurality of hosts and send data packets;
所述多个主机中的每个主机上均部署负载均衡器和真实服务器RS,所述负载均衡器用于执行如上第一方面或第一方面的各种可能的实现方式所述的负载均衡方法。A load balancer and a real server RS are deployed on each of the multiple hosts, and the load balancer is configured to execute the load balancing method described in the first aspect or various possible implementation manners of the first aspect.
所述查询设备用于执行如上第二方面或第二方面的各种可能的实现方式所述的负载均衡方法。The query device is configured to execute the load balancing method described in the second aspect or various possible implementation manners of the second aspect.
本申请实施例提供的负载均衡方法,负载均衡系统中的各主机上的负载均衡器检测出负载均衡系统中新增主机时,一旦一个负载均衡器接收到数据包,倘若映射表中不存在该数据包的五元组,则从负载均衡系统包含的各主机的RS中确定出用于负载均衡的生效RS,从生效RS中选择出目标RS并将数据包发送给目标RS,从而完成第二次负载均衡。采用该种方案,每次新增主机后,负载均衡器从已生效的RS中确定出目标RS并发送数据包,确保新增主机上的负载均衡器的有充足的时间针对已有业务生成映射表,映射表中记录已有业务的五元组和RS的映射关系,避免负载均衡器将已有业务的数据包发送给不正确的RS。也就是说,每次新增主机后,该主机上的负载均衡器生效但是RS并不立即参与负载均衡,而是待新增主机上的负载均衡器的映射表中保存所有已有业务的五元组和RS的映射关系后,才将新增主机上的RS用于负载均衡,确保新增主机后已有业务的数据包发送给正确的RS,实现提高业务质量的目的的同时,无需改动交换机,减少影响面和操作复杂度。In the load balancing method provided by the embodiment of the present application, when the load balancer on each host in the load balancing system detects a new host in the load balancing system, once a load balancer receives a data packet, if the load balancer does not exist in the mapping table The five-tuple of the data packet, the effective RS for load balancing is determined from the RSs of each host included in the load balancing system, the target RS is selected from the effective RS, and the data packet is sent to the target RS, thereby completing the second Secondary load balancing. With this solution, after each new host is added, the load balancer determines the target RS from the valid RSs and sends data packets, ensuring that the load balancer on the newly added host has sufficient time to generate mappings for existing services The mapping table records the mapping relationship between the quintuple of the existing service and the RS, so as to prevent the load balancer from sending the data packet of the existing service to the incorrect RS. That is to say, each time a host is added, the load balancer on the host takes effect, but the RS does not immediately participate in load balancing. Instead, the mapping table of the load balancer on the host to be added saves all existing services in the mapping table. After the mapping relationship between the tuple and the RS, the RS on the newly added host is used for load balancing to ensure that the data packets of the existing services after the newly added host are sent to the correct RS, and the purpose of improving the service quality is achieved without any modification. switches, reducing the impact surface and operational complexity.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the drawings that are used in the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative effort.
图1是本申请实施例提供的负载均衡方法所适用的负载均衡系统的架构示意图;FIG. 1 is a schematic diagram of the architecture of a load balancing system to which the load balancing method provided by an embodiment of the present application is applicable;
图2是本申请实施例提供的基于XDP的负载均衡架构在主机上的工作层级示意图;2 is a schematic diagram of a working level of an XDP-based load balancing architecture provided by an embodiment of the present application on a host;
图3是本申请实施例提供的负载均衡方法的流程图;FIG. 3 is a flowchart of a load balancing method provided by an embodiment of the present application;
图4是本申请实施例提供的负载均衡方法的另一个流程图;FIG. 4 is another flowchart of the load balancing method provided by the embodiment of the present application;
图5是本申请实施例提供的负载均衡方法的应用场景示意图;FIG. 5 is a schematic diagram of an application scenario of the load balancing method provided by an embodiment of the present application;
图6为本申请实施例提供的一种负载均衡装置的示意图;FIG. 6 is a schematic diagram of a load balancing apparatus provided by an embodiment of the present application;
图7为本申请实施例提供的另一种负载均衡装置的示意图;FIG. 7 is a schematic diagram of another load balancing apparatus provided by an embodiment of the present application;
图8为本申请实施例提供的一种电子设备的结构示意图FIG. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present application
具体实施方式Detailed ways
为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。In order to make the objectives, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.
随着集群技术的发展,负载均衡作为集群技术的核心也得到广泛关注研究。负载均衡保证后端服务器的负载相当的同时,还需要保证将属于同一个连接的数据包被发送到同一个后端服务器。属于同一个连接的数据包的五元组相同。With the development of cluster technology, load balancing, as the core of cluster technology, has also received extensive attention and research. While load balancing ensures that the load on the backend servers is equal, it also needs to ensure that packets belonging to the same connection are sent to the same backend server. The quintuple of packets belonging to the same connection is the same.
负载均衡旨在提供高可用性、高性能的集群技术,它提供了一种廉价有效透明的方法扩展集群的带宽、增加集群的吞吐量、加强集群对网络数据的处理能力,保证业务的高可用性。Load balancing aims to provide high-availability and high-performance cluster technology. It provides a cheap, effective and transparent method to expand the bandwidth of the cluster, increase the throughput of the cluster, strengthen the cluster's ability to process network data, and ensure high service availability.
现有的四层负载均衡技术使用LVS架构,是一种基于TCP/IP的负载均衡技术,通过IP虚拟服务器(IP Virtual Server,IPVS)模块来实现,工作在内核。LVS架构存在如下弊端:The existing four-layer load balancing technology uses the LVS architecture, which is a TCP/IP-based load balancing technology, implemented through an IP Virtual Server (IP Virtual Server, IPVS) module, and works in the kernel. The LVS architecture has the following disadvantages:
第一、性能开销严重。First, the performance overhead is serious.
基于LVS架构,数据包的转发需要经过网卡、内核系统才能实现转发。从设计的角度来说,操作系统为了保证安全性和隔离性,数据包经过内核时都要经历:分配套接字缓存(Socket Buffer,SKB)、套接字加锁、TCP(或UDP)……协议栈、内核态和用户态切换。导致性能开销严重。同时,LVS架构需要保证集群内的各个负载均衡器之间同步,导致流量异常增加以及负载均衡器性能开销大。Based on the LVS architecture, the forwarding of data packets needs to pass through the network card and the kernel system to achieve forwarding. From a design point of view, in order to ensure security and isolation of the operating system, data packets must go through: allocation of socket buffers (Socket Buffer, SKB), socket locking, TCP (or UDP)... …protocol stack, kernel mode and user mode switching. Causes serious performance overhead. At the same time, the LVS architecture needs to ensure synchronization between the load balancers in the cluster, resulting in an abnormal increase in traffic and high performance overhead of the load balancer.
第二、负载均衡器容易受负载突增的影响。Second, load balancers are susceptible to load spikes.
基于LVS架构,由于性能开销大,数据流量较大时会增加设备故障的可能性。因此,为了降低机器故障率,通过将负载均衡器和后端真正提供服务的RS放在不同的主机上,负载均衡器的数量少于RS的数量,这使得负载均衡器容易受到负载突增的影响。数据包在负载均衡器处理之前要经过常规的linux网络堆栈,更是加剧了这个问题。Based on the LVS architecture, due to the high performance overhead, the possibility of equipment failure will increase when the data traffic is large. Therefore, in order to reduce the machine failure rate, the number of load balancers is less than the number of RSs by placing the load balancer and the RS that the backend really provides services on different hosts, which makes the load balancer vulnerable to load surges. influences. This problem is exacerbated by the fact that packets go through the regular linux networking stack before being processed by the load balancer.
为克服LVS负载均衡技术的问题,业界引入基于XDP实现的负载均衡架构。这种架构中,数据包进入用户态之前直接对数据包进行过滤或处理,相对于基于LVS的负载均衡架构,基于XDP的负载均衡架构的性能更优。基于XDP的负载均衡架构具有如下优点:In order to overcome the problems of LVS load balancing technology, the industry has introduced a load balancing architecture based on XDP. In this architecture, the data packets are directly filtered or processed before entering the user mode. Compared with the LVS-based load balancing architecture, the XDP-based load balancing architecture has better performance. The XDP-based load balancing architecture has the following advantages:
a、及时、高效的数据包处理。a. Timely and efficient packet processing.
基于XDP的负载均衡架构下,负载均衡器在驱动程序模式下被启用后,在网卡收到数据包之后、内核截获数据包之前,负载均衡器处理数据包。处理过程中,对于每个入站的数据包,负载均衡器一律调用柏克莱封包过滤器(Berkeley Packet Filter,BPF)程序。如果网卡有多个队列,则负载均衡器为每一个队列并行调用BPF程序。而且,用于处理数据包的BPF程序是无锁的,使用每个CPU特有的BPF映射。基于这种并行机制,负载均衡的性能随着网卡的接收队列的数量呈线性扩展。Under the XDP-based load balancing architecture, after the load balancer is enabled in driver mode, the load balancer processes the data packets after the network card receives the data packets and before the kernel intercepts the data packets. During the processing, for each incoming data packet, the load balancer will always call the Berkeley Packet Filter (BPF) procedure. If the network card has multiple queues, the load balancer calls the BPF program in parallel for each queue. Also, the BPF program used to process packets is lock-free, using a BPF map specific to each CPU. Based on this parallel mechanism, the performance of load balancing scales linearly with the number of receive queues of the network card.
b、无需保证集群内的各个负载均衡器之间同步。b. There is no need to ensure synchronization between load balancers in the cluster.
基于XDP的负载均衡架构采用一致性哈希(hash)算法代替传统的负载均衡算法,避免了基于LVS的负载均衡架构保证集群内的各个负载均衡器之间同步,因此能够避免流量异常和负载均衡器性能开销大的问题。The XDP-based load balancing architecture uses a consistent hash algorithm to replace the traditional load balancing algorithm, avoiding the LVS-based load balancing architecture to ensure synchronization between load balancers in the cluster, so it can avoid abnormal traffic and load balancing The problem of high performance overhead.
c、提供快速路径c. Provide a fast path
基于XDP的负载均衡架构为高速处理数据包提供一条快速路径,负载均衡器和RS部署在同一个主机上一起运行,且性能不会出现任何下降。同时,增强了面对负载猛增、主机故障和维护的适应能力。The XDP-based load balancing architecture provides a fast path for processing packets at high speed, and the load balancer and RS are deployed on the same host to run together without any performance degradation. At the same time, it enhances the adaptability in the face of load surges, host failures and maintenance.
基于XDP的负载均衡架构和基于LVS的负载均衡架构的相同点在于:负载均衡器需要和机房的交换机起路由协议,如开放式最短路径优先(Open Shortest Path First,OSPF)协议,目的是为了向外界通告负载均衡器的虚拟IP地址(vertical IP,VIP)。之后,客户端才能将数据包发送到集群内相应的负载均衡器上。最后,负载均衡器根据负载均衡算法从多个RS中选择出一个RS,并将数据包发送给该RS。The same point between the XDP-based load balancing architecture and the LVS-based load balancing architecture is that the load balancer needs to have a routing protocol with the switch in the computer room, such as the Open Shortest Path First (OSPF) protocol, in order to The outside world advertises the virtual IP address (vertical IP, VIP) of the load balancer. After that, the client can send the packet to the corresponding load balancer in the cluster. Finally, the load balancer selects one RS from the multiple RSs according to the load balancing algorithm, and sends the data packet to the RS.
通常情况下,集群对外提供服务时集群内的主机的数量增减无法避免且频率很高。实际使用发现:当在集群中新增主机时,原本发送给集群的RS甲的数据包被发送给RS乙,导致集群内的正在进行的业务发生异常。而且,异常的比例随着新增主机的数量的增加而增加。Usually, the number of hosts in the cluster is unavoidable and frequent when the cluster provides services to the outside world. Actual usage discovery: When a host is added to the cluster, the data packet originally sent to RS A of the cluster is sent to RS B, causing an exception to the ongoing business in the cluster. Moreover, the proportion of anomalies increases with the number of new hosts.
为了对集群新增机器,业界考虑对交换机进行改进。但是实际中,一个交换机连接着许多的主机,每台主机上都有流量。如果改动交换机,则意味着:由于规划的变动或机器宕机等原因需要在集群中增加机器或替换机器时,若通过改动交换机实现,则需要将整个集群的流量全部备份,不然会对集群内正在进行的业务造成影响,耗费人力物力且导致业务质量差,引起客户投诉。其中,正在进行的业务称之为旧业务、已有业务等,用于传输正在进行的业务的数据包的连接称之为旧连接。In order to add machines to the cluster, the industry considers improving the switches. But in reality, a switch is connected to many hosts, and each host has traffic. If the switch is changed, it means that when a machine needs to be added or replaced in the cluster due to changes in planning or machine downtime, if it is achieved by changing the switch, all the traffic of the entire cluster needs to be backed up. The ongoing business has an impact, consumes manpower and material resources, leads to poor business quality, and causes customer complaints. Among them, the ongoing service is referred to as an old service, an existing service, etc., and a connection for transmitting data packets of an ongoing service is referred to as an old connection.
显然,现有的基于XDP的负载均衡架构,无法在集群中新增机器,大大限制了集群的可拓展性和可用性。Obviously, the existing XDP-based load balancing architecture cannot add new machines to the cluster, which greatly limits the scalability and availability of the cluster.
基于此,本申请实施例提供一种负载均衡方法、装置、设备及可读存储介质,通过对负载均衡器进行改进,使得负载均衡器具有查询各RS的挂载时长的功能,以解决基于XDP的架构增加新的服务器时对已有业务的影响,实现提高业务可靠性的目的的同时,无需改动交换机。Based on this, the embodiments of the present application provide a load balancing method, apparatus, device, and readable storage medium. By improving the load balancer, the load balancer has the function of querying the mount duration of each RS, so as to solve the problem based on XDP It can improve the reliability of the service without changing the switch when the new server is added.
图1是本申请实施例提供的负载均衡方法所适用的负载均衡系统的架构示意图。请参照图1,该负载均衡系统包括主机11、查询设备12、交换机13和终端设备14。查询设备12与各主机11之间建立网络连接。各主机11和交换机13之间建立网络连接,终端设备14和交换机13之间建立网络连接。FIG. 1 is a schematic structural diagram of a load balancing system to which the load balancing method provided by the embodiment of the present application is applicable. Referring to FIG. 1 , the load balancing system includes a host 11 , a
主机11也称之为机器、服务器等,每台主机11上部署基于XDP的负载均衡器111和RS112。负载均衡器111具有查询各RS112的VIP的功能,能够通过查询设备12获取各主机11上的RS112的VIP以及VIP的通告时间点。需要说明的是,由于每台主机11上部署负载均衡器111和RS12,因此,主机11的VIP、该主机11上的负载均衡器111、该主机11上的RS112的VIP相同。The host 11 is also referred to as a machine, a server, etc., and an XDP-based load balancer 111 and an RS 112 are deployed on each host 11 . The load balancer 111 has the function of querying the VIP of each RS 112 , and can obtain the VIP of the RS 112 on each host 11 and the announcement time point of the VIP through the
查询设备12也称之为IP watcher组件,其可以是独立与主机11的机器,也可以是一台主机11,该主机11上部署负载均衡器111和RS112的同时,保存负载均衡系统中各主机11的VIP以及VIP的通告时间点。负载均衡系统中每次新增主机11时,新增主机11的RS112向查询设备12通告VIP,查询设备12记录RS112的VIP以及通告时间点。由此可见,查询设备12用于收集并记录负载均衡系统内每个RS112的VIP以及通告时间点。通告时间点即为新增主机11的时间点。The
交换机13用于连接终端设备14和主机11,用于第一次负载均衡。交换机13接收到来自终端设备14的数据包后,从多个主机11中选择一台主机11并发送数据包。选中的主机11的负载均衡器111接收到数据包后,执行本申请实施例提供的负载均衡方法进行第二次负载均衡,从多个RS112中选中目标RS,并将数据包发送给目标RS。The
终端设备14可以是硬件也可以是软件。当终端设备14为硬件时,终端设备14例如为安装有安卓操作系统、微软操作系统、塞班操作系统、Linux操作系统或苹果iOS操作系统的手机、平板电脑、个人电脑、电子书阅读器、膝上型便携电脑、台式计算机等。当终端设备14为软件时,其可以安装在上述列举的硬件设备中,此时,终端设备14例如为多个软件模块或单个软件模块等,本申请实施例并不限制。The
请参照图1,负载均衡器111使用快速重路由(Fast Reroute,FRR)、quagga等和交换机13进行对等互联,向交换机13通告负载均衡器111的VIP。然后,交换机13使用等价多路径(Equal-Cost Multipath Routing,ECMP)机制,从已经通告VIP的负载均衡器111中选中一台目标负载均衡器并发送数据包,从而完成第一次负载均衡。其中,负载均衡器111向交换机13通告VIP时,通常使用开放式最短路径优先(Open Shortest Path First,OSPF)路由协议等。Referring to FIG. 1 , the load balancer 111 uses Fast Reroute (FRR), quagga, etc. to perform peering with the
根据上述可知:本申请实施例中存在两种VIP通告,一种是负载均衡器111使用OSPF路由协议向外界,即向交换机13等通告负载均衡器111的VIP。一种是RS112向查询设备12通告RS112的VIP。It can be known from the above that there are two types of VIP advertisements in this embodiment of the present application. One is that the load balancer 111 uses the OSPF routing protocol to advertise the VIP of the load balancer 111 to the outside world, that is, to the
第一次负载均衡后,数据包经过交换机13到达负载均衡器111后,负载均衡器111会从负载均衡系统包含的主机11上的RS112中选出目标RS,并将数据包发送给目标RS,从而完成第二次负载均衡。为了保证同一个业务的数据包发送到同一个目标RS,负载均衡器111接收到一个业务的第一个数据包后,会使用一致性哈希算法。一致性哈希算法根据数据包的五元组、负载均衡系统内各RS的VIP、RS的数量等,确定出目标RS。针对一个业务的第一个数据包确定出目标RS后,负载均衡器111在本地的映射表中记录第一个数据包的五元组和目标RS的映射关系。这样一来,后续负载均衡器111每次接收到同一个业务的数据包后,根据数据包的五元组查询映射表即可确定出目标RS。After the first load balancing, after the data packet reaches the load balancer 111 through the
也就是说,本申请实施例中,负载均衡器111每次接收到数据包后,优先根据数据包的五元组查询映射表,若映射表中存在数据包的五元组,则直接将五元组对应的RS作为目标RS。若映射表中不存在该数据包的五元组,则确定生效RS,并从生效RS中确定出目标RS。That is to say, in this embodiment of the present application, after each time the load balancer 111 receives a data packet, it preferentially queries the mapping table according to the quintuple of the data packet. The RS corresponding to the tuple is used as the target RS. If the quintuple of the data packet does not exist in the mapping table, the valid RS is determined, and the target RS is determined from the valid RS.
采用该种方案,负载均衡器每次执行第二次负载均衡时优先查映射表以确定目标RS,只有在无法通过查询映射表的方式确定出目标RS时,才从生效RS中确定出目标RS,避免反复执行一致性哈希带来的性能消耗。With this solution, the load balancer first checks the mapping table to determine the target RS each time it performs the second load balancing, and only determines the target RS from the valid RSs when the target RS cannot be determined by querying the mapping table. , to avoid the performance consumption caused by repeated consistent hashing.
可选的,上述实施例中,负载均衡器从生效RS中确定出目标RS之后,还在映射表中新增数据包的五元组和目标RS的映射关系。这样一来,每次确定出新的五元组和RS的映射关系,则在映射表中新增一条记录。由于同一个业务的数据包的五元组相同,因此,后续接收到同一个业务的数据包后,直接查询映射表即可确定出目标RS,无需执行一致性哈希运算,速度快、性能消耗低。Optionally, in the above embodiment, after the load balancer determines the target RS from the valid RS, the mapping relationship between the quintuple of the data packet and the target RS is added to the mapping table. In this way, each time a new mapping relationship between the quintuple and the RS is determined, a new record is added to the mapping table. Since the quintuple of the data packets of the same service is the same, after receiving the data packets of the same service, the target RS can be determined by directly querying the mapping table without performing consistent hash operation, which is fast and consumes performance. Low.
采用该种方案,通过将五元组和目标RS的映射关系存储在映射表中,能够避免后续反复执行一致性哈希带来的性能消耗。With this solution, by storing the mapping relationship between the quintuple and the target RS in the mapping table, the performance consumption caused by the subsequent repeated execution of consistent hashing can be avoided.
可选的,上述实施例中,负载均衡器从生效RS中确定出目标RS时,根据生效RS的VIP、数据包的五元组、生效RS的数量等进行一致性哈希运算,从而确定出目标RS。Optionally, in the above-mentioned embodiment, when the load balancer determines the target RS from the effective RS, it performs a consistent hash operation according to the VIP of the effective RS, the quintuple of the data packet, the number of the effective RS, etc., so as to determine the target RS. Target RS.
另外,由于同一个业务的所有数据包的五元组相同,因此,当负载均衡系统内的RS的数量不变时,无论哪个负载均衡器111接收到数据包,都可以将属于同一个业务的数据包发送给同一个目标RS。因此,不需要负载均衡系统内的各个负载均衡器111进行同步。In addition, since the quintuple of all data packets of the same service is the same, when the number of RSs in the load balancing system remains unchanged, no matter which load balancer 111 receives the data packet, it can The packets are sent to the same target RS. Therefore, synchronization of the various load balancers 111 within the load balancing system is not required.
当负载均衡系统内新增主机11时,相当于同时增加负载均衡器111和RS112。交换机13使用OSPF路由协议执行第一次负载均衡确定目标负载均衡器,很有可能将数据包发送给新增主机11上的负载均衡器111,负载均衡器111的映射表为空。When a host 11 is added in the load balancing system, it is equivalent to adding a load balancer 111 and an RS 112 at the same time. The
新增主机11导致RS112的数量发生变化,进而导致一致性哈希算法的结果发生变化。因此,传统的基于XDP的负载均衡架构中,当负载均衡器111接收到一个数据包,且该数据包是已有业务的数据包时,负载均衡器111根据一致性哈希算法确定出的目标RS,很有可能不是正确的RS,例如,负载均衡器111将原本应该发送给RS甲的数据包被发送给RS乙。RS乙接收到数据包后,由于RS乙上并没有已有业务的五元组等信息,因此直接丢弃数据包或者反馈复位(reset,RST),导致已有业务异常。显然,交换机13的第一次负载均衡和负载均衡器111的第二次负载均衡,导致负载均衡系统中新增主机11时,已有业务异常的比例飙升。The addition of host 11 results in a change in the number of RS112s, which in turn results in a change in the results of the consistent hashing algorithm. Therefore, in the traditional XDP-based load balancing architecture, when the load balancer 111 receives a data packet, and the data packet is a data packet of an existing service, the load balancer 111 determines the target according to the consistent hash algorithm The RS may not be the correct RS. For example, the load balancer 111 sends the data packet that should be sent to RS A to RS B. After RS B receives the data packet, since there is no information such as the quintuple of the existing service on RS B, it directly discards the data packet or feeds back a reset (reset, RST), resulting in an abnormality of the existing service. Obviously, the first load balancing of the
可以理解的是:已有业务是指新增主机11之前,负载均衡系统中存在至少一个主机11,该主机11上的负载均衡器111的映射表中存在这个业务的五元组和目标RS的对应关系。例如,一个视频业务,新增主机11之前,负载均衡系统中有3个主机11,相应的,负载均衡系统中有3个负载均衡器。若全部或部分负载均衡器的映射表中记录视频业务的五元组和目标RS的映射关系,则说明视频业务为已有业务。It can be understood that: an existing service refers to at least one host 11 in the load balancing system before the new host 11 is added, and the mapping table of the load balancer 111 on the host 11 contains the quintuple of the service and the target RS. Correspondence. For example, for a video service, before adding a host 11, there are three hosts 11 in the load balancing system, and correspondingly, there are three load balancers in the load balancing system. If the mapping relationship between the quintuple of the video service and the target RS is recorded in the mapping table of all or part of the load balancer, it indicates that the video service is an existing service.
本申请实施例中,每次新增主机11时,新增主机11上的RS112向查询设备12上报VIP,查询设备12记录新增主机11上的RS112的VIP和通告时间点。而且,每次新增主机11时,开启新增主机11上的负载均衡器111的功能,暂不开启新增主机11上的RS112的功能,而是经过预设时长后才开启新增主机11上的RS112的功能。新增主机11上的RS112的功能开启后,负载均衡器111执行一致性哈希运算时考虑该RS112。In the embodiment of the present application, each time a host 11 is added, the RS 112 on the new host 11 reports the VIP to the
负载均衡器111接收到数据包后,从多个RS112中确定出挂载时长超过预设时长的RS112作为生效RS112。之后,从生效RS112中确定出目标RS并发送数据包。也就是说,每次新增主机11后,新增主机11上的RS112并不立即参与一致性哈希算法,经过预设时长后才参与一致性哈希算法。预设时长内,初始时,新增主机11上的负载均衡器111的映射表为空。之后,每次接收到数据包后,若映射表中不存在数据包的五元组,则根据生效RS112、数据包的五元组等执行一致性哈希,确定出目标RS并发送数据包。同时,新增主机11上的负载均衡器111在映射表中记录五元组与目标RS的映射关系。After receiving the data packet, the load balancer 111 determines, from the multiple RSs 112, the RS 112 whose mounting duration exceeds the preset duration as the effective RS 112. After that, the target RS is determined from the valid RS 112 and a data packet is sent. That is to say, after each new host 11 is added, the RS 112 on the newly added host 11 does not immediately participate in the consistent hashing algorithm, and only participates in the consistent hashing algorithm after a preset time period. Within the preset time period, initially, the mapping table of the load balancer 111 on the newly added host 11 is empty. After that, after each data packet is received, if the quintuple of the data packet does not exist in the mapping table, consistent hashing is performed according to the valid RS112, the quintuple of the data packet, etc., to determine the target RS and send the data packet. At the same time, the load balancer 111 on the newly added host 11 records the mapping relationship between the quintuple and the target RS in the mapping table.
这样一来,新增主机11经过预设时长后,新增主机11上的负载均衡器111的映射表中会记录所有已有业务的数据包的五元组和目标RS的映射关系。预设时长后,新增主机11上的RS112生效,这时,若使用一致性哈希算法确定已有业务的数据包的目标RS,则很有可能出错。但是,针对已有业务的数据包,负载均衡器111优先查询映射表,因此能够确定出正确的目标RS。针对新业务的数据包,负载均衡器111根据当前已生效的RS112、新业务的数据包的五元组等执行一致性哈希算法确定目标RS并在映射表中增加新的记录。In this way, after the preset time period has elapsed for the newly added host 11, the mapping table of the load balancer 111 on the newly added host 11 will record the mapping relationship between the quintuple of the data packets of all existing services and the target RS. After the preset time period, the RS112 on the newly added host 11 takes effect. At this time, if the consistent hash algorithm is used to determine the target RS of the data packet of the existing service, an error is likely to occur. However, for the data packets of existing services, the load balancer 111 preferentially queries the mapping table, so that the correct target RS can be determined. For the data packet of the new service, the load balancer 111 performs a consistent hash algorithm to determine the target RS according to the currently valid RS 112, the quintuple of the data packet of the new service, etc., and adds a new record to the mapping table.
对于负载均衡系统中原有主机11上的负载均衡器111而言,若负载均衡器111的映射表中本来就存在已有业务的数据包的五元组和目标RS的映射关系,则通过查询映射表就能够确定出正确的目标RS。若映射表中不存在已有业务的数据包的五元组和目标RS的映射关系,则同样能够根据生效RS112、数据包的五元组等执行一致性哈希确定出目标RS并发送数据包。For the load balancer 111 on the original host 11 in the load balancing system, if the mapping table of the load balancer 111 already has a mapping relationship between the quintuple of the existing service data packet and the target RS, the mapping relationship can be obtained by querying the mapping The table can determine the correct target RS. If there is no mapping relationship between the quintuple of the data packet of the existing service and the target RS in the mapping table, the target RS can also be determined according to the effective RS112, the quintuple of the data packet, etc., and the target RS can be sent to send the data packet. .
应当理解的是,图1中的主机11、查询设备12、交换机13和终端设备14的数量仅仅是示意性的。实际实现中,根据实际需求部署任意数量的主机11、查询设备12、交换机13和终端设备14。It should be understood that the numbers of hosts 11,
图2是本申请实施例提供的基于XDP的负载均衡架构在主机上的工作层级示意图。请参照图2,主机上的工作层级包括:网卡驱动、负载均衡器、内核(kernel)用户进程等。其中,负载均衡器为基于XDP的负载均衡器,用户进程是用户态下的相关进程。当主机上的RS是内容分发网络(Content Delivery Network,CDN)中的边缘节点时,用户态具有squid缓存以及shark(调度)组件等。FIG. 2 is a schematic diagram of a working level of an XDP-based load balancing architecture on a host provided by an embodiment of the present application. Referring to FIG. 2 , the working layers on the host include: a network card driver, a load balancer, a kernel (kernel) user process, and the like. The load balancer is an XDP-based load balancer, and the user process is a related process in the user mode. When the RS on the host is an edge node in a Content Delivery Network (CDN), the user mode has a squid cache and a shark (scheduling) component.
请参照图2,主机在驱动程序模式下被启用,数据包处理在网卡收到数据包之后、内核截获前进行,避免了用户态和内核态切换导致的开销,因此,相较于基于LVS的负载均衡架构,本申请实施例提供的基于XDP的负载均衡架构能够降低性能开销。Referring to Figure 2, the host is enabled in driver mode, and the data packet processing is performed after the network card receives the data packet and before the kernel intercepts it, avoiding the overhead caused by switching between user mode and kernel mode. Therefore, compared with LVS-based Load balancing architecture, the XDP-based load balancing architecture provided by the embodiments of the present application can reduce performance overhead.
下面,基于图1所示负载均衡系统,对本申请实施例所述的负载均衡方法进行详细说明。示例性的,请参照图3,图3是本申请实施例提供的负载均衡方法的流程图。本实施例是从负载均衡器的角度进行说明。本实施例包括:Below, based on the load balancing system shown in FIG. 1 , the load balancing method described in the embodiments of the present application will be described in detail. For example, please refer to FIG. 3 , which is a flowchart of a load balancing method provided by an embodiment of the present application. This embodiment is described from the perspective of a load balancer. This embodiment includes:
301、负载均衡器确定负载均衡系统中存在新增主机。301. The load balancer determines that a new host exists in the load balancing system.
其中,负载均衡器是所述负载均衡系统包含的多个主机中的任意一个主机上的负载均衡器,所述多个主机中的每个主机上均部署负载均衡器和真实服务器RS。由于每个主机上部署负载均衡器和RS,因此,每新增一台主机,则表示负载均衡器和RS分别增加一台。The load balancer is a load balancer on any one of the multiple hosts included in the load balancing system, and the load balancer and the real server RS are deployed on each of the multiple hosts. Since the load balancer and RS are deployed on each host, each new host means that one load balancer and one RS are added respectively.
本申请实施例中,包括两次负载均衡,以下分别称之为第一次负载均衡和第二次负载均衡,第一次负载均衡指交换从多个主机的负载均衡器中选择目标负载均衡器,并将数据包发送给目标负载均衡器。第二次负载均衡指目标负载均衡器从多个主机的RS中选中目标RS并将数据包发送给目标RS。目标负载均衡器和目标RS可能位于同一个主机,也可能位于不同的主机。In the embodiment of the present application, two load balancing are included, which are referred to as the first load balancing and the second load balancing respectively, and the first load balancing refers to switching to select a target load balancer from the load balancers of multiple hosts. , and send the packet to the target load balancer. The second load balancing means that the target load balancer selects the target RS from the RSs of multiple hosts and sends the data packet to the target RS. The target load balancer and target RS may be on the same host or on different hosts.
本申请实施例中,负载均衡器是新增主机之后,负载均衡系统中每个主机上的负载均衡器。也就是说,负载均衡系统中的每一个负载均衡器,包括负载均衡系统中原有主机上的负载均衡器,以及新增主机上的负载均衡器,每个负载均衡器检测出负载均衡系统中新增主机后,均执行本申请实施例所述的负载均衡方法。In the embodiment of the present application, the load balancer is a load balancer on each host in the load balancing system after the new host is added. That is to say, each load balancer in the load balancing system includes the load balancer on the original host in the load balancing system and the load balancer on the newly added host. After the hosts are added, the load balancing method described in the embodiments of the present application is executed.
负载均衡器确定负载均衡系统新增主机后,一旦该负载均衡器接收到来自交换机的数据包,则表示该负载均衡器为目标负载均衡器。After the load balancer determines that a new host is added to the load balancing system, once the load balancer receives the data packet from the switch, it indicates that the load balancer is the target load balancer.
302、负载均衡器接收数据包。302. The load balancer receives the data packet.
示例性的,交换机执行第一次负载均衡,从多个主机的负载均衡器选中目标负载均衡器并发送数据包给目标负载均衡器。相应的,目标负载均衡器接收数据包。数据包可以是用户的终端设备发起的业务请求等,目标RS接收到数据包后,根据数据包响应业务请求。Exemplarily, the switch performs the first load balancing, selects the target load balancer from the load balancers of the multiple hosts, and sends the data packet to the target load balancer. Accordingly, the target load balancer receives the packet. The data packet may be a service request initiated by the user's terminal equipment, etc. After receiving the data packet, the target RS responds to the service request according to the data packet.
从交换机的角度而言,和传统的基于XDP的负载均衡架构一样,使用OSPF路由协议执行第一次负载均衡确定目标负载均衡器,很有可能将数据包发送给新增主机上的负载均衡器,新增主机上的负载均衡器的映射表为空。当然,交换机也很有可能将数据包发送给原有主机上的负载均衡器。From the switch's point of view, like the traditional XDP-based load balancing architecture, the OSPF routing protocol is used to perform the first load balancing to determine the target load balancer, and it is likely to send packets to the load balancer on the newly added host. , the mapping table of the load balancer on the newly added host is empty. Of course, there is also a good chance that the switch will send the packet to the load balancer on the original host.
303、负载均衡器从负载均衡系统包含的各主机的RS中确定出生效RS,所述生效RS是新增主机之前所述负载均衡器对已有业务的数据包进行负载均衡时涉及的RS,所述已有业务是新增主机之前所述负载均衡系统正在提供给用户的业务。303. The load balancer determines the effective RS from the RSs of each host included in the load balancing system, and the effective RS is the RS involved when the load balancer performs load balancing on the data packets of the existing services before the new host is added, The existing service is the service that the load balancing system is providing to the user before the new host is added.
本申请实施例中,负载均衡器每次接收到数据包后,查询本地的映射表,若映射表中不存在该数据包的五元组,则执行一致性哈希运算以确定目标RS。传统的基于XDP的负载均衡架构中,当有新增主机时,负载均衡器根据数据包的五元组、负载均衡系统中所有RS的VIP、以及RS的数量执行一致性哈希,导致确定出的目标RS不正确。In the embodiment of the present application, each time the load balancer receives a data packet, it queries a local mapping table, and if the quintuple of the data packet does not exist in the mapping table, a consistent hash operation is performed to determine the target RS. In the traditional XDP-based load balancing architecture, when a new host is added, the load balancer performs consistent hashing according to the quintuple of data packets, the VIPs of all RSs in the load balancing system, and the number of RSs, resulting in the determination of The target RS is incorrect.
本申请实施例中,每次新增主机后,该主机上的RS并不立即生效,即并不立即参与负载均衡,而是待新增主机上的负载均衡器的映射表中保存所有已有业务的五元组和RS的映射关系后,才将新增主机上的RS用于负载均衡。In the embodiment of the present application, after each new host is added, the RS on the host does not take effect immediately, that is, it does not participate in load balancing immediately, but saves all existing After the mapping relationship between the quintuple of the service and the RS, the RS on the newly added host is used for load balancing.
因此,负载均衡器查映射表无法确定出目标RS而执行一致性哈希时,从所有RS中确定出生效RS。生效的RS有可能提供至少一种已有业务的RS,或者没有提供已有业务。但是,无论是否提供已有业务,生效RS都是新增主机之前,负载均衡器对已有业务的数据包执行一致性哈希时涉及的RS。Therefore, when the load balancer cannot determine the target RS by looking up the mapping table and performs consistent hashing, it determines the valid RS from all the RSs. A valid RS may provide at least one RS of an existing service, or may not provide an existing service. However, regardless of whether an existing service is provided, the effective RS is the RS involved when the load balancer performs consistent hashing on the data packets of the existing service before adding a host.
例如,负载均衡系统中有2个主机,分别为主机1和主机2,主机1上部署负载均衡器1a和RS1b,主机2上部署负载均衡器2a和RS2b。新增主机3,主机3上部署负载均衡器3a和RS3b。负载均衡器1a上存储一个映射表,该映射表中存储五元组A和RS2b的对应关系,负载均衡器2a和负载均衡器3a上的映射表的为空,即RS2b已对外提供业务,RS1b并未提供业务。For example, there are two hosts in the load balancing system, namely host 1 and host 2. Load balancers 1a and RS1b are deployed on host 1, and load balancers 2a and RS2b are deployed on host 2. Add host 3, and deploy load balancer 3a and RS3b on host 3. A mapping table is stored on load balancer 1a, which stores the correspondence between quintuple A and RS2b, and the mapping table on load balancer 2a and load balancer 3a is empty, that is, RS2b has provided services to the outside world, and RS1b Business is not provided.
也就是说,新增主机之前,有一种已有业务,该种业务的数据包的五元组分别为五元组A。新增主机之前,负载均衡器(负载均衡器1a或负载均衡器2a)第一次接收到五元组为五元组A的数据包后,根据五元组A、RS1b的VIP、RS2b、RS数量等执行一致性哈希,确定出目标RS为RS2b。显然,新增主机3之前,负载均衡器对已有业务的数据包执行一致性哈希时涉及的RS包括RS1b和RS2b。因此,生效RS包括RS1b和RS2b。That is to say, before the new host is added, there is an existing service, and the quintuple of the data packet of this service is quintuple A, respectively. Before adding a host, after the load balancer (load balancer 1a or load balancer 2a) receives the data packet whose quintuple is quintuple A for the first time, according to the VIP of quintuple A, RS1b, RS2b, RS Quantity, etc., perform consistent hashing, and determine that the target RS is RS2b. Obviously, before adding host 3, the RSs involved when the load balancer performs consistent hashing on data packets of existing services include RS1b and RS2b. Therefore, the effective RS includes RS1b and RS2b.
304、负载均衡器从所述生效RS中确定出目标RS。304. The load balancer determines the target RS from the valid RSs.
示例性的,负载均衡器并非直接从负载均衡系统中所有的RS中选择目标RS,而是先从所有的RS中确定出生效RS,再从生效RS中选出目标RS。Exemplarily, the load balancer does not directly select the target RS from all the RSs in the load balancing system, but first determines the valid RS from all the RSs, and then selects the target RS from the valid RSs.
例如,负载均衡系统中有2个主机,分别为主机1和主机2,主机1上部署负载均衡器1a和RS1b,主机2上部署负载均衡器2a和RS2b。新增主机3,主机3上部署负载均衡器3a和RS3b。负载均衡器1a上存储一个映射表,该映射表中存储五元组A和RS2b的对应关系,负载均衡器2a上的映射表存储五元组B和RS1b的对应关系,负载均衡器3a上的映射表的为空。也就是说,新增主机之前,有两种已有业务,该两种业务的数据包的五元组分别为五元组A和五元组B。For example, there are two hosts in the load balancing system, namely host 1 and host 2. Load balancers 1a and RS1b are deployed on host 1, and load balancers 2a and RS2b are deployed on host 2. Add host 3, and deploy load balancer 3a and RS3b on host 3. Load balancer 1a stores a mapping table, which stores the correspondence between quintuple A and RS2b, and the mapping table on load balancer 2a stores the correspondence between quintuple B and RS1b. The mapping table is empty. That is to say, before the host is added, there are two existing services, and the quintuple of the data packets of the two services are quintuple A and quintuple B, respectively.
假设交换机执行第一次负载均衡选中负载均衡器1a,负载均衡器1a接收到数据包后,确定出数据包的五元组为五元组A。因此,负载均衡器1a根据五元组查询映射表确定出目标RS为RS2b。It is assumed that the switch performs the first load balancing and selects the load balancer 1a. After receiving the data packet, the load balancer 1a determines that the quintuple of the data packet is quintuple A. Therefore, the load balancer 1a determines that the target RS is RS2b according to the five-tuple query mapping table.
假设交换机执行第一次负载均衡选中负载均衡器2a,负载均衡器2a接收到数据包后,确定出数据包的五元组为五元组A。但是,由于映射表为空,因此,负载均衡器2a确定生效RS,生效RS包括RS1b和RS2b。之后,负载均衡器2a执行一致性哈希算法确定出目标RS为RS2b。It is assumed that the switch performs the first load balancing and selects the load balancer 2a. After receiving the data packet, the load balancer 2a determines that the quintuple of the data packet is quintuple A. However, since the mapping table is empty, the load balancer 2a determines the valid RS, and the valid RS includes RS1b and RS2b. After that, the load balancer 2a performs a consistent hashing algorithm to determine that the target RS is RS2b.
假设交换机执行第一次负载均衡选中负载均衡器3a,负载均衡器3a接收到数据包后,确定出数据包的五元组为五元组A。但是,由于映射表为空,因此,负载均衡器3a确定生效RS,生效RS包括RS1b和RS2b。之后,负载均衡器3a执行一致性哈希算法确定出目标RS为RS2b。Assuming that the switch performs the first load balancing and selects the load balancer 3a, after receiving the data packet, the load balancer 3a determines that the quintuple of the data packet is quintuple A. However, since the mapping table is empty, the load balancer 3a determines the valid RS, and the valid RS includes RS1b and RS2b. After that, the load balancer 3a performs a consistent hashing algorithm to determine that the target RS is RS2b.
再如,负载均衡系统中原本有100个主机,新增主机时,增加了一批主机,这批主机共10个,使得负载均衡系统中总共有110个主机,该100个主机上的RS的编号为100至110。增加一批主机时,110个主机中的每个主机上的负载均衡器检测出新增主机。当任意一个主机上的负载均衡器接收到数据包时,若无法通过查询映射表的方式确定出目标RS时,负载均衡器确定生效RS,假设编号为1-90RS是新增主机之前,负载均衡器对已有业务的数据包进行负载均衡时涉及的RS,则负载均衡器从根据数据包的五元组、这90个RS中各RS的VIP和RS的数量确定目标RS。For another example, there were originally 100 hosts in the load balancing system. When a new host was added, a batch of hosts was added. This batch of hosts totaled 10, making a total of 110 hosts in the load balancing system. The RS on the 100 hosts Numbered 100 to 110. When adding a batch of hosts, the load balancer on each of the 110 hosts detected the new host. When the load balancer on any host receives a data packet, if the target RS cannot be determined by querying the mapping table, the load balancer determines the effective RS. It is assumed that the number of 1-90 RS is before the new host is added. The load balancer determines the target RS according to the quintuple of the data packet, the VIP of each RS in the 90 RSs, and the number of RSs.
305、负载均衡器向所述目标RS发送所述数据包。305. The load balancer sends the data packet to the target RS.
本申请实施例中,发送数据包的负载均衡器,即目标负载均衡器和目标RS位于同一个主机或不同主机。In this embodiment of the present application, the load balancer that sends the data packet, that is, the target load balancer and the target RS are located on the same host or different hosts.
本申请实施例提供的负载均衡方法,负载均衡系统中的各主机上的负载均衡器检测出负载均衡系统中新增主机时,一旦一个负载均衡器接收到数据包,倘若映射表中不存在该数据包的五元组,则从负载均衡系统包含的各主机的RS中确定出用于负载均衡的生效RS,从生效RS中选择出目标RS并将数据包发送给目标RS,从而完成第二次负载均衡。采用该种方案,每次新增主机后,负载均衡器从已生效的RS中确定出目标RS并发送数据包,确保新增主机上的负载均衡器的有充足的时间针对已有业务生成映射表,映射表中记录已有业务的五元组和RS的映射关系,避免负载均衡器将已有业务的数据包发送给不正确的RS。也就是说,每次新增主机后,该主机上的负载均衡器生效但是RS并不立即参与负载均衡,而是待新增主机上的负载均衡器的映射表中保存所有已有业务的五元组和RS的映射关系后,才将新增主机上的RS用于负载均衡,确保新增主机后已有业务的数据包发送给正确的RS,实现提高业务质量的目的的同时,无需改动交换机,减少影响面和操作复杂度。In the load balancing method provided by the embodiment of the present application, when the load balancer on each host in the load balancing system detects a new host in the load balancing system, once a load balancer receives a data packet, if the load balancer does not exist in the mapping table The five-tuple of the data packet, the effective RS for load balancing is determined from the RSs of each host included in the load balancing system, the target RS is selected from the effective RS, and the data packet is sent to the target RS, thereby completing the second Secondary load balancing. With this solution, after each new host is added, the load balancer determines the target RS from the valid RSs and sends data packets, ensuring that the load balancer on the newly added host has sufficient time to generate mappings for existing services The mapping table records the mapping relationship between the quintuple of the existing service and the RS, so as to prevent the load balancer from sending the data packet of the existing service to the incorrect RS. That is to say, each time a host is added, the load balancer on the host takes effect, but the RS does not immediately participate in load balancing. Instead, the mapping table of the load balancer on the host to be added saves all existing services in the mapping table. After the mapping relationship between the tuple and the RS, the RS on the newly added host is used for load balancing to ensure that the data packets of the existing services after the newly added host are sent to the correct RS, and the purpose of improving the service quality is achieved without any modification. switches, reducing the impact surface and operational complexity.
可选的,上述实施例中,负载均衡器从负载均衡系统包含的各主机的RS中确定出生效RS的过程中,确定各主机的RS的挂载时长,将挂载时长超过预设时长的RS作为生效RS。其中,挂载时长指通告时间点和接收时间点之间的时长,通告时间点是主机的RS向查询设备通告VIP的时间点,接收时间点是负载均衡器接收到数据包的时间点。通过对比挂载时长和预设时长,实现准确确定出生效RS的目的。Optionally, in the above embodiment, in the process of determining the effective RS from the RSs of each host included in the load balancing system, the load balancer determines the mounting duration of the RSs of each host, and determines the mounting duration of the RSs of the hosts exceeds the preset duration. RS as the effective RS. The mount duration refers to the duration between the notification time point and the reception time point, the notification time point is the time point when the host's RS announces the VIP to the querying device, and the reception time point is the time point when the load balancer receives the data packet. By comparing the mount duration and the preset duration, the purpose of accurately determining the effective RS is achieved.
一种方式中,每个负载均衡器记录本主机加入负载均衡系统的时间点,将该时间点作为通告时间点,负载均衡系统中的各负载均衡器之间可以相互通信。因此,负载均衡器能够确定出其他主机加入负载均衡系统的时间点,即通告时间点。主机的通告时间点即为主机上的RS的通告时间点。In one method, each load balancer records the time point when the host joins the load balancing system, and uses the time point as the notification time point, and the load balancers in the load balancing system can communicate with each other. Therefore, the load balancer can determine the time point when other hosts join the load balancing system, that is, the advertisement time point. The announcement time point of the host is the announcement time point of the RS on the host.
负载均衡器接收到数据包需要执行一致性哈希时,根据各个主机的RS的通告时间点和接收数据包的接收时间点,就能够确定出RS的挂载时长。将挂载时长超过预设时长的RS作为生效RS。预设时长例如为10分钟、8分钟、20分钟等。本申请实施例并不限制。预设时长至少能够满足:新增主机上的负载均衡器执行第二次负载均衡,以使得该负载均衡器的映射表中保存所有已有业务的五元组和RS的映射关系。When the load balancer needs to perform consistent hashing after receiving a data packet, the mounting duration of the RS can be determined according to the notification time point of the RS of each host and the reception time point of the received data packet. The RS with the mount duration exceeding the preset duration is used as the effective RS. The preset duration is, for example, 10 minutes, 8 minutes, 20 minutes, and the like. The embodiments of the present application are not limited. The preset duration can at least satisfy: the load balancer on the newly added host performs the second load balancing, so that the mapping table of the load balancer saves the mapping relationship between the quintuple and RS of all existing services.
另一种方式中,如图1所示,设置一个查询设备。负载均衡器检测出新增主机,接收到数据包需要执行一致性哈希时,向查询设备发送查询请求,以请求获取所述负载均衡系统包含的各主机的RS的通告时间点。查询设备接收到查询请求后,向负载均衡器发送查询响应,该查询响应携带所述负载均衡系统包含的各主机的RS的通告时间点。之后,负载均衡器根据所述接收时间点和所述各主机的RS的通告时间点,确定所述各主机的RS的挂载时长。In another way, as shown in Figure 1, an inquiry device is provided. The load balancer detects the newly added host, and when it receives a data packet and needs to perform consistent hashing, it sends a query request to the query device to request to obtain the notification time point of the RS of each host included in the load balancing system. After receiving the query request, the query device sends a query response to the load balancer, where the query response carries the notification time point of the RS of each host included in the load balancing system. After that, the load balancer determines the mounting duration of the RS of each host according to the receiving time point and the notification time point of the RS of each host.
示例性的,在负载均衡器上增加query_VIP功能,用于通过查询设备获取负载均衡系统包含的各主机的RS的通告时间点。这样一来,负载均衡器每次执行一致性哈希时,无需与负载均衡系统中的其他负载均衡器交互以获取RS的通告时间点,而是仅通过一次和查询设备交互,即可确定出负载均衡系统包含的各主机的RS的通告时间点,进而确定出各主机的RS的挂载时长。Exemplarily, a query_VIP function is added to the load balancer, which is used to obtain the notification time point of the RS of each host included in the load balancing system through the query device. In this way, each time the load balancer performs consistent hashing, it does not need to interact with other load balancers in the load balancing system to obtain the notification time point of the RS, but only by interacting with the query device once to determine The notification time point of the RS of each host included in the load balancing system is used to determine the mounting duration of the RS of each host.
采用该种方案,通过在负载均衡系统中设置查询设备,在负载均衡器上增加VIP查询功能,实现快速确定出各主机的RS的挂载时长的目的。With this solution, by setting up a query device in the load balancing system and adding a VIP query function to the load balancer, the purpose of quickly determining the RS mount duration of each host is achieved.
可选的,上述实施例中,负载均衡器可灵活的确定出负载均衡系统中是否存在新增主机。Optionally, in the above embodiment, the load balancer can flexibly determine whether a new host exists in the load balancing system.
一种方式中,负载均衡器检测负载均衡系统中主机的数量是否发生变化。当负载均衡系统中主机的数量发生变化时,确定负载均衡系统中存在新增主机。当负载均衡系统中主机的数量未发生变化时,负载均衡器认为负载均衡系统中没有新增主机。In one approach, the load balancer detects whether the number of hosts in the load balancing system has changed. When the number of hosts in the load balancing system changes, it is determined that there are new hosts in the load balancing system. When the number of hosts in the load balancing system has not changed, the load balancer considers that there are no new hosts in the load balancing system.
示例性的,每个负载均衡器实时检测负载均衡系统中RS的数量。一旦RS的数量发生变化,则表示主机的数量发生变化。因此,负载均衡器可以通过检测RS的数量快速确定出负载均衡系统中是否新增或减少主机。Exemplarily, each load balancer detects the number of RSs in the load balancing system in real time. Once the number of RSs changes, it means that the number of hosts changes. Therefore, the load balancer can quickly determine whether to add or reduce hosts in the load balancing system by detecting the number of RSs.
另一种方式中,负载均衡器确定负载均衡系统中是否存在新增主机时,确定负载均衡系统包含的各主机的RS中,是否存在挂载时长未超过预设时长的RS。这是因为一个RS的挂载时长未超过预设时长时,该RS未生效时,无法参与一致性哈希运算。In another manner, when the load balancer determines whether a new host exists in the load balancing system, it determines whether there is an RS whose mounting duration does not exceed the preset duration among the RSs of each host included in the load balancing system. This is because when the mount duration of an RS does not exceed the preset duration, and the RS does not take effect, it cannot participate in the consistent hashing operation.
当负载均衡系统包含的各主机的RS中存在挂载时长未超过预设时长的RS时,确定所述负载均衡系统中存在新增主机,新增主机即为挂载时长未超过预设时长的RS。这时候,一旦负载均衡器接收到数据包需要执行一致性哈希时,则从负载均衡系统包含的所有RS中确定出生效RS,从生效RS中确定出目标RS。When there is an RS whose mounting duration does not exceed the preset duration in the RSs of each host included in the load balancing system, it is determined that a new host exists in the load balancing system, and the newly added host is the one whose mounting duration does not exceed the preset duration. RS. At this time, once the load balancer receives the data packet and needs to perform consistent hashing, the effective RS is determined from all the RSs included in the load balancing system, and the target RS is determined from the effective RSs.
当负载均衡系统包含的各主机的RS中的挂载时长均超过预设时长,负载均衡器认为负载均衡系统中不存在新增主机。这时候,一旦负载均衡器接收到数据包需要执行一致性哈希时,则直接从负载均衡系统包含的所有RS中确定出目标RS。When the mount duration in the RS of each host included in the load balancing system exceeds the preset duration, the load balancer considers that there is no new host in the load balancing system. At this time, once the load balancer receives the data packet and needs to perform consistent hashing, the target RS is directly determined from all RSs included in the load balancing system.
采用该种方案,考虑RS到未生效时无法用于一致性哈希运算,因此,将挂载时长未超过预设时长的RS的主机都视为新增主机,避免后续一致性哈希运算时出错,实现提高已有业务的业务质量的目的。With this solution, considering that RS cannot be used for consistent hashing operations when it is not in effect, the hosts with RSs whose mounting duration does not exceed the preset duration are regarded as newly added hosts to avoid subsequent consistent hashing operations. Error, to achieve the purpose of improving the service quality of existing services.
图4是本申请实施例提供的负载均衡方法的另一个流程图。本实施例是从查询设备的角度说明。本实施例包括:FIG. 4 is another flowchart of the load balancing method provided by the embodiment of the present application. This embodiment is described from the perspective of a query device. This embodiment includes:
401、查询设备接收所述负载均衡系统中新增主机上的RS发送的通告请求,所述通告请求用于指示所述RS的虚拟IP地址VIP。401. The query device receives a notification request sent by an RS on a newly added host in the load balancing system, where the notification request is used to indicate the virtual IP address VIP of the RS.
402、记录所述VIP以及通告时间点,所述通告时间点是所述查询设备接收到所述通告请求的时间点,所述负载均衡系统中的生效RS是所述新增主机之前,所述负载均衡系统中的负载均衡器对已有业务的数据包进行负载均衡时涉及的RS,所述已有业务是新增主机之前所述负载均衡系统正在提供给用户的业务。402. Record the VIP and the notification time point, where the notification time point is the time point when the query device receives the notification request, and the effective RS in the load balancing system is before the newly added host, the The RS involved when the load balancer in the load balancing system performs load balancing on the data packets of the existing service, where the existing service is the service that the load balancing system is providing to the user before the new host is added.
示例性的,每次新增主机时,新增主机上的RS向查询设备发送通告请求,以通过VIP。查询设备接收到通告请求后,记录新增主机的VIP和通告时间点。可以理解的是,新增主机的时间点、新增主机上的RS的初始挂载的时间点即为所述通告时间点,即查询设备接收到通告请求的时间点。Exemplarily, each time a host is added, the RS on the newly added host sends a notification request to the inquiring device to pass the VIP. After the query device receives the notification request, it records the VIP of the newly added host and the notification time point. It can be understood that the time point of the newly added host and the time point of initial mounting of the RS on the newly added host are the notification time point, that is, the time point when the query device receives the notification request.
采用该种方案,通过设置一个查询设备记录各新增主机的VIP和通告时间点,便于负载均衡器从查询设备快速获取到各个RS的挂载时长,进而快速从负载均衡系统所有的RS中确定出生效RS。Using this solution, by setting a query device to record the VIP and notification time point of each new host, it is convenient for the load balancer to quickly obtain the mount time of each RS from the query device, and then quickly determine from all the RSs of the load balancing system. out of the effective RS.
下面,用一个例子对上述的负载均衡方法进行详细说明。示例性的,请参照图5,图5是本申请实施例提供的负载均衡方法的应用场景示意图。Hereinafter, the above load balancing method will be described in detail with an example. For example, please refer to FIG. 5 , which is a schematic diagram of an application scenario of the load balancing method provided by the embodiment of the present application.
请参照图5,新增主机之前,负载均衡系统中有3个主机,分别为主机1、主机2和主机3,主机1上部署负载均衡器1a和RS1b,主机2上部署负载均衡器2a和RS2b,主机3上部署负载均衡器3a和RS3b。18:00整时,新增主机4,主机4上部署负载均衡器4a和RS4b。负载均衡器1a上存储一个映射表,该映射表中存储五元组A和RS2b的对应关系,负载均衡器2a上的映射表存储五元组B和RS1b的对应关系,负载均衡器3a和负载均衡器4a上的映射表的为空。Please refer to Figure 5. Before adding a host, there are 3 hosts in the load balancing system, namely host 1, host 2 and host 3. Load balancers 1a and RS1b are deployed on host 1, and load balancers 2a and 2 are deployed on host 2. RS2b, load balancer 3a and RS3b are deployed on host 3. At 18:00, host 4 is added, and load balancer 4a and RS4b are deployed on host 4. Load balancer 1a stores a mapping table, which stores the correspondence between quintuple A and RS2b, the mapping table on load balancer 2a stores the correspondence between quintuple B and RS1b, load balancer 3a and load The mapping table on the equalizer 4a is empty.
查询设备12上预先设置预设时长为10分钟,即自18:00起,负载均衡器4a的功能开启,但是RS4b的功能未开启,不参与一致性哈希运算。The pre-set duration on the
18:00-18:10这段时间内,交换机13接收到终端设备14的数据包,执行第一次负载均衡。其中,数据包的五元组为五元组A,即数据包是已有业务的数据包。倘若未新增主机4,则交换机13将数据包发送给负载均衡器1a。但是,由于负载均衡器4a开启,交换机13执行第一次负载均衡,很有可能会将原本应该发送给负载均衡器1a的数据包发送给负载均衡器2a、负载均衡器3a或负载均衡器4a。During the period from 18:00 to 18:10, the
无论是发送给哪个负载均衡器,这个负载均衡器均确定出有效RS包括RS1b、RS2b和RS3b。因此,通过执行一致性哈希运算,确定出目标RS为RS2b,之后,将数据包发送给RS2b。Regardless of which load balancer it is sent to, the load balancer determines that valid RSs include RS1b, RS2b, and RS3b. Therefore, by performing a consistent hash operation, it is determined that the target RS is RS2b, and then the data packet is sent to RS2b.
同理,当数据包的五元组为五元组B、第一次负载均衡应该发送给负载均衡器器2a时,交换机很有可能将该数据包发送给负载均衡器1a、负载均衡器3a或负载均衡器4a,处理方式同上,此处不再赘述。Similarly, when the quintuple of the data packet is quintuple B and the first load balancing should be sent to load balancer 2a, the switch is likely to send the packet to load balancer 1a and load balancer 3a Or the load balancer 4a, the processing method is the same as above, and details are not repeated here.
18:00-18:10这段时间内,负载均衡器4a能够建立存储所有已有业务的五元组与RS映射关系的映射表。During the period from 18:00 to 18:10, the load balancer 4a can establish a mapping table that stores the mapping relationship between the quintuple and the RS of all existing services.
18:10之后,交换机接收到已有业务的数据包后,对于交换机而言,并没有新增负载均衡器(因为新增的负载均衡器在18:00时已开启),因此,交换机不会将数据包分错。数据包到达负载均衡器后,由于存在新增的RS(新增RS在18:10之后开启),导致一致性哈希运算的结果变化。但是,由于18:10之后,每个负载均衡器,包括18:00时新增的负载均衡器,均已存储所有已有业务的五元组与RS映射关系的映射表,因此,优先查询映射表。若映射表中存在数据包的五元组,则说明是已有业务的数据包,直接将五元组对应的RS作为目标RS。若映射表中不存在数据包的五元组,则说明该数据包是新业务的数据包,负载均衡器(负载均衡器1a、负载均衡器2a、负载均衡器3a或负载均衡器4a)确定出有效RS包括RS1b、RS2b、RS3b和RS4b,根据新业务的数据包的五元组和有效RS的VIP、数量等执行一致性哈希运算,从而确定出目标RS,该目标RS可能是RS1b、RS2b、RS3b或RS4b。之后,负载均衡器在本地映射表中添加新业务的数据包的五元组和目标RS的映射关系。After 18:10, after the switch receives the data packet of the existing service, for the switch, there is no new load balancer (because the newly added load balancer is turned on at 18:00), so the switch will not Misclassify packets. After the data packet arrives at the load balancer, the result of the consistent hash operation changes due to the presence of the newly added RS (the new RS will be opened after 18:10). However, after 18:10, each load balancer, including the newly added load balancer at 18:00, has stored the mapping table of the mapping relationship between the quintuple and RS of all existing services. Therefore, the mapping table should be queried first. surface. If there is a quintuple of data packets in the mapping table, it means that it is a data packet of an existing service, and the RS corresponding to the quintuple is directly used as the target RS. If there is no quintuple of the data packet in the mapping table, it means that the data packet is a data packet of a new service, and the load balancer (load balancer 1a, load balancer 2a, load balancer 3a or load balancer 4a) determines The valid RS includes RS1b, RS2b, RS3b and RS4b, and a consistent hash operation is performed according to the quintuple of the data packet of the new service and the VIP, quantity, etc. of the valid RS, so as to determine the target RS, which may be RS1b, RS2b, RS3b or RS4b. After that, the load balancer adds the mapping relationship between the five-tuple of the data packet of the new service and the target RS in the local mapping table.
下述为本申请装置实施例,可以用于执行本申请方法实施例。对于本申请装置实施例中未披露的细节,请参照本申请方法实施例。The following are apparatus embodiments of the present application, which can be used to execute the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
图6为本申请实施例提供的一种负载均衡装置的示意图。该负载均衡装置600包括:确定模块61、接收模块62、处理模块63和发送模块64。FIG. 6 is a schematic diagram of a load balancing apparatus provided by an embodiment of the present application. The load balancing apparatus 600 includes: a determining
确定模块61,用于确定负载均衡系统中存在新增主机,所述负载均衡器是所述负载均衡系统包含的多个主机中的任意一个主机上的负载均衡器,所述多个主机中的每个主机上均部署负载均衡器和真实服务器RS;The determining
接收模块62,用于接收数据包;a receiving
处理模块63,用于从所述负载均衡系统包含的各主机的RS中确定出生效RS,所述生效RS是新增主机之前所述负载均衡器对已有业务的数据包进行负载均衡时涉及的RS,所述已有业务是新增主机之前所述负载均衡系统正在提供给用户的业务,从所述生效RS中确定出目标RS;The
发送模块64,用于向所述目标RS发送所述数据包。A sending
一种可行的实现方式中,所述处理模块63从所述负载均衡系统包含的各主机的RS中确定出生效RS时,用于确定所述各主机的RS的挂载时长,将挂载时长超过预设时长的RS作为生效RS,所述挂载时长指通告时间点和接收时间点之间的时长,所述通告时间点是所述主机的RS向查询设备通告虚拟IP地址VIP的时间点,所述接收时间点是所述负载均衡器接收到所述数据包的时间点。In a feasible implementation manner, when the
一种可行的实现方式中,所述发送模块64,还用于向查询设备发送查询请求,以请求获取所述负载均衡系统包含的各主机的RS的通告时间点;In a feasible implementation manner, the sending
所述接收模块62,还用于接收来自所述查询设备的查询响应,所述查询响应携带所述负载均衡系统包含的各主机的RS的通告时间点;The receiving
所述处理模块63,用于根据所述接收时间点和所述各主机的RS的通告时间点,确定所述各主机的RS的挂载时长。The
一种可行的实现方式中,所述确定模块61,用于确定所述负载均衡系统包含的各主机的RS中,是否存在挂载时长未超过预设时长的RS;当负载均衡系统包含的各主机的RS中存在挂载时长未超过预设时长的RS时,确定所述负载均衡系统中存在新增主机。In a feasible implementation manner, the determining
一种可行的实现方式中,所述确定模块61,用于检测所述负载均衡系统中RS的数量是否发生变化;当所述负载均衡系统中RS的数量发生变化时,确定所述负载均衡系统中存在新增主机。In a feasible implementation manner, the determining
一种可行的实现方式中,所述处理模块63从所述负载均衡系统包含的各主机的RS中确定出生效RS时,用于根据所述数据包的五元组查询映射表,所述映射表中存储五元组与RS的对应关系;当所述映射表中不存在所述数据包的五元组时,从所述负载均衡系统包含的各主机的RS中确定出生效RS。In a feasible implementation manner, when the
一种可行的实现方式中,所述处理模块63从所述生效RS中确定出目标RS之后,还用于在所述映射表中新增所述数据包的五元组和所述目标RS的映射关系。In a feasible implementation manner, after the
一种可行的实现方式中,所述处理模块63从所述生效RS中确定出目标RS时,用于根据所述数据包的五元组、各所述生效RS的VIP、所述生效RS的数量执行一致性哈希以确定出所述目标RS。In a feasible implementation manner, when the
本申请实施例提供的负载均衡装置,可以执行上述实施例中负载均衡器的动作,其实现原理和技术效果类似,在此不再赘述。The load balancing apparatus provided in the embodiment of the present application can perform the action of the load balancer in the foregoing embodiment, and the implementation principle and technical effect thereof are similar, and are not repeated here.
图7为本申请实施例提供的另一种负载均衡装置的示意图。该负载均衡装置700包括:收发模块71和处理模块72。FIG. 7 is a schematic diagram of another load balancing apparatus provided by an embodiment of the present application. The load balancing apparatus 700 includes: a
收发模块71,用于接收所述负载均衡系统中新增主机上的RS发送的通告请求,所述通告请求用于指示所述RS的虚拟IP地址VIP;A
处理模块72,用于记录所述VIP以及通告时间点,所述通告时间点是所述查询设备接收到所述通告请求的时间点,所述VIP和所述通告时间点用于确定所述新增主机上的RS是否转变为生效RS,所述负载均衡系统中的生效RS是所述负载均衡系统中的负载均衡器对已有业务的数据包进行负载均衡时涉及的RS,所述已有业务是新增主机之前所述负载均衡系统正在提供给用户的业务。The
一种可行的实现方式中,所述收发模块71,还用于接收来自负载均衡器的查询请求,所述负载均衡器是所述负载均衡系统包含的各主机的负载均衡器中接收到数据包的负载均衡器;向所述负载均衡器发送查询响应,所述查询响应携带所述负载均衡系统包含的各主机的RS的通告时间点。In a feasible implementation manner, the
本申请实施例提供的负载均衡装置,可以执行上述实施例中查询设备的动作,其实现原理和技术效果类似,在此不再赘述。The load balancing apparatus provided in the embodiment of the present application can perform the action of querying the device in the foregoing embodiment, and the implementation principle and technical effect thereof are similar, and are not repeated here.
图8为本申请实施例提供的一种电子设备的结构示意图。如图8所示,该电子设备800例如为上述的查询设备或主机,该电子设备800包括:FIG. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present application. As shown in FIG. 8 , the electronic device 800 is, for example, the above-mentioned query device or host, and the electronic device 800 includes:
处理器81和存储器82;
所述存储器82存储计算机指令;the memory 82 stores computer instructions;
所述处理器81执行所述存储器82存储的计算机指令,使得所述处理器81执行如上主机中的负载均衡器实施的负载均衡方法;或者,使得所述处理器81执行如上查询设备实施的负载均衡方法。The
处理器81的具体实现过程可参见上述方法实施例,其实现原理和技术效果类似,本实施例此处不再赘述。For the specific implementation process of the
可选地,该电子设备800还包括通信部件83。其中,处理器81、存储器82以及通信部件83可以通过总线84连接。Optionally, the electronic device 800 further includes a
本申请实施例还提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机指令,所述计算机指令被处理器执行时用于实现如上主机中的负载均衡器实施的负载均衡方法;或者,实现如上查询设备实施的负载均衡方法。Embodiments of the present application further provide a computer-readable storage medium, where computer instructions are stored in the computer-readable storage medium, and when the computer instructions are executed by a processor, are used to implement the load balancing implemented by the load balancer in the host as above method; or, implement the load balancing method implemented by the query device as above.
本申请实施例还提供一种计算机程序产品,该计算机程序产品包含计算机程序,计算机程序被处理器执行时实现如上主机中的负载均衡器实施的负载均衡方法;或者,实现如上查询设备实施的负载均衡方法。Embodiments of the present application further provide a computer program product, the computer program product includes a computer program, and when the computer program is executed by the processor, implements the load balancing method implemented by the load balancer in the host as above; or, implements the load balancing method implemented by the above query device Balance method.
本领域技术人员在考虑说明书及实践这里公开的发明后,将容易想到本申请的其它实施方案。本申请旨在涵盖本申请的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本申请的一般性原理并包括本申请未公开的本技术领域中的公知常识或惯用技术手段。说明书和实施例仅被视为示例性的,本申请的真正范围和精神由下面的权利要求书指出。Other embodiments of the present application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses or adaptations of this application that follow the general principles of this application and include common knowledge or conventional techniques in the technical field not disclosed in this application . The specification and examples are to be regarded as exemplary only, with the true scope and spirit of the application being indicated by the following claims.
应当理解的是,本申请并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本申请的范围仅由所附的权利要求书来限制。It is to be understood that the present application is not limited to the precise structures described above and illustrated in the accompanying drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.
Claims (13)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210555137.8A CN114928615B (en) | 2022-05-19 | 2022-05-19 | Load balancing method, device, equipment and readable storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202210555137.8A CN114928615B (en) | 2022-05-19 | 2022-05-19 | Load balancing method, device, equipment and readable storage medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN114928615A true CN114928615A (en) | 2022-08-19 |
| CN114928615B CN114928615B (en) | 2023-10-24 |
Family
ID=82811225
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202210555137.8A Expired - Fee Related CN114928615B (en) | 2022-05-19 | 2022-05-19 | Load balancing method, device, equipment and readable storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN114928615B (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20220116448A1 (en) * | 2017-07-03 | 2022-04-14 | Pure Storage, Inc. | Load Balancing Reset Packets |
Citations (15)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20040260745A1 (en) * | 2003-06-18 | 2004-12-23 | Gage Christopher A. S. | Load balancer performance using affinity modification |
| US20070233851A1 (en) * | 2006-03-31 | 2007-10-04 | Cisco Technology, Inc. | System and method for handling persistence information in a network |
| CN201518488U (en) * | 2008-04-15 | 2010-06-30 | 丛林网络公司 | Server load equalizer and system thereof |
| US20120155266A1 (en) * | 2010-12-17 | 2012-06-21 | Microsoft Corporation | Synchronizing state among load balancer components |
| CN104184819A (en) * | 2014-08-29 | 2014-12-03 | 城云科技(杭州)有限公司 | Multi-hierarchy load balancing cloud resource monitoring method |
| US9055076B1 (en) * | 2011-06-23 | 2015-06-09 | Amazon Technologies, Inc. | System and method for distributed load balancing with load balancer clients for hosts |
| CN106095532A (en) * | 2016-06-12 | 2016-11-09 | 北京大学 | A kind of virtual machine load balancing sacurity dispatching method in cloud environment |
| US9807016B1 (en) * | 2015-09-29 | 2017-10-31 | Juniper Networks, Inc. | Reducing service disruption using multiple virtual IP addresses for a service load balancer |
| CN108768878A (en) * | 2018-06-06 | 2018-11-06 | 北京奇艺世纪科技有限公司 | A kind of SiteServer LBS, method, apparatus and load-balancing device |
| CN109842651A (en) * | 2017-11-27 | 2019-06-04 | 中国移动通信集团上海有限公司 | A kind of continual load-balancing method of business and system |
| US20190364103A1 (en) * | 2018-08-20 | 2019-11-28 | Beijing Baidu Netcom Science And Technology Co., Ltd. | Method and device for load balancing, and storage medium |
| CN110708393A (en) * | 2019-10-21 | 2020-01-17 | 北京百度网讯科技有限公司 | Method, device and system for transmitting data |
| CN111327647A (en) * | 2018-12-13 | 2020-06-23 | 北京金山云网络技术有限公司 | A method, device and electronic device for a container to provide external services |
| US20220030060A1 (en) * | 2020-07-24 | 2022-01-27 | Vmware, Inc. | Policy-based forwarding to a load balancer of a load balancing cluster |
| CN114500545A (en) * | 2022-01-24 | 2022-05-13 | 杭州博盾习言科技有限公司 | Network load balancing method and device suitable for container and electronic equipment |
-
2022
- 2022-05-19 CN CN202210555137.8A patent/CN114928615B/en not_active Expired - Fee Related
Patent Citations (16)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20040260745A1 (en) * | 2003-06-18 | 2004-12-23 | Gage Christopher A. S. | Load balancer performance using affinity modification |
| US20070233851A1 (en) * | 2006-03-31 | 2007-10-04 | Cisco Technology, Inc. | System and method for handling persistence information in a network |
| CN201518488U (en) * | 2008-04-15 | 2010-06-30 | 丛林网络公司 | Server load equalizer and system thereof |
| US20120155266A1 (en) * | 2010-12-17 | 2012-06-21 | Microsoft Corporation | Synchronizing state among load balancer components |
| US9055076B1 (en) * | 2011-06-23 | 2015-06-09 | Amazon Technologies, Inc. | System and method for distributed load balancing with load balancer clients for hosts |
| CN104184819A (en) * | 2014-08-29 | 2014-12-03 | 城云科技(杭州)有限公司 | Multi-hierarchy load balancing cloud resource monitoring method |
| US9807016B1 (en) * | 2015-09-29 | 2017-10-31 | Juniper Networks, Inc. | Reducing service disruption using multiple virtual IP addresses for a service load balancer |
| CN106095532A (en) * | 2016-06-12 | 2016-11-09 | 北京大学 | A kind of virtual machine load balancing sacurity dispatching method in cloud environment |
| CN109842651A (en) * | 2017-11-27 | 2019-06-04 | 中国移动通信集团上海有限公司 | A kind of continual load-balancing method of business and system |
| CN108768878A (en) * | 2018-06-06 | 2018-11-06 | 北京奇艺世纪科技有限公司 | A kind of SiteServer LBS, method, apparatus and load-balancing device |
| US20190364103A1 (en) * | 2018-08-20 | 2019-11-28 | Beijing Baidu Netcom Science And Technology Co., Ltd. | Method and device for load balancing, and storage medium |
| CN111327647A (en) * | 2018-12-13 | 2020-06-23 | 北京金山云网络技术有限公司 | A method, device and electronic device for a container to provide external services |
| CN110708393A (en) * | 2019-10-21 | 2020-01-17 | 北京百度网讯科技有限公司 | Method, device and system for transmitting data |
| US20210120076A1 (en) * | 2019-10-21 | 2021-04-22 | Beijing Baidu Netcom Science And Technology Co., Ltd. | Method, apparatus and system for transmitting data |
| US20220030060A1 (en) * | 2020-07-24 | 2022-01-27 | Vmware, Inc. | Policy-based forwarding to a load balancer of a load balancing cluster |
| CN114500545A (en) * | 2022-01-24 | 2022-05-13 | 杭州博盾习言科技有限公司 | Network load balancing method and device suitable for container and electronic equipment |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20220116448A1 (en) * | 2017-07-03 | 2022-04-14 | Pure Storage, Inc. | Load Balancing Reset Packets |
| US11689610B2 (en) * | 2017-07-03 | 2023-06-27 | Pure Storage, Inc. | Load balancing reset packets |
Also Published As
| Publication number | Publication date |
|---|---|
| CN114928615B (en) | 2023-10-24 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US9736278B1 (en) | Method and apparatus for connecting a gateway router to a set of scalable virtual IP network appliances in overlay networks | |
| Araújo et al. | Balancing on the edge: Transport affinity without network state | |
| CN109802985B (en) | Data transmission method, device, equipment and readable storage medium | |
| US10534601B1 (en) | In-service software upgrade of virtual router with reduced packet loss | |
| JP7623432B2 (en) | Congestion Avoidance in Slice-Based Networks | |
| Patel et al. | Ananta: Cloud scale load balancing | |
| US9037712B2 (en) | Systems and methods for self-loading balancing access gateways | |
| US20150189009A1 (en) | Distributed multi-level stateless load balancing | |
| US10313247B2 (en) | System, method, and device for network load balance processing | |
| US8706864B1 (en) | Behavior monitoring and compliance for multi-tenant resources | |
| US10225194B2 (en) | Transparent network-services elastic scale-out | |
| CN116137582B (en) | CUPS BNG-based packet forwarding system, method and non-transitory computer readable storage medium | |
| CN103201989B (en) | The methods, devices and systems of control data transmission | |
| US20150200808A1 (en) | Method and system for virtual machine aware policy management | |
| US20130159487A1 (en) | Migration of Virtual IP Addresses in a Failover Cluster | |
| US11418582B1 (en) | Priority-based transport connection control | |
| US11997024B2 (en) | Mapping NVMe-over-fabric packets using virtual output queues | |
| CN102404229A (en) | Load balancing system, device and method | |
| US20190253321A1 (en) | Network aware dynamic orchestration method and system for multicast services | |
| CN113726636B (en) | Data forwarding method and system of software forwarding device and electronic device | |
| Aghdai et al. | In-network congestion-aware load balancing at transport layer | |
| US11811685B1 (en) | Selective packet processing including a run-to-completion packet processing data plane | |
| CN114928615B (en) | Load balancing method, device, equipment and readable storage medium | |
| US8209421B2 (en) | Computer telephony system | |
| US20240348544A1 (en) | Communication Method and Apparatus, and Communication System |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant | ||
| CF01 | Termination of patent right due to non-payment of annual fee | ||
| CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20231024 |