CN104104611A - Method and device for achieving cluster load balancing dispatching - Google Patents
Method and device for achieving cluster load balancing dispatching Download PDFInfo
- Publication number
- CN104104611A CN104104611A CN201410327814.6A CN201410327814A CN104104611A CN 104104611 A CN104104611 A CN 104104611A CN 201410327814 A CN201410327814 A CN 201410327814A CN 104104611 A CN104104611 A CN 104104611A
- Authority
- CN
- China
- Prior art keywords
- server
- hash
- level
- module
- scheduling
- 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
Landscapes
- Computer And Data Communications (AREA)
Abstract
本发明公开了一种实现集群负载均衡调度的方法及装置,包括:计算集群收到请求包时,设定散列hash层级为0;根据请求包及hash层级,确定hash层级对应的服务器;判断获得的服务器是否满足调度条件,当服务器满足调度条件时,则将请求分发到所述服务器;当服务器不满足调度条件时,则hash层级增加1,继续确定hash层级对应的服务器,当hash层级超过最大值,则拒绝请求;其中,hash层级的取值范围为[0,N-1],N为服务器的总个数。本申请的技术方案降低了拒绝请求的概率,极大地提高集群资源的利用率。
The invention discloses a method and device for realizing cluster load balancing scheduling, comprising: when the computing cluster receives a request packet, setting the hash level to 0; according to the request packet and the hash level, determining the server corresponding to the hash level; judging Whether the obtained server meets the scheduling conditions. When the server meets the scheduling conditions, the request will be distributed to the server; when the server does not meet the scheduling conditions, the hash level will increase by 1, and continue to determine the server corresponding to the hash level. If the maximum value is set, the request is rejected; the value range of the hash level is [0, N-1], and N is the total number of servers. The technical solution of the present application reduces the probability of rejecting requests and greatly improves the utilization rate of cluster resources.
Description
技术领域technical field
本发明涉及计算机集群领域,尤指一种实现集群负载均衡调度的方法及装置。The invention relates to the field of computer clusters, in particular to a method and device for realizing cluster load balance scheduling.
背景技术Background technique
在集群计算中经常使用各种负载均衡方法,解决系统的可伸缩性和透明性问题,即通过负载均衡调度器将请求高效地分发到不同的服务器执行,使得由多台独立计算机组成的集群系统成为一台虚拟服务器;客户端应用程序与集群系统交互时,就像与一台高性能的服务器交互一样。Various load balancing methods are often used in cluster computing to solve the scalability and transparency problems of the system, that is, the load balancing scheduler efficiently distributes requests to different servers for execution, making a cluster system composed of multiple independent computers Become a virtual server; client applications interact with the cluster system as if interacting with a high-performance server.
目前,常见的负载均衡调度方法有轮叫调度、加权轮叫调度、最小连接调度、加权最小连接调度、基于局部性的最少链接、带复制的基于局部性最少链接、目标地址散列调度、源地址散列调度等,其中目标地址散列调度和源地址散列调度是比较常见的静态调度方法,在实际应用中,结合这两种调度方法使用在防火墙集群中,从而保证整个系统有唯一的出入口。At present, common load balancing scheduling methods include round-robin scheduling, weighted round-robin scheduling, minimum connection scheduling, weighted minimum connection scheduling, locality-based least connection, locality-based least connection with replication, target address hash scheduling, source Address hash scheduling, etc. Among them, destination address hash scheduling and source address hash scheduling are relatively common static scheduling methods. In practical applications, these two scheduling methods are used in firewall clusters to ensure that the entire system has a unique entrance and exit.
源地址散列调度算法的基本原理是:根据请求的源IP地址,作为散列键从静态分配的散列表中找出对应的服务器。此算法可以快速有效调度服务器,同时又能保证相同地址的请求给调度相同的服务器。但是,这种方法的问题是,如果一个源地址所hash到的服务器已超载,则返回空,即拒绝处理后续的请求,所以当单个服务器负载较大时会使得hash到该服务器的频繁请求无法得到处理,这就降低了集群资源的利用率。The basic principle of the source address hash scheduling algorithm is to find out the corresponding server from the statically allocated hash table according to the source IP address of the request as a hash key. This algorithm can quickly and efficiently schedule servers, and at the same time, it can ensure that requests with the same address are scheduled to the same server. However, the problem with this method is that if the server hashed by a source address is overloaded, it will return empty, that is, it will refuse to process subsequent requests, so when a single server is heavily loaded, frequent requests to the server cannot be hashed. be processed, which reduces the utilization of cluster resources.
发明内容Contents of the invention
为了解决上述技术问题,本发明提供了一种实现集群负载均衡调度的方法及装置,可以大大减少拒绝请求的概率,极大地提高集群资源的利用率。In order to solve the above technical problems, the present invention provides a method and device for implementing cluster load balancing scheduling, which can greatly reduce the probability of rejecting requests and greatly improve the utilization rate of cluster resources.
为了达到上述发明目的,本发明公开了一种实现集群负载均衡调度的方法,包括:In order to achieve the purpose of the above invention, the present invention discloses a method for realizing cluster load balancing scheduling, including:
计算集群收到请求包时,设定散列hash层级为0;When the computing cluster receives the request packet, set the hash level to 0;
根据请求包及hash层级,确定hash层级对应的服务器;According to the request package and the hash level, determine the server corresponding to the hash level;
判断获得的服务器是否满足调度条件,当服务器满足调度条件时,则将请求分发到所述服务器;当服务器不满足调度条件时,则hash层级增加1,继续确定hash层级对应的服务器,当hash层级超过最大值,则拒绝请求;Determine whether the obtained server meets the scheduling conditions. When the server meets the scheduling conditions, distribute the request to the server; If the maximum value is exceeded, the request is rejected;
其中,hash层级的取值范围为[0,N-1],N为服务器的总个数。Wherein, the value range of the hash level is [0, N-1], and N is the total number of servers.
进一步地,在计算集群收到请求包时,设定hash层级为0之前,上述述方法还包括:建立用于存储计算集群中的各个服务器信息与索引值的一一对应关系的ServerNode表。Further, before the hash level is set to 0 when the computing cluster receives the request packet, the above method further includes: establishing a ServerNode table for storing the one-to-one correspondence between each server information and the index value in the computing cluster.
进一步地,请求包包括:外部用户的IP地址。Further, the request packet includes: the IP address of the external user.
进一步地,确定hash层级对应的服务器,包括:Further, determine the server corresponding to the hash level, including:
通过下面的公式得到服务器的索引值:The index value of the server is obtained by the following formula:
(ip_addr*2654435761UL)%(N—hash层级);其中,ip_addr是对应于IP地址的整数,%是取模运算。(ip_addr*2654435761UL)% (N—hash level); wherein, ip_addr is an integer corresponding to the IP address, and % is a modulo operation.
根据服务器的索引值,在ServerNode表中找到hash层级对应的服务器。According to the index value of the server, find the server corresponding to the hash level in the ServerNode table.
进一步地,调度条件为:服务器存活、权值不为0且服务器的连接数小于2倍的权值。Further, the scheduling condition is: the server is alive, the weight is not 0, and the number of connections of the server is less than twice the weight.
本发明还公开了一种实现集群负载均衡调度的装置,包括:设置模块、映射模块、判断模块和分发模块;其中,The invention also discloses a device for realizing cluster load balance scheduling, including: a setting module, a mapping module, a judging module and a distribution module; wherein,
设置模块,用于当外部用户向计算集群发送请求包时,设定散列hash层级为0;The setting module is used to set the hash level to 0 when an external user sends a request packet to the computing cluster;
映射模块,与设置模块相连,用于根据请求包及hash层级,确定hash层级对应的服务器;The mapping module is connected with the setting module, and is used to determine the server corresponding to the hash level according to the request packet and the hash level;
判断模块,用于判断获得的服务器是否满足调度条件;A judging module, configured to judge whether the obtained server satisfies the scheduling condition;
分发模块,用于当服务器满足调度条件时,则将请求分发到该服务器;The distribution module is used for distributing the request to the server when the server meets the scheduling condition;
所述映射模块,还用于当服务器不满足调度条件时,则hash层级增加1,继续确定hash层级对应的服务器,当hash层级超过最大值,则拒绝请求;The mapping module is also used to increase the hash level by 1 when the server does not meet the scheduling conditions, continue to determine the server corresponding to the hash level, and reject the request when the hash level exceeds the maximum value;
其中,hash层级的取值范围为[0,N-1],N为服务器的总个数。Wherein, the value range of the hash level is [0, N-1], and N is the total number of servers.
进一步地,上述装置还包括存储模块,与设置模块相连,用于:在计算集群收到请求包时,设定hash层级为0之前,建立用于存储计算集群中的各个服务器信息与索引值的一一对应关系的ServerNode表。Further, the above-mentioned device also includes a storage module, which is connected to the setting module, and is used for: when the computing cluster receives the request packet, before setting the hash level to 0, establish a server information and index value for storing each server in the computing cluster ServerNode table of one-to-one correspondence.
进一步地,请求包包括:外部用户的IP地址。Further, the request packet includes: the IP address of the external user.
进一步地,映射模块具体用于:Further, the mapping module is specifically used for:
通过下面的公式得到所述服务器的索引值:The index value of the server is obtained by the following formula:
(ip_addr*2654435761UL)%(N—hash层级);其中,ip_addr是对应于所述IP地址的整数,%是取模运算。(ip_addr*2654435761UL)%(N—hash level); wherein, ip_addr is an integer corresponding to the IP address, and % is a modulo operation.
根据所述服务器的索引值,在ServerNode表中找到所述hash层级对应的服务器。Find the server corresponding to the hash level in the ServerNode table according to the index value of the server.
进一步地,调度条件为:服务器存活、权值不为0且服务器的连接数小于2倍的权值。Further, the scheduling condition is: the server is alive, the weight is not 0, and the number of connections of the server is less than twice the weight.
本申请技术方案包括:当外部用户向计算集群发送请求包时,设定散列hash层级为0;根据请求包及hash层级,确定hash层级对应的服务器;判断获得的服务器是否满足调度条件,当服务器满足调度条件时,则将请求分发到所述服务器;当服务器不满足调度条件时,则hash层级增加1,继续确定hash层级对应的服务器,当hash层级超过最大值,则拒绝请求;其中,hash层级的取值范围为[0,N-1],N为服务器的总个数。本申请的技术方案降低了拒绝请求的概率,极大地提高了集群资源的利用率。The technical solution of the present application includes: when an external user sends a request packet to the computing cluster, set the hash level to 0; determine the server corresponding to the hash level according to the request packet and the hash level; determine whether the obtained server meets the scheduling conditions, and when When the server meets the scheduling conditions, the request is distributed to the server; when the server does not meet the scheduling conditions, the hash level is increased by 1, and the server corresponding to the hash level is continued to be determined. When the hash level exceeds the maximum value, the request is rejected; wherein, The value range of the hash level is [0, N-1], and N is the total number of servers. The technical solution of the present application reduces the probability of rejecting requests and greatly improves the utilization rate of cluster resources.
附图说明Description of drawings
此处所说明的附图用来提供对本发明的进一步理解,构成本申请的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:The accompanying drawings described here are used to provide a further understanding of the present invention and constitute a part of the application. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations to the present invention. In the attached picture:
图1为本发明实现集群负载均衡调度的方法的流程图;Fig. 1 is the flow chart of the method for realizing cluster load balance scheduling of the present invention;
图2为本发明实现集群负载均衡调度的方法的实施例的流程图;Fig. 2 is the flow chart of the embodiment of the method for realizing cluster load balance scheduling of the present invention;
图3为本发明实现集群负载均衡调度的装置的结构示意图。FIG. 3 is a schematic structural diagram of a device for implementing cluster load balancing scheduling according to the present invention.
具体实施方式Detailed ways
本发明对已有的源地址散列散列调度算法进行了改进,引入层级参数hash层级(level),用于指定hash层级。当level为0时就是源地址散列调度所使用的hash函数,如果level=0时找不到满足要求服务器则增加一个level级别继续找,如此瀑布式增加level直到找到满足要求的服务器,该方法只有当level达到服务器数量N时才会宣布找不到满足要求的服务器,而level达到N值时,表明已经遍历了所有服务器,即所有服务器都是不满足要求的服务器。The invention improves the existing source address hash scheduling algorithm, and introduces a level parameter hash level (level) for specifying the hash level. When the level is 0, it is the hash function used by the source address hash scheduling. If no server meeting the requirements is found when level=0, then add a level to continue searching, and increase the level in a waterfall manner until a server meeting the requirements is found. This method Only when the level reaches the number of servers N will it announce that no server that meets the requirements can be found, and when the level reaches the N value, it indicates that all servers have been traversed, that is, all servers are servers that do not meet the requirements.
下面结合附图及具体实施例对本发明进行详细说明。The present invention will be described in detail below in conjunction with the accompanying drawings and specific embodiments.
图1为本发明实现集群负载均衡调度的方法的流程图,如图1所示,包括:Fig. 1 is the flow chart of the method for realizing cluster load balancing scheduling of the present invention, as shown in Fig. 1, comprising:
步骤101,计算集群收到请求包时,设定散列hash层级为0。Step 101, when the computing cluster receives the request packet, set the hash level to 0.
本步骤中的请求包来自外部网络某个用户向计算集群发送的,请求包中包括源地址IP即外部用户使用的IP地址。The request packet in this step is sent from a user on the external network to the computing cluster, and the request packet includes the source address IP, which is the IP address used by the external user.
在本步骤之前,本发明方法还包括:建立用于存储所述计算集群中的各个服务器信息与索引值的一一对应关系的ServerNode表。Before this step, the method of the present invention further includes: establishing a ServerNode table for storing a one-to-one correspondence between each server information and an index value in the computing cluster.
其中服务器信息包括:服务器的IP,名称,内存,硬盘。关于如何建立ServerNode表属于本领域技术人员熟知的公知常识,在此不再赘述。The server information includes: server IP, name, memory, hard disk. How to establish the ServerNode table belongs to the common knowledge well known by those skilled in the art, and details are not repeated here.
需要说明的是,ServerNode表包含了所有服务器及其信息,且ServerNode表中的每一个索引值都与ServerNode表中一个服务器对应,即找到索引值,就可以获得与之对应的服务器以及该服务器的信息。It should be noted that the ServerNode table contains all servers and their information, and each index value in the ServerNode table corresponds to a server in the ServerNode table, that is, if you find the index value, you can obtain the corresponding server and the server's information.
上述请求包包括:外部用户的IP地址。The above request packet includes: the IP address of the external user.
步骤102,根据请求包及hash层级,确定hash层级对应的服务器。Step 102, according to the request packet and the hash level, determine the server corresponding to the hash level.
具体包括:Specifically include:
首先,通过下面的公式得到hash层级对应的服务器的索引值:First, get the index value of the server corresponding to the hash level through the following formula:
(ip_addr*2654435761UL)%(N—hash层级);其中,ip_addr是对应于所述IP地址的整数,%是取模运算。(ip_addr*2654435761UL)%(N—hash level); wherein, ip_addr is an integer corresponding to the IP address, and % is a modulo operation.
其次,根据该服务器的索引值,在ServerNode表中找到该hash层级对应的服务器。Secondly, according to the index value of the server, find the server corresponding to the hash level in the ServerNode table.
需要说明的是,通过上述公式找到服务器的索引值,类似于现有技术中素数乘法hash函数,不同之处,也是本发明的核心所在:第一个不同是,hash掩码,即N—hash层级,不是固定的,而是根据hash层级变化;第二个不同是,获取hash层级对应的服务器索引值不是用与运算而是用取模运算,使得运算更加的简便,这就大大节省了运算时间。另外,2654435761UL是一个全局固定的值,是2到2^32(4294967296)间接近于黄金分割的素数,2654435761/4294967296=0.618033987,这样保证了不同的源地址会尽量分配到不同的服务器中。It should be noted that finding the index value of the server through the above formula is similar to the hash function of prime number multiplication in the prior art. The difference is also the core of the present invention: the first difference is that the hash mask, that is, N-hash The level is not fixed, but changes according to the hash level; the second difference is that the server index value corresponding to the hash level is not obtained by AND operation but by modulo operation, which makes the operation more convenient and greatly saves calculation time. In addition, 2654435761UL is a globally fixed value, which is a prime number close to the golden section between 2 and 2^32 (4294967296), 2654435761/4294967296=0.618033987, which ensures that different source addresses will be allocated to different servers as much as possible.
可以通过以下方法得到对应的ip_addr:不足三位的域加0补足三位。The corresponding ip_addr can be obtained by the following method: field less than three digits plus 0 to make up three digits.
举例说明,当IP地址为192.168.0.1时,因为前两个域均为三位,所以只需补足后两个域即可,即第三个域补充两个0变成000,第四个域补充两个0变成001,上述IP地址转化后得到ip_addr=192168000001。如共1000台服务器即N=1000,IP地址为192.168.0.1时,ip_addr=192168000001,当hash层级=0时,N—hash层级=1000–0=1000,则(ip_addr*2654435761UL)%(N—hash层级)=192168000001*2654435761%1000=761,即hash到第761台服务器,当hash层级为1时,N—hash层级=1000–1=999,则(ip_addr*2654435761UL)%(N—hash层级)=192168000001*2654435761%999=763,即hash到第763台服务器。For example, when the IP address is 192.168.0.1, because the first two fields are three digits, it is only necessary to fill in the last two fields, that is, add two 0s to the third field to become 000, and the fourth field Two 0s are added to become 001, and the above IP address is converted to ip_addr=192168000001. If there are 1000 servers in total, N=1000, and the IP address is 192.168.0.1, ip_addr=192168000001, when the hash level=0, N—hash level=1000–0=1000, then (ip_addr*2654435761UL)%(N— hash level)=192168000001*2654435761%1000=761, that is, hash to the 761st server, when the hash level is 1, N—hash level=1000–1=999, then (ip_addr*2654435761UL)%(N—hash level )=192168000001*2654435761%999=763, that is, hash to the 763rd server.
步骤103,判断获得的服务器是否满足调度条件,当服务器满足调度条件时,则将请求分发到所述服务器;当服务器不满足调度条件时,则hash层级增加1,返回步骤102,当hash层级超过最大值,则拒绝请求。Step 103, judging whether the obtained server meets the scheduling condition, when the server meets the scheduling condition, then distribute the request to the server; when the server does not meet the scheduling condition, then the hash level increases by 1, and returns to step 102, when the hash level exceeds maximum value, the request is rejected.
本步骤中,调度条件为:服务器存活、权值不为0且服务器的连接数小于2倍的权值。In this step, the scheduling condition is: the server is alive, the weight is not 0, and the number of connections of the server is less than twice the weight.
如果服务器的连接数大于等于2倍的权值时,则表明服务器已超载。If the number of server connections is greater than or equal to 2 times the weight, it indicates that the server is overloaded.
本步骤中需要说明的是,可以使用现有技术中的心跳检测技术判断当前服务器是否存活,此处不再赘述。服务器的权值与连接数保存在调度器中,权值指保存在调度器可人工编辑的各服务器额定的连接数,可以人工设置,并且在调度时可以实时的更新各个服务器的连接数,连接数是指与服务器相连的外部用户的个数,可以实时修改。采用现有技术中源地址散列调度算法中的方法获得及更新各个服务器的权值与连接数。What needs to be explained in this step is that the heartbeat detection technology in the prior art can be used to determine whether the current server is alive, which will not be repeated here. The weight and connection number of the server are stored in the scheduler. The weight refers to the rated connection number of each server saved in the scheduler and can be manually edited. It can be manually set, and the connection number of each server can be updated in real time during scheduling. The number refers to the number of external users connected to the server, which can be modified in real time. The method in the source address hash scheduling algorithm in the prior art is used to obtain and update the weight and connection number of each server.
上述方法中,hash层级的取值范围为[0,N-1],N为服务器的总个数。In the above method, the value range of the hash level is [0, N-1], and N is the total number of servers.
本发明方法只有当level达到服务器数量N时才会宣布找不到满足要求的服务器,而level达到N(服务器的总的个数)值时,表明已经遍历了所有服务器,即所有服务器都是不满足要求的服务器,因此该方法是一个最优的调度算法,同时该算法能继承源地址散列调度算法的优点,即具有调度局部性,在服务器的负载基本平衡情况下,将相同IP地址的请求调度到同一台服务器,提高了各台服务器的访问局部性和主存命中率,从而提高了整个集群系统的处理能力。Only when the level reaches the server quantity N, the method of the present invention will announce that no server meeting the requirements can be found, and when the level reaches the value of N (the total number of servers), it indicates that all servers have been traversed, that is, all servers are unavailable. Therefore, this method is an optimal scheduling algorithm. At the same time, this algorithm can inherit the advantages of the source address hash scheduling algorithm, that is, it has scheduling locality. When the load of the server is basically balanced, the same IP address Requests are dispatched to the same server, which improves the access locality and main memory hit rate of each server, thereby improving the processing capacity of the entire cluster system.
图2为本发明实现集群负载均衡调度的方法的实施例的流程图,如图2所示,包括以下步骤:Fig. 2 is the flow chart of the embodiment of the method for realizing the cluster load balancing scheduling of the present invention, as shown in Fig. 2, comprises the following steps:
步骤201,计算集群收到请求包时,设定散列hash层级为0。Step 201, when the computing cluster receives the request packet, set the hash level to 0.
步骤202,根据请求包及hash层级,确定hash层级对应的服务器。Step 202, according to the request packet and the hash level, determine the server corresponding to the hash level.
本步骤与步骤102相同,在此不再赘述。This step is the same as step 102 and will not be repeated here.
步骤203,判断服务器是否满足调度条件,若满足调度条件,转入步骤204,若服务器不满足调度条件,则转入步骤205。Step 203, judging whether the server satisfies the scheduling condition, if the scheduling condition is met, go to step 204, if the server does not meet the scheduling condition, go to step 205.
本步骤中的调度条件与步骤103中的要求相同。The scheduling condition in this step is the same as the requirement in step 103 .
步骤204,将请求分发到服务器。至此分发任务完成,结束。Step 204, distribute the request to the server. At this point, the distribution task is completed and ends.
步骤205,hash层级增加1。转入步骤206。In step 205, the hash level is increased by 1. Go to step 206.
步骤206,判断hash层级是否超过最大值,若超过最大值,则转入步骤207;若未超过最大值,则返回步骤202。Step 206, judge whether the hash level exceeds the maximum value, if it exceeds the maximum value, then go to step 207; if it does not exceed the maximum value, then return to step 202.
上述hash层级的取值范围为[0,N-1],N为服务器的总个数。The value range of the above hash level is [0, N-1], and N is the total number of servers.
步骤207,拒绝请求。Step 207, rejecting the request.
图3为本发明实现集群负载均衡调度的装置的结构示意图,如3所示,包括:设置模块、映射模块、判断模块和分发模块。其中,FIG. 3 is a schematic structural diagram of a device for implementing cluster load balancing scheduling according to the present invention, as shown in FIG. 3 , including: a setting module, a mapping module, a judging module and a distribution module. in,
设置模块,用于计算集群收到请求包时,设定散列hash层级为0。The setting module is used to set the hash level to 0 when the computing cluster receives the request packet.
设置模块接收来自外部网络某个用户向计算集群发送的请求包,请求包中包括源地址IP即外部用户使用的IP地址,设置模块将IP地址以及hash层级发送给映射模块。The setting module receives a request packet sent from a user on the external network to the computing cluster. The request packet includes the source address IP, which is the IP address used by the external user, and the setting module sends the IP address and hash level to the mapping module.
映射模块,与设置模块相连,用于根据请求包及hash层级,确定hash层级对应的服务器。The mapping module is connected with the setting module, and is used to determine the server corresponding to the hash level according to the request packet and the hash level.
进一步地,上述映射模块具体用于:Further, the above mapping module is specifically used for:
通过下面的公式得到上述服务器的索引值:The index value of the above server is obtained by the following formula:
(ip_addr*2654435761UL)%(N—hash层级);其中,ip_addr是对应于所述IP地址的整数,%是取模运算。(ip_addr*2654435761UL)%(N—hash level); wherein, ip_addr is an integer corresponding to the IP address, and % is a modulo operation.
根据所述服务器的索引值,在ServerNode表中找到上述hash层级对应的服务器。According to the index value of the server, the server corresponding to the above hash level is found in the ServerNode table.
需要说明的是,通过上述公式找到服务器的索引值,类似于现有技术中素数乘法hash函数,不同之处,也是本发明的核心所在:第一个不同是,hash掩码,即N—hash层级,不是固定的,而是根据hash层级变化;第二个不同是,获取hash层级对应的服务器索引值不是用与运算而是用取模运算,使得运算更加的渐变,这就大大节省了运算时间。另外,2654435761UL是一个全局固定的值,是2到2^32(4294967296)间接近于黄金分割的素数,2654435761/4294967296=0.618033987,这样保证了不同的源地址会尽量分配到不同的服务器中。It should be noted that finding the index value of the server through the above formula is similar to the hash function of prime number multiplication in the prior art. The difference is also the core of the present invention: the first difference is that the hash mask, that is, N-hash The level is not fixed, but changes according to the hash level; the second difference is that obtaining the server index value corresponding to the hash level does not use the AND operation but the modulo operation, which makes the operation more gradual, which greatly saves the operation time. In addition, 2654435761UL is a globally fixed value, which is a prime number close to the golden section between 2 and 2^32 (4294967296), 2654435761/4294967296=0.618033987, which ensures that different source addresses will be allocated to different servers as much as possible.
可以通过以下方法得到对应的ip_addr:不足三位的域加0补足三位。The corresponding ip_addr can be obtained by the following method: field less than three digits plus 0 to make up three digits.
举例说明,当IP地址为192.168.0.1时,因为前两个域均为三位,所以只需补足后两个域即可,即第三个域补充两个0变成000,第四个域补充两个0变成001,上述IP地址转化后得到ip_addr=192168000001。如共1000台服务器即N=1000,IP地址为192.168.0.1时,ip_addr=192168000001,当hash层级=0时,N—hash层级=1000–0=1000,则(ip_addr*2654435761UL)%(N—hash层级)=192168000001*2654435761%1000=761,即hash到第761台服务器,当hash层级为1时,N—hash层级=1000–1=999,则(ip_addr*2654435761UL)%(N—hash层级)=192168000001*2654435761%999=763,即hash到第763台服务器。For example, when the IP address is 192.168.0.1, because the first two fields are three digits, it is only necessary to fill in the last two fields, that is, the third field is supplemented with two 0s to become 000, and the fourth field Two 0s are added to become 001, and the above IP address is converted to ip_addr=192168000001. If there are 1000 servers in total, that is N=1000, when the IP address is 192.168.0.1, ip_addr=192168000001, when the hash level=0, N—hash level=1000–0=1000, then (ip_addr*2654435761UL)%(N— hash level)=192168000001*2654435761%1000=761, that is, hash to the 761st server, when the hash level is 1, N—hash level=1000–1=999, then (ip_addr*2654435761UL)%(N—hash level )=192168000001*2654435761%999=763, that is, hash to the 763th server.
判断模块,用于判断获得的服务器是否满足调度条件。A judging module, configured to judge whether the obtained server satisfies the scheduling condition.
上述调度条件包括:该服务器存活、权值不为0且所述服务器的连接数小于2倍的权值。The above scheduling conditions include: the server is alive, the weight is not 0, and the number of connections of the server is less than twice the weight.
如果服务器的连接数大于等于2倍的权值时,则表明服务器已超载。If the number of server connections is greater than or equal to 2 times the weight, it indicates that the server is overloaded.
需要说明的是,可以使用现有技术中的心跳检测技术判断当前服务器是否存活,此处不再赘述。服务器的权值与连接数保存在调度器中,权值指保存在调度器可人工编辑的各服务器额定的连接数,并且在调度时可以实时的更新各个服务器的连接数,连接数是指与服务器相连的外部用户的个数。采用现有技术中源地址散列调度算法中的方法获得及更新各个服务器的权值与连接数。It should be noted that the heartbeat detection technology in the prior art can be used to determine whether the current server is alive, which will not be repeated here. The server's weight and connection number are stored in the scheduler. The weight refers to the rated connection number of each server that can be manually edited in the scheduler, and the connection number of each server can be updated in real time during scheduling. The connection number refers to the The number of external users connected to the server. The method in the source address hash scheduling algorithm in the prior art is used to obtain and update the weight and connection number of each server.
分发模块,用于当服务器满足调度条件时,则将请求分发到该服务器。The distribution module is configured to distribute the request to the server when the server meets the scheduling condition.
上述映射模块,还用于当服务器不满足调度条件时,则hash层级增加1,继续确定hash层对应的服务器,当hash层级超过最大值,则拒绝请求。The above mapping module is also used to increase the hash level by 1 when the server does not meet the scheduling conditions, and continue to determine the server corresponding to the hash level, and reject the request when the hash level exceeds the maximum value.
上述装置中,hash层级的取值范围为[0,N-1],N为服务器的总个数。In the above device, the value range of the hash level is [0, N-1], and N is the total number of servers.
上述装置还包括:存储模块,与设置模块相连,用于:在计算集群收到请求包时,设定hash层级为0之前,建立用于存储所述计算集群中的各个服务器信息与索引值的一一对应关系的ServerNode表。The above-mentioned device also includes: a storage module, connected to the setting module, used for: when the computing cluster receives the request packet, before setting the hash level to 0, establish a server information and index value for storing each server information and index value in the computing cluster ServerNode table of one-to-one correspondence.
其中服务器信息包括:服务器的IP,名称,内存,硬盘。关于如何建立ServerNode表属于本领域技术人员熟知的公知常识,在此不再赘述。The server information includes: server IP, name, memory, hard disk. How to establish the ServerNode table belongs to the common knowledge well known by those skilled in the art, and details are not repeated here.
需要说明的是,ServerNode表包含了所有服务器及其信息,且ServerNode表中的每一个索引值都与ServerNode表中一个服务器对应,即找到索引值,就可以获得与之对应的服务器以及该服务器的信息。It should be noted that the ServerNode table contains all servers and their information, and each index value in the ServerNode table corresponds to a server in the ServerNode table, that is, if you find the index value, you can obtain the corresponding server and the server's information.
本领域普通技术人员可以理解上述方法中的全部或部分步骤可通过程序来指令相关硬件完成,所述程序可以存储于计算机可读存储介质中,如只读存储器、磁盘或光盘等。可选地,上述实施例的全部或部分步骤也可以使用一个或多个集成电路来实现。相应地,上述实施例中的各模块/单元可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。本申请不限制于任何特定形式的硬件和软件的结合。Those skilled in the art can understand that all or part of the steps in the above method can be completed by instructing relevant hardware through a program, and the program can be stored in a computer-readable storage medium, such as a read-only memory, a magnetic disk or an optical disk, and the like. Optionally, all or part of the steps in the foregoing embodiments may also be implemented using one or more integrated circuits. Correspondingly, each module/unit in the foregoing embodiments may be implemented in the form of hardware, or may be implemented in the form of software function modules. This application is not limited to any specific form of combination of hardware and software.
以上所述,仅为本发明的较佳实例而已,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above descriptions are only preferred examples of the present invention, and are not intended to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410327814.6A CN104104611B (en) | 2014-07-10 | 2014-07-10 | A kind of method and device for realizing cluster load balance scheduling |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410327814.6A CN104104611B (en) | 2014-07-10 | 2014-07-10 | A kind of method and device for realizing cluster load balance scheduling |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104104611A true CN104104611A (en) | 2014-10-15 |
CN104104611B CN104104611B (en) | 2017-12-12 |
Family
ID=51672419
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410327814.6A Active CN104104611B (en) | 2014-07-10 | 2014-07-10 | A kind of method and device for realizing cluster load balance scheduling |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104104611B (en) |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104468823A (en) * | 2014-12-24 | 2015-03-25 | 浪潮(北京)电子信息产业有限公司 | Cluster load balancing scheduling method and system |
CN112015552A (en) * | 2020-08-27 | 2020-12-01 | 平安科技(深圳)有限公司 | Hash ring load balancing method and device, electronic equipment and storage medium |
CN112947333A (en) * | 2021-02-05 | 2021-06-11 | 天津市普迅电力信息技术有限公司 | Socket long connection-based balanced load fragmentation method |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1595906A (en) * | 2003-12-17 | 2005-03-16 | 浪潮电子信息产业股份有限公司 | Single address traffic distributor of cluster network |
US20060218176A1 (en) * | 2005-03-24 | 2006-09-28 | International Business Machines Corporation | System, method, and service for organizing data for fast retrieval |
CN102325093A (en) * | 2011-11-01 | 2012-01-18 | 西安电子科技大学 | A method for constructing routing system in structured P2P network |
CN102571991A (en) * | 2012-03-27 | 2012-07-11 | 电子科技大学 | Multistage-mapping-based large-scale multi-copy distributed storage system and application method thereof |
CN103139093A (en) * | 2013-02-22 | 2013-06-05 | 桂林电子科技大学 | High speed network data flow load balancing scheduling method based on field programmable gate array (FPGA) |
-
2014
- 2014-07-10 CN CN201410327814.6A patent/CN104104611B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1595906A (en) * | 2003-12-17 | 2005-03-16 | 浪潮电子信息产业股份有限公司 | Single address traffic distributor of cluster network |
US20060218176A1 (en) * | 2005-03-24 | 2006-09-28 | International Business Machines Corporation | System, method, and service for organizing data for fast retrieval |
CN102325093A (en) * | 2011-11-01 | 2012-01-18 | 西安电子科技大学 | A method for constructing routing system in structured P2P network |
CN102571991A (en) * | 2012-03-27 | 2012-07-11 | 电子科技大学 | Multistage-mapping-based large-scale multi-copy distributed storage system and application method thereof |
CN103139093A (en) * | 2013-02-22 | 2013-06-05 | 桂林电子科技大学 | High speed network data flow load balancing scheduling method based on field programmable gate array (FPGA) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104468823A (en) * | 2014-12-24 | 2015-03-25 | 浪潮(北京)电子信息产业有限公司 | Cluster load balancing scheduling method and system |
CN104468823B (en) * | 2014-12-24 | 2018-02-06 | 浪潮(北京)电子信息产业有限公司 | A kind of cluster load balance dispatching method and system |
CN112015552A (en) * | 2020-08-27 | 2020-12-01 | 平安科技(深圳)有限公司 | Hash ring load balancing method and device, electronic equipment and storage medium |
CN112947333A (en) * | 2021-02-05 | 2021-06-11 | 天津市普迅电力信息技术有限公司 | Socket long connection-based balanced load fragmentation method |
Also Published As
Publication number | Publication date |
---|---|
CN104104611B (en) | 2017-12-12 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108431796B (en) | Distributed resource management system and method | |
US20220329651A1 (en) | Apparatus for container orchestration in geographically distributed multi-cloud environment and method using the same | |
CN105224392B (en) | A kind of virtual computing resource quota management method and platform | |
CN103188345B (en) | Distributed dynamic load management system and method | |
CN104065568B (en) | Web server cluster routing method | |
CN106817432B (en) | Method, system and equipment for elastically stretching virtual resources in cloud computing environment | |
CN105391797A (en) | SDN-based cloud server load balancing method and device | |
CN102929701A (en) | Scheduling method and device for batched virtual machines | |
CN105471985A (en) | Load balance method, cloud platform computing method and cloud platform | |
CN108768716A (en) | A kind of micro services routing resource and device | |
CN111913670B (en) | Processing method and device for load balancing, electronic equipment and storage medium | |
CN110489238A (en) | Nodal test method, apparatus, electronic equipment and storage medium | |
JP2019204489A (en) | Object storage system with multi-level hashing function for storage address determination | |
JPWO2018220708A1 (en) | Resource allocation system, management device, method and program | |
CN102970381A (en) | Multi-source load balance method and system for proportional polling based on content distribution network | |
Ullah et al. | Enhancing the dynamic load balancing technique for cloud computing using HBATAABC algorithm | |
CN113014611A (en) | Load balancing method and related equipment | |
Jain et al. | A multi stage load balancing technique for cloud environment | |
CN110233866A (en) | A kind of load-balancing method and load balancer | |
Komarasamy et al. | A novel approach for Dynamic Load Balancing with effective Bin Packing and VM Reconfiguration in cloud | |
Imdoukh et al. | Optimizing scheduling decisions of container management tool using many‐objective genetic algorithm | |
CN104104611B (en) | A kind of method and device for realizing cluster load balance scheduling | |
CN105210324B (en) | Strategy and charging rule functions virtual method, apparatus and system | |
Sasidhar et al. | Load Balancing Techniques for Efficient Traffic Management in Cloud Environment. | |
CN107920129A (en) | A kind of method, apparatus, equipment and the cloud storage system of data storage |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |