CN107426332A - The load-balancing method and system of a kind of web server cluster - Google Patents
The load-balancing method and system of a kind of web server cluster Download PDFInfo
- Publication number
- CN107426332A CN107426332A CN201710680742.7A CN201710680742A CN107426332A CN 107426332 A CN107426332 A CN 107426332A CN 201710680742 A CN201710680742 A CN 201710680742A CN 107426332 A CN107426332 A CN 107426332A
- Authority
- CN
- China
- Prior art keywords
- server
- mrow
- msub
- load
- moment
- 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
- 238000000034 method Methods 0.000 title claims abstract description 73
- 230000003068 static effect Effects 0.000 claims abstract description 145
- 230000006870 function Effects 0.000 claims description 35
- 238000012545 processing Methods 0.000 claims description 28
- 230000008569 process Effects 0.000 claims description 16
- 238000009499 grossing Methods 0.000 claims description 8
- 230000004044 response Effects 0.000 claims description 5
- 230000005540 biological transmission Effects 0.000 claims description 2
- 238000013277 forecasting method Methods 0.000 claims 1
- 230000000694 effects Effects 0.000 abstract description 8
- 238000003672 processing method Methods 0.000 abstract description 2
- 238000010276 construction Methods 0.000 description 1
- 230000007812 deficiency Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000002474 experimental method Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000000737 periodic effect Effects 0.000 description 1
- 238000011160 research Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
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/1004—Server selection for load balancing
- H04L67/1008—Server selection for load balancing based on parameters of servers, e.g. available memory or workload
-
- 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/1004—Server selection for load balancing
-
- 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/50—Network services
- H04L67/60—Scheduling or organising the servicing of application requests, e.g. requests for application data transmissions using the analysis and optimisation of the required network resources
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Hardware Design (AREA)
- General Engineering & Computer Science (AREA)
- Computer And Data Communications (AREA)
- Information Transfer Between Computers (AREA)
Abstract
本发明公开了一种WEB服务器集群的负载均衡方法及系统,首先为每种类型静态页面访问分别指定其所要分配的服务器,同时构建负载均衡目标函数,当接收到页面方法请求时,进行分类,当为静态页面访问请求时,根据其所属类型将其分配到相应的服务器中;当为动态页面访问请求时,根据上一周期所获取到的当前周期各台服务器动态页面访问的最优分配权重对当前周期各时刻的动态页面访问进行分配;当时间到达当前周期最后一时刻时,通过均衡目标函数得到下一周期各台服务器动态页面访问的最优分配权重;本发明针对静态页面和动态页面分别提出了不同的处理方式,这样可以充分利用服务器资源,在复杂的访问形势下依然可以达到负载均衡的效果。
The invention discloses a load balancing method and system of a WEB server cluster. Firstly, for each type of static page access, the server to be allocated is respectively designated, and at the same time, a load balancing target function is constructed. When a page method request is received, it is classified, When it is a static page access request, it is allocated to the corresponding server according to its type; when it is a dynamic page access request, it is obtained according to the optimal allocation weight of each server's dynamic page access in the current cycle obtained in the previous cycle Allocate the dynamic page access at each moment of the current cycle; when the time reaches the last moment of the current cycle, obtain the optimal allocation weight of each server's dynamic page access in the next cycle by balancing the objective function; the present invention is aimed at static pages and dynamic pages Different processing methods are proposed respectively, so that server resources can be fully utilized, and load balancing effects can still be achieved under complex access situations.
Description
技术领域technical field
本发明涉及计算机服务器集群领域,特别涉及一种WEB服务器集群的负载 均衡方法及系统。The invention relates to the field of computer server clusters, in particular to a load balancing method and system for a WEB server cluster.
背景技术Background technique
随着互联网的高速发展,各类网络化信息系统规模越来越大,访问流量呈几 何级数增长,这对服务器的工作性能提出更高要求。单个Web服务器在处理大 量服务请求时会存在工作负载过大,服务请求响应时间长,反馈延迟大的问题, 严重时会出现单点故障,用户体验表现较差。因此使用服务器集群技术提高系 统响应效率与可靠性,为用户提供并发服务。服务器集群中单个服务器的结构 和性能存在差异,客户端访问具有随机性和突发性,因此现有系统一般会配置 负载均衡器。负载均衡器根据单个服务器的最大处理能力和当前的负载状况, 依据负载调度策略分配负载任务,合理利用每台服务器的资源而避免出现过载 情况,提高了服务器集群的稳定性和响应速度。With the rapid development of the Internet, the scale of various networked information systems is getting larger and larger, and the access traffic is increasing exponentially, which puts forward higher requirements for the working performance of the server. When a single web server handles a large number of service requests, there will be problems such as excessive workload, long service request response time, and large feedback delay. In severe cases, there will be a single point of failure, and the user experience will be poor. Therefore, server cluster technology is used to improve system response efficiency and reliability, and to provide users with concurrent services. The structure and performance of individual servers in the server cluster are different, and client access is random and sudden, so the existing system generally configures a load balancer. According to the maximum processing capacity of a single server and the current load status, the load balancer distributes load tasks according to the load scheduling strategy, reasonably utilizes the resources of each server to avoid overloading, and improves the stability and response speed of the server cluster.
对于Web服务器集群的负载均衡研究,从模型、方法与应用实现几个方面 已有较多成果。负载均衡方法分为静态和动态两大类。静态负载均衡方法包括 Random随机(RAN)方法、Round-Robin轮询(RR)方法以及静态权重轮询(SWRR) 方法。随机法即随机从服务器集群中选择一台服务器响应服务请;轮询法即将 新的访问请求一次轮询发到各个服务器上;静态加权轮询法即根据每台服务器 的不用处理能力,给每台服务器分配给不同的权值,使其能够接受相应权值数 的服务请求。静态负载均衡方法将各服务器的任务分配比例作为系统参数保存 在负载均衡器中,不考虑服务器负载的实时变化情况。静态负载均衡方法属于 开环负载调节方式,难以满足新一代服务器集群的性能要求。动态负载均衡方 法包括最少连接(LC)方法、加权最少连接(WLC)方法和动态权重轮询(DWRR)方 法。负载均衡器周期性收集每台服务器的负载信息,根据服务器的实时负载水 平计算任务分配权重分配任务,在请求任务类型不同和工作负载差异较大的情 况下,动态负载均衡算性能优于静态负载均衡方法,但动态负载均衡方法需要 额外的数据处理与传输。传统的动态负载均衡方法存在着局限性,譬如,最少 连接方法以连接数量衡量服务器当前的负载情况,因为服务器性能不同、动态 页面访问任务消耗的服务器资源不同,连接数相同不等同于服务器承受的负载 量相同,因此传统的动态负载均衡方法并不能准确衡量服务器当前负载情况。For the load balancing research of Web server clusters, there have been many achievements in the aspects of model, method and application realization. There are two types of load balancing methods: static and dynamic. Static load balancing methods include Random Random (RAN) method, Round-Robin Round Robin (RR) method and Static Weight Round Robin (SWRR) method. The random method is to randomly select a server from the server cluster to respond to the service request; the polling method is to send a new access request to each server in a poll; the static weighted polling method is to give each Each server is assigned different weights so that it can accept service requests with corresponding weights. The static load balancing method saves the task distribution ratio of each server as a system parameter in the load balancer, regardless of the real-time changes in server load. The static load balancing method is an open-loop load adjustment method, which is difficult to meet the performance requirements of the new generation of server clusters. Dynamic load balancing methods include Least Connection (LC) method, Weighted Least Connection (WLC) method and Dynamic Weighted Round Robin (DWRR) method. The load balancer periodically collects the load information of each server, and calculates the task distribution weight distribution tasks according to the real-time load level of the server. In the case of different types of request tasks and large differences in workload, the performance of dynamic load balancing is better than that of static loads. Balancing method, but the dynamic load balancing method requires additional data processing and transmission. The traditional dynamic load balancing method has limitations. For example, the least connection method uses the number of connections to measure the current load of the server. Because the performance of the server is different and the server resources consumed by the dynamic page access task are different, the same number of connections does not mean the load on the server. The load is the same, so the traditional dynamic load balancing method cannot accurately measure the current load of the server.
发明内容Contents of the invention
本发明的第一目的在于克服现有技术的缺点与不足,提供一种WEB服务器 集群的负载均衡方法,该方法能够在混合请求服务下实现服务器集群的负载均 衡,相比传统的负载均衡方法,该方法可以充分利用服务器资源,在复杂的访 问形势下依然可以达到负载均衡的效果。The first purpose of the present invention is to overcome the shortcoming and deficiency of prior art, provide a kind of load balancing method of WEB server cluster, this method can realize the load balancing of server cluster under mixed request service, compared with traditional load balancing method, This method can make full use of server resources, and can still achieve the effect of load balancing under complex access situations.
本发明的第二目在于提供一种用于实现上述负载均衡方法的WEB服务器 集群的负载均衡系统。The second object of the present invention is to provide a kind of load balancing system for realizing the WEB server cluster of above-mentioned load balancing method.
本发明的第一目的通过下述技术方案实现:一种WEB服务器集群的负载均 衡方法,包括如下步骤:The first purpose of the present invention is achieved through the following technical solutions: a load balancing method of a WEB server cluster, comprising the steps:
S1、首先为每种类型静态页面访问分别指定其所要分配的服务器;同时, 以下一周期最后一时刻各台服务器的负载率对应最接近于下一周期最后一时刻 服务器平均预测负载率为目标构建负载均衡目标函数,通过目标函数求解下一 周期各台服务器动态页面访问的最优分配权重;并且构建负载均衡目标函数的 约束条件,包括:下一周期最后一时刻各台服务器负载率小于一定值以及下一 周期各台服务器动态页面访问分配权重之和为1;S1. First, specify the server to be allocated for each type of static page access; at the same time, the load rate of each server at the last moment of the next cycle corresponds to the target construction that is closest to the average predicted load rate of the server at the last moment of the next cycle Load balancing objective function, through the objective function to solve the optimal allocation weight of each server's dynamic page access in the next period; and construct the constraints of the load balancing objective function, including: the load rate of each server at the last moment of the next period is less than a certain value And the sum of the dynamic page access allocation weights of each server in the next cycle is 1;
针对于当前周期各时刻接收的客户端所提出的页面访问请求,进行如下处 理:For the page access request received from the client at each moment of the current cycle, the following processing is performed:
S2、在当前周期各时刻接收到客户端所提出的页面访问请求时,首先对请 求访问的页面进行分类,若为动态页面,则进行步骤S4的处理;若为静态页面, 则进行步骤S3的处理;同时,当时间到达当前周期最后一时刻时,采集当前周 期最后一时刻各台服务器的负载率,并且计算下一周期各台服务器动态页面访 问的最优分配权重,具体过程如下:首先根据当前周期最后一时刻各台服务器 的负载率及上一周期最后一时刻所预测得到的当前周期最后一时刻各台服务器 的预测负载率预测下一周期最后一时刻各台服务器的预测负载率,然后求均值 得到下一周期最后一时刻服务器平均预测负载率,最后将下一周期最后一时刻 服务器平均预测负载率输入步骤S1中构建的负载均衡目标函数中求取最优解, 从而得到下一周期各台服务器动态页面访问的最优分配权重;在下一周期到来 时,返回本步骤;S2, when receiving the page access request proposed by the client at each moment of the current cycle, first classify the page requested to be accessed, if it is a dynamic page, then proceed to step S4; if it is a static page, then proceed to step S3 At the same time, when the time reaches the last moment of the current cycle, collect the load rate of each server at the last moment of the current cycle, and calculate the optimal distribution weight of each server's dynamic page access in the next cycle. The specific process is as follows: first, according to The load rate of each server at the last moment of the current cycle and the predicted load rate of each server at the last moment of the current cycle predicted at the last moment of the previous cycle predict the predicted load rate of each server at the last moment of the next cycle, and then Calculate the average value to obtain the average predicted load rate of the server at the last moment of the next cycle, and finally input the average predicted load rate of the server at the last moment of the next cycle into the load balancing objective function constructed in step S1 to obtain the optimal solution, thereby obtaining the next cycle The optimal allocation weight of each server's dynamic page access; when the next cycle comes, return to this step;
S3、针对于当前周期各时刻的静态页面访问请求,首先获取请求访问的静 态页面的类型,然后查找该种类型静态页面访问指定的所要分配的服务器,并 且判断该服务器当前是否还能对页面访问提供服务,若是,则将静态页面访问 分配至该服务器;若否,则将静态页面访问分配至WEB服务器集群中上一周期 最后一时刻负载率最小的服务器中,并且将该种类型静态页面访问指定所要分 配的服务器更新为该服务器;S3. For the static page access requests at each moment of the current cycle, first obtain the type of the static page that is requested to be accessed, and then search for the server to be assigned for this type of static page access, and determine whether the server can currently access the page Provide services, if so, assign the static page access to the server; if not, assign the static page access to the server with the smallest load rate at the last moment of the last cycle in the WEB server cluster, and assign this type of static page access Specify that the server to be assigned is updated to this server;
S4、针对于当前周期各时刻的动态页面访问请求,根据上一周期最后一时 刻所获取到的当前周期各台服务器动态页面访问的最优分配权重对当前周期各 时刻的动态页面访问进行分配。S4. For the dynamic page access requests at each moment of the current cycle, the dynamic page access at each moment of the current cycle is allocated according to the optimal distribution weight of the dynamic page access of each server in the current cycle obtained at the last moment of the previous cycle.
优选的,步骤S1中为每种类型静态页面访问分别指定其所要分配的服务器, 并且记录在哈希表中;所述步骤S3中针对于当前周期各时刻的静态页面访问请 求,获取请求访问的静态页面的类型后,通过哈希表查找该种类型静态页面访 问指定的所要分配的服务器。Preferably, in step S1, the server to be assigned is specified for each type of static page access respectively, and is recorded in the hash table; in the step S3, for the static page access request at each moment of the current cycle, the request access information is obtained. After specifying the type of the static page, look up the static page of this type through the hash table to access the specified server to be allocated.
优选的,步骤S2,当前周期各个时刻各台服务器的负载率计算公式为:Preferably, in step S2, the formula for calculating the load rate of each server at each moment in the current period is:
其中Ri(t)为当前周期t时刻第i台服务器的负载率,为当前周期t时刻第 i台服务器要处理的静态页面负载量,为当前周期t时刻第i台服务器要处理 的动态页面负载量,Ci为第i台服务器的最大处理能力;其中当t取(k-1)T时, 通过上式计算得到当前周期即第(k-1)个周期最后一时刻(k-1)T时刻第i台服务 器的负载率,k=2,3,...;Where R i (t) is the load rate of the i-th server at time t of the current period, is the static page load to be processed by the i-th server at time t of the current period, is the dynamic page load to be processed by the i-th server at time t in the current cycle, and C i is the maximum processing capacity of the i-th server; when t is (k-1)T, the current cycle is calculated by the above formula (k-1) The load rate of the i-th server at the last moment (k-1)T of the cycle, k=2,3,...;
其中当前周期各时刻各台服务器要处理的静态页面负载量计算公式为:The formula for calculating the static page load to be processed by each server at each moment in the current cycle is:
其中ci,1(t),ci,2(t),…ci,j(t)分别对应为当前周期t时刻第i台服务器持有的第1,2,…,j类静态文件访问数量;是访问第j类静态页面产生的负载,Sj为 第j类静态页面的大小,λ是读取静态页面文件及处理发送的资源使用率系数,T 为周期长度;当t取(k-1)T时,通过上式计算得到当前周期即第(k-1)个周期最 后一时刻(k-1)T时刻第i台服务器要处理的静态页面负载量 Among them, c i,1 (t), c i,2 (t), ... c i, j (t) respectively correspond to the first, second, ..., j-type static files held by the i-th server at the moment of the current cycle t number of visits; is the load generated by accessing the jth type of static page, S j is the size of the jth type of static page, λ is the resource utilization coefficient for reading the static page file and processing and sending, T is the cycle length; when t is taken as (k-1 )T, the static page load to be processed by the i-th server at the last moment (k-1)T of the current period (k-1)th period is calculated by the above formula
其中当前周期各时刻各台服务器要处理的动态页面负载量计算公式为:The formula for calculating the dynamic page load to be processed by each server at each moment in the current cycle is:
其中为当前周期t时刻前第i台服务器未完成动态页面负载量,Mi为第i 台服务器生成动态页面的性能常数,wi(k-1)为上一周期所获取到的当前周期即 第(k-1)个周期第i台服务器动态页面访问的最优分配权重;为当前周期t时刻 需要缓冲与转发至第i台服务器的动态页面访问数量,为当前周期t时刻对应 个动态页面访问数量在第i台服务器产生的负载量;当t取(k-1)T时,通过 上式计算得到当前周期即第(k-1)个周期最后一时刻(k-1)T时刻第i台服务器要 处理的动态页面负载量 in is the uncompleted dynamic page load of the i-th server before time t in the current cycle, M i is the performance constant of the dynamic page generated by the i-th server, w i (k-1) is the current cycle obtained in the previous cycle, i.e. the (k-1) The optimal allocation weight of the i-th server's dynamic page access in the cycle; is the number of dynamic page visits that need to be buffered and forwarded to the i-th server at time t of the current period, Corresponding to time t of the current cycle The load generated by the number of dynamic page visits on the i server; when t is (k-1)T, the current cycle is calculated by the above formula, that is, the last moment (k-1) of the (k-1)th cycle The amount of dynamic page load to be processed by the i-th server at time T
当前周期最后一时刻各台服务器的负载率为:The load rate of each server at the last moment of the current cycle:
其中Ri((k-1)T)为当前周期即第(k-1)个周期最后一时刻(k-1)T时刻第i 台服务器的负载率。Wherein R i ((k-1)T) is the load rate of the i-th server at the last moment (k-1)T of the current cycle, that is, the (k-1)th cycle.
更进一步的,读取静态页面文件及处理发送的资源使用率系数λ取值如下:Furthermore, the value of the resource utilization coefficient λ for reading static page files and processing and sending is as follows:
当服务器从磁盘中读静态页面文件及处理时,取λ=λ1,λ1为服务器从磁盘 中读静态页面文件及处理发送的资源使用率系数,When the server reads the static page file from the disk and processes it, take λ=λ 1 , where λ 1 is the resource utilization coefficient for the server to read the static page file from the disk and process it,
当服务器从缓存中读静态页面文件及处理时,取λ=λ2;λ2为服务器从缓存 中读静态页面文件及处理发送的资源使用率系数;When the server reads the static page file and processes it from the cache, get λ=λ 2 ; λ 2 is the resource utilization coefficient that the server reads the static page file from the cache and processes and sends it;
其中λ1>λ2。where λ 1 >λ 2 .
更进一步的,第i台服务器的最大处理能力Ci为:Furthermore, the maximum processing capacity C i of the i-th server is:
其中k1~k4各指标对服务器最大处理能力的影响系数;μi为第i台服务器CPU 数量,fi第i台服务器CPU频率,Gi为第i台服务器的内存容量,Di为第i台服务器 的I/O速率,Ni为第i台服务器的网络吞吐量。Among them, k 1 ~ k 4 are the influence coefficients of each index on the maximum processing capacity of the server; μ i is the CPU quantity of the i-th server, f i is the CPU frequency of the i-th server, G i is the memory capacity of the i-th server, and D i is The I/O rate of the i-th server, N i is the network throughput of the i-th server.
优选的,步骤S2中,根据当前周期最后一时刻各台服务器的负载率及其上 一周期最后一时刻所预测的当前周期最后一时刻各台服务器的预测负载率,通 过指数平滑预测法预测下一周期最后一时刻各台服务器的预测负载率:Preferably, in step S2, according to the load rate of each server at the last moment of the current cycle and the predicted load rate of each server at the last moment of the current cycle predicted at the last moment of the previous cycle, the following is predicted by the exponential smoothing prediction method The predicted load rate of each server at the last moment of a cycle:
其中Ri((k-1)T)为当前周期即第(k-1)个周期最后一时刻(k-1)T时刻第i台 服务器的负载率,为当前周期即第(k-1)个周期的上一周期即第k-2个 周期最后一时刻所预测得到的当前周期即第(k-1)个周期最后一时刻(k-1)T时 刻各台服务器的预测负载率,为下一周期即第k个周期最后一时刻kT时刻 第i台服务器的预测负载率;α为平滑系数;Where R i ((k-1)T) is the load rate of the i-th server at the last moment (k-1)T of the current period (k-1)th period, The last moment (k-1)T of the current period (k-1)th period predicted by the last period of the current period (k-1)th period, i.e. the last moment of the k-2th period The predicted load rate of each server at time, is the predicted load rate of the i-th server at time kT at the last moment of the k-th cycle in the next cycle; α is the smoothing coefficient;
根据下一周期最后一时刻各台服务器的预测负载率求取下一周期最后一时 刻服务器平均预测负载率:According to the predicted load rate of each server at the last moment of the next cycle, the average predicted load rate of the server at the last moment of the next cycle is obtained:
其中为下一周期即第k个周期最后一时刻kT时刻服务器平均预测负 载率;n为WEB服务器集群中服务器的总台数。in It is the average predicted load rate of the server at kT time at the last moment of the next period, that is, the kth period; n is the total number of servers in the WEB server cluster.
优选的,步骤S1中构建的负载均衡目标函数为:Preferably, the load balancing objective function constructed in step S1 is:
步骤S1中构建的负载均衡目标函数的约束条件为:The constraints of the load balancing objective function constructed in step S1 are:
Ri(kT)≤0.9,i=1,2,3,...n;R i (kT)≤0.9, i=1,2,3,...n;
其中Ri(kT)为下一周期即第k个周期最后一时刻kT的各台服务器的负载率,为下一周期即第k个周期最后一时刻服务器平均预测负载率,n为WEB服 务器集群服务器的总台数;wi(k)为下一周即第k个周期第i台服务器动态页面访 问的最优分配权重,其中i=1,2,...n;T为周期长度。Among them, R i (kT) is the load rate of each server at kT at the last moment of the k-th cycle in the next cycle, is the average predicted load rate of the server at the last moment of the next cycle, that is, the kth cycle, n is the total number of WEB server cluster servers; Optimal distribution of weights, where i=1,2,...n; T is the cycle length.
更进一步的,步骤S2中,通过柯西不等式和穷举法求得负载均衡目标函数 中的最优解,即最优分配权重。Furthermore, in step S2, the optimal solution in the load balancing objective function, that is, the optimal distribution weight is obtained through Cauchy's inequality and exhaustive method.
优选的,步骤S3中服务器在接收到静态页面访问时,首先是否缓存有该静 态页面,若否,则从磁盘中读取;Preferably, in step S3, when server receives static page visit, at first whether cache has this static page, if not, then read from disk;
步骤S2中,针对于第一周期各时刻的动态页面访问请求,设置该周期各台 服务器动态页面访问的最优分配权重相同。In step S2, for the dynamic page access requests at each moment of the first cycle, the optimal allocation weights of each server dynamic page access in this cycle are set to be the same.
本发明的第二目的通过下述技术方案实现:一种用于实现上述负载均衡方 法的WEB服务器集群的负载均衡系统,包括客户端和WEB服务器集群,所述 WEB服务器集群包括多台服务器;其特征在于,还包括负载均衡器,所述负载 均衡器设置在客户端和WEB服务器集群之间;The second object of the present invention is achieved through the following technical solutions: a load balancing system for a WEB server cluster for implementing the above load balancing method, including a client and a WEB server cluster, and the WEB server cluster includes a plurality of servers; It is characterized in that it also includes a load balancer, and the load balancer is set between the client and the WEB server cluster;
所述客户端,用于通过互联网向负载均衡器发送页面访问请求;The client is configured to send a page access request to the load balancer through the Internet;
所述负载均衡器,用于为每种类型静态页面访问分别指定其所要分配的服 务器;用于构建负载均衡目标函数及约束条件;所述负载均衡目标函数以下一 周期最后一时刻各台服务器的负载率对应最接近于下一周期最后一时刻服务器 平均预测负载率为目标,所述约束条件包括下一周期最后一时刻各台服务器负 载率小于一定值以及下一周期各台服务器动态页面访问分配权重之和为1;The load balancer is used to specify the server to be allocated for each type of static page access; it is used to construct a load balancing objective function and constraints; The load rate corresponds to the target that is closest to the average predicted load rate of the servers at the last moment of the next cycle. The constraints include that the load rate of each server is less than a certain value at the last moment of the next cycle and the dynamic page access allocation of each server in the next cycle The sum of the weights is 1;
用于接收当前周期各时刻客户端所提出的页面访问请求,在接收到页面访 问请求后,首先对请求访问的页面进行分类;若为静态页面,首先获取请求访 问的静态页面的类型,然后查找该种类型静态页面访问指定的所要分配的服务 器,并且判断该服务器当前是否还能对页面访问提供服务,若是,则将静态页 面访问分配至该服务器;若否,则将静态页面访问分配至WEB服务器集群中上 一周期最后一时刻负载率最小的服务器中,并且将该种类型静态页面访问指定 所要分配的服务器更新为该服务器;若为动态页面,根据上一周期最后一时刻 所获取到的当前周期各台服务器动态页面访问的最优分配权重对当前周期各时 刻的动态页面访问进行分配;It is used to receive the page access request from the client at each moment of the current cycle. After receiving the page access request, first classify the page that is requested to be accessed; if it is a static page, first obtain the type of the static page that is requested to be accessed, and then search This type of static page access specifies the server to be allocated, and judges whether the server can currently provide services for page access. If so, assign the static page access to the server; if not, assign the static page access to the WEB In the server cluster, the server with the smallest load rate at the last moment of the previous cycle, and the server to be allocated for this type of static page access is updated to this server; if it is a dynamic page, according to the obtained at the last moment of the previous cycle The optimal allocation weight of each server's dynamic page access in the current cycle is used to allocate the dynamic page access at each moment in the current cycle;
用于当时间到达当前周期最后一时刻时,采集WEB服务器集群中当前周期 最后一时刻各台服务器的负载率;Used to collect the load rate of each server at the last moment of the current cycle in the WEB server cluster when the time reaches the last moment of the current cycle;
用于当时间到达当前周期最后一时刻时,计算下一周期各台服务器动态页 面访问的最优分配权重,具体过程如下:首先根据当前周期最后一时刻各台服 务器的负载率及上一周期最后一时刻所预测得到的当前周期最后一时刻各台服 务器的预测负载率,预测下一周期最后一时刻各台服务器的预测负载率,然后 求均值得到下一周期最后一时刻服务器平均预测负载率,最后将下一周期最后 一时刻服务器平均预测负载率输入负载均衡目标函数中求取最优解,从而得到 下一周期各台服务器动态页面访问的最优分配权重;When the time reaches the last moment of the current period, it is used to calculate the optimal distribution weight of each server's dynamic page access in the next period. The specific process is as follows: first, according to the load rate of each server at the last moment of the current period and the last period of the previous period The predicted load rate of each server at the last moment of the current cycle is predicted at one moment, and the predicted load rate of each server at the last moment of the next cycle is predicted, and then the average value is obtained to obtain the average predicted load rate of the server at the last moment of the next cycle. Finally, the average predicted load rate of the server at the last moment of the next cycle is input into the load balancing objective function to find the optimal solution, so as to obtain the optimal allocation weight of the dynamic page access of each server in the next cycle;
所述WEB服务器集群中的各台服务器,用于当时间到达当前周期最后一时 刻时,计算其中负载率,供负载均衡器进行周期性的采集;用于接收负载均衡 器分配至其中的静态页面访问和动态页面访问;用于根据分配到其中的静态页 面访问和动态页面访问向客户端响应相应的服务。Each server in the WEB server cluster is used to calculate the load rate therein when the time reaches the last moment of the current cycle, and provide the load balancer for periodic collection; for receiving the static pages assigned to it by the load balancer Access and dynamic page access; used to respond to the client with the corresponding service based on the static page access and dynamic page access assigned to it.
本发明相对于现有技术具有如下的优点及效果:Compared with the prior art, the present invention has the following advantages and effects:
(1)本发明中,首先为每种类型静态页面访问分别指定其所要分配的服务 器,同时以下一周期最后一时刻各台服务器的负载率对应最接近于下一周期最 后一时刻服务器平均预测负载率为目标构建负载均衡目标函数,并且设定约束 条件;当接收到页面方法请求时,首先进行分类,当为静态页面访问请求时, 获取请求访问的静态页面的类型,然后将静态页面访问分配至还能提供访问服 务的该种类型静态页面访问指定的所要分配的服务器,若该服务器不能再提供 服务,则将静态页面访问分配至上一周期最后一时刻负载率最小的服务器中, 并且将该种类型静态页面访问指定所要分配的服务器更新为该服务器;当为动 态页面访问请求时,根据上一周期所获取到的当前周期各台服务器动态页面访 问的最优分配权重对当前周期各时刻的动态页面访问进行分配;当时间到达当 前周期最后一时刻时,将下一周期最后一时刻服务器平均预测负载率输入到负 载均衡目标函数中求取最优解,从而得到下一周期各台服务器动态页面访问的 最优分配权重;由上述可知,本发明针对静态页面和动态页面分别提出了不同 的处理方式,这样可以充分利用服务器资源,在复杂的访问形势下依然可以达 到负载均衡的效果。(1) In the present invention, at first for each type of static page access, specify the server to be allocated respectively, and at the same time, the load rate of each server at the last moment of the next cycle corresponds closest to the average predicted load of the server at the last moment of the next cycle Construct a load balancing objective function with the target rate, and set constraints; when receiving a page method request, first classify it, and when it is a static page access request, obtain the type of static page that is requested to be accessed, and then allocate the static page access The designated server to be allocated for this type of static page access that can still provide access services, if the server can no longer provide services, the static page access will be allocated to the server with the smallest load rate at the last moment of the previous period, and the Each type of static page access specifies that the server to be allocated is updated to this server; when it is a dynamic page access request, the optimal allocation weight of each server's dynamic page access in the current cycle obtained in the previous cycle has a significant impact on the current cycle at each moment. Dynamic page access is allocated; when the time reaches the last moment of the current cycle, the average predicted load rate of the server at the last moment of the next cycle is input into the load balancing objective function to obtain the optimal solution, so as to obtain the dynamic status of each server in the next cycle The optimal allocation weight of page access; As can be seen from the above, the present invention proposes different processing methods for static pages and dynamic pages, so that server resources can be fully utilized, and the effect of load balancing can still be achieved under complex access situations.
(2)本发明中,首先针对于每种类型静态页面访问分别指定其所要分配的 服务器,在接收到静态页面访问请求时,获取请求访问的静态页面的类型,然 后将静态页面访问分配至还能提供访问服务的该种类型静态页面访问指定的所 要分配的服务器,若该服务器不能再提供服务,则将静态页面访问分配至上一 周期最后一时刻负载率最小的服务器中,并且将该种类型静态页面访问指定所 要分配的服务器更新为该服务器。本发明充分利用服务器会缓存静态页面这一 特点,首先针对于每种类型静态页面访问分别指定其所要分配的服务器,并且 进行实时更新;当接收到静态页面访问请求时,首先是查找出该类型静态页面 访问指定的其所要分配到的服务器,在该服务器还能够提供服务的情况下,将请求的静态页面访问分配至该服务器,而该服务器由于为该类型静态页面访问 指定的要分配的服务器,所以其很可能已经接收过该静态页面的访问,因此其 很可能还缓存着上一次该静态页面访问时所提供的静态页面,这样可以大大提 高响应速度,提升用户的体验。(2) In the present invention, at first for each type of static page access, specify its server to be allocated respectively, when receiving the static page access request, obtain the type of the static page that requests to visit, then assign the static page access to another This type of static page that can provide access services is accessed to the designated server to be allocated. If the server can no longer provide services, the static page access will be allocated to the server with the smallest load rate at the last moment of the previous cycle, and this type Static page access specifies that the server to be assigned is updated to the server. The present invention makes full use of the feature that the server can cache static pages, and first specifies the server to be allocated for each type of static page access, and performs real-time update; when receiving a static page access request, it first finds out the type Static page access specifies the server to be assigned to it, and if the server is still able to provide services, assign the requested static page access to the server, and the server is assigned to the server for this type of static page access , so it is likely to have received the visit of the static page, so it is likely to cache the static page provided when the static page was visited last time, which can greatly improve the response speed and improve the user experience.
(3)本发明中,每种类型静态页面访问分别指定其所要分配的服务器,并 且记录在哈希表中;对于当前周期各时刻的静态页面访问请求,本发明方法获 取请求访问的静态页面的类型后,通过哈希表查找该种类型静态页面访问指定 的所要分配的服务器。由上述克制,本发明方法可以通过哈希表查找某种类型 静态页面访问指定的所要分配的服务器,提高了查找速率。(3) In the present invention, each type of static page access specifies its server to be allocated respectively, and is recorded in the hash table; After the type, look up the static page of this type through the hash table to access the specified server to be allocated. By above-mentioned restraint, the method of the present invention can search through the hash table the server that certain type of static page access designation will distribute, has improved search rate.
(4)本发明中,当前周期最后一时刻各台服务器的负载率由动态页面负载 量和静态页面负载量总和求出,因此能够更加准确衡量的服务器当前负载情况, 大大提高了负载均衡的效果。(4) In the present invention, the load rate of each server at the last moment of the current cycle is obtained by the sum of the dynamic page load and the static page load, so the current load of the server can be measured more accurately, greatly improving the effect of load balancing .
(5)本发明中,只需要采集到当前周期最后一时刻各台服务器的负载率以 及获取当前周期最后一时刻各台服务器的预测负载率即可预测出下一周期最后 一时刻各台服务器的预测负载率,然后将下一周期最后一时刻服务器平均预测 负载率通过负载均衡目标函数即可得到下一周期各台服务器动态页面访问的最 优分配权重,可见,本发明负载均衡过程中不需要实时的采集各台服务器的负 载率,大大减少了各台服务器负载率的计算量。另外,本发明通过指数平滑预 测法预测下一周期最后一时刻各台服务器的预测负载率;可见,本发明考虑了 负载参数在短时间内可能会有较大波动的情况,相比传统负载均衡方法在处理 负载分配时只是单纯根据实时服务器负载情况进行判断的方式,本发明通过指 数平滑预测法预测下一周期最后一时刻各台服务器负载率的方式,能够进一步 提高了负载均衡的效果。(5) In the present invention, it is only necessary to collect the load rate of each server at the last moment of the current cycle and obtain the predicted load rate of each server at the last moment of the current cycle to predict the load rate of each server at the last moment of the next cycle. Predict the load rate, and then the average predicted load rate of the servers at the last moment of the next cycle can be obtained by the load balancing objective function to obtain the optimal distribution weight of each server dynamic page access in the next cycle. It can be seen that the load balancing process of the present invention does not need The load rate of each server is collected in real time, which greatly reduces the calculation amount of the load rate of each server. In addition, the present invention predicts the predicted load rate of each server at the last moment of the next cycle through the exponential smoothing prediction method; it can be seen that the present invention considers that the load parameters may fluctuate greatly in a short period of time, compared with traditional load balancing The method only judges according to the real-time server load when processing load distribution. The present invention predicts the load rate of each server at the last moment of the next cycle through the exponential smoothing prediction method, which can further improve the effect of load balancing.
(6)本发明中,在客户端和WEB服务器集群之间设置有负载均衡器,负 载均衡器在当前周期最后一时刻分别对应采集各台服务器在该周期最后一时刻 的负载率,即负载均衡器周期性采集WEB服务器集群中各台服务器的负载率; 并且根据采集的当前周期最后一时刻各台服务器的负载率、当前周期最后一时 刻各台服务器的预测负载率以及目标函数最终能够计算得到下一周期各台服务 器动态页面访问的最优分配权重,是一类动态反馈的任务分配策略,能够有效 提高负载均衡效果。(6) In the present invention, a load balancer is arranged between the client and the WEB server cluster, and the load balancer respectively collects the load rate of each server at the last moment of the cycle at the last moment of the current cycle, that is, load balancing The server periodically collects the load rate of each server in the WEB server cluster; and according to the collected load rate of each server at the last moment of the current cycle, the predicted load rate of each server at the last moment of the current cycle, and the objective function can finally be calculated The optimal distribution weight of each server's dynamic page access in the next cycle is a kind of dynamic feedback task distribution strategy, which can effectively improve the load balancing effect.
附图说明Description of drawings
图1是本发明WEB服务器集群的负载均衡方法流程图。FIG. 1 is a flowchart of a load balancing method for a WEB server cluster in the present invention.
图2是本发明WEB服务器集群的负载均衡系统结构框图。Fig. 2 is a structural block diagram of the load balancing system of the WEB server cluster of the present invention.
具体实施方式detailed description
下面结合实施例及附图对本发明作进一步详细的描述,但本发明的实施方 式不限于此。The present invention will be described in further detail below in conjunction with the examples and accompanying drawings, but the embodiments of the present invention are not limited thereto.
实施例Example
本实施例公开了一种WEB服务器集群的负载均衡方法,具体过程如下:This embodiment discloses a load balancing method for a WEB server cluster, and the specific process is as follows:
S1、首先为每种类型静态页面访问分别指定其所要分配的服务器,并且记 录在负载均衡器的哈系表中;其中静态页面按照文件大小进行分类,将一定大 小范围的静态页面定义为一种类型;在本实施例中,按照静态页面文件大小, 将静态页面分类4种类型,其中第一种类型静态页面的文件大小为0~50KB,第 二种类型静态页面的文件大小为51~75KB,第三种类型静态页面的文件大小为 76~100KB;第四种类型静态页面的文件大小为大于100KB。S1. First, specify the server to be allocated for each type of static page access, and record it in the hash table of the load balancer; among them, static pages are classified according to file size, and static pages of a certain size range are defined as one Type; in this embodiment, according to the size of the static page file, the static page is classified into 4 types, wherein the file size of the first type of static page is 0-50KB, and the file size of the second type of static page is 51-75KB , the file size of the third type of static page is 76-100KB; the file size of the fourth type of static page is larger than 100KB.
同时,以下一周期最后一时刻各台服务器的负载率对应最接近于下一周期 最后一时刻服务器平均预测负载率为目标构建负载均衡目标函数,通过目标函 数求解下一周期各台服务器动态页面访问的最优分配权重;并且构建负载均衡 目标函数的约束条件,包括:下一周期最后一时刻各台服务器负载率小于一定 值以及下一周期各台服务器动态页面访问分配权重之和为1;At the same time, the load rate of each server at the last moment of the next period corresponds closest to the target average predicted load rate of the server at the last moment of the next period. Build a load balancing objective function, and use the objective function to solve the dynamic page access of each server in the next period. The optimal allocation weights; and construct the constraints of the load balancing objective function, including: the load rate of each server is less than a certain value at the last moment of the next cycle and the sum of the dynamic page access allocation weights of each server in the next cycle is 1;
其中本实施例的下一周期是指当前周期的下一个周期;Wherein the next cycle in this embodiment refers to the next cycle of the current cycle;
针对于当前周期各时刻接收的客户端所提出的页面访问请求,进行如下处 理:For the page access request received from the client at each moment of the current cycle, the following processing is performed:
S2、在当前周期各时刻接收到客户端所提出的页面访问请求时,首先对请 求访问的页面进行分类,若为动态页面,则进行步骤S4的处理;若为静态页面, 则进行步骤S3的处理;同时在本实施例中,当时间到达当前周期最后一时刻时, 采集当前周期最后一时刻各台服务器的负载率,并且计算下一周期各台服务器 动态页面访问的最优分配权重,具体过程如下:首先根据当前周期最后一时刻 各台服务器的负载率及上一周期最后一时刻所预测得到的当前周期最后一时刻 各台服务器的预测负载率预测下一周期最后一时刻各台服务器的预测负载率, 然后求均值得到下一周期最后一时刻服务器平均预测负载率,最后将下一周期 最后一时刻服务器平均预测负载率输入步骤S1中构建的负载均衡目标函数中求取最优解,从而得到下一周期各台服务器动态页面访问的最优分配权重;当下 一周期到来时,返回本步骤;在本实施例中,针对于第一个周期各时刻的动态 页面访问请求,设置该周期各台服务器动态页面访问的最优分配权重相同。即 w1(1)=w2(1),…,=wn(1)。S2, when receiving the page access request proposed by the client at each moment of the current cycle, first classify the page requested to be accessed, if it is a dynamic page, then proceed to step S4; if it is a static page, then proceed to step S3 Processing; at the same time in this embodiment, when the time reaches the last moment of the current cycle, the load rate of each server at the last moment of the current cycle is collected, and the optimal distribution weight of each server dynamic page access in the next cycle is calculated, specifically The process is as follows: First, predict the load rate of each server at the last moment of the next cycle based on the load rate of each server at the last moment of the current cycle and the predicted load rate of each server at the last moment of the previous cycle. Predict the load rate, then calculate the average value to obtain the average predicted load rate of the server at the last moment of the next cycle, and finally input the average predicted load rate of the server at the last moment of the next cycle into the load balancing objective function constructed in step S1 to obtain the optimal solution, Thereby obtain the optimal distribution weight of each server dynamic page access in the next cycle; When the next cycle arrives, return to this step; In this embodiment, the cycle is set for the dynamic page access requests at each moment of the first cycle The optimal allocation weights of each server's dynamic page access are the same. That is, w 1 (1)=w 2 (1), . . . ,=w n (1).
其中各台服务器当前周期最后一时刻的负载率由各台服务器自身计算出来, 本实施例周期性的采集各台服务器的负载率,即本实施例中分别在每个周期的 最后一时刻采集各台服务器的负载率。本实施例中当前请求访问的页面文件是 以.html结尾的,则将该页面定义为静态页面,当前请求访问的页面文件是以.jsp 结尾的,则将该页面定义为动态页面。The load rate of each server at the last moment of the current cycle is calculated by each server itself, and this embodiment periodically collects the load rate of each server, that is, in this embodiment, each The load rate of the server. In the present embodiment, if the page file of the current request to visit ends with .html, then the page is defined as a static page, and if the page file of the current request to visit ends with .jsp, then the page is defined as a dynamic page.
S3、针对于当前周期各时刻的静态页面访问请求,首先获取请求访问的静 态页面的类型,然后查找该种类型静态页面访问指定的所要分配的服务器,并 且判断该服务器当前是否还能对页面访问提供服务,若是,则将静态页面访问 分配至该服务器;若否,则将静态页面访问分配至WEB服务器集群中上一周期 最后一时刻负载率最小的服务器中,并且将该种类型静态页面访问指定所要分 配的服务器更新为该服务器;其中通过对比上一周期最后一时刻各台服务器的 负载率,即可获取到其中负载率最小的服务器;另外服务器在接收到静态页面 访问时,首先是否缓存有该静态页面,若否,则从磁盘中读取。本实施例中通过检测服务器所承受的负载是否解决其最大处理能力来判断服务器是否还还能 对页面访问提供服务。S3. For the static page access requests at each moment of the current cycle, first obtain the type of the static page that is requested to be accessed, and then search for the server to be assigned for this type of static page access, and determine whether the server can currently access the page Provide services, if so, assign the static page access to the server; if not, assign the static page access to the server with the smallest load rate at the last moment of the last cycle in the WEB server cluster, and assign this type of static page access Specify that the server to be allocated is updated to this server; the server with the smallest load rate can be obtained by comparing the load rate of each server at the last moment of the previous cycle; in addition, when the server receives a static page access, whether to cache first If there is this static page, if not, it will be read from disk. In this embodiment, it is judged whether the server can also provide services for page access by detecting whether the load borne by the server solves its maximum processing capacity.
S4、针对于当前周期各时刻的动态页面访问请求,根据上一周期最后一时 刻所获取到的当前周期各台服务器动态页面访问的最优分配权重对当前周期各 时刻的动态页面访问进行分配。S4. For the dynamic page access requests at each moment of the current cycle, the dynamic page access at each moment of the current cycle is allocated according to the optimal distribution weight of the dynamic page access of each server in the current cycle obtained at the last moment of the previous cycle.
本实施例上述步骤S2中,当前周期各个时刻各台服务器的负载率计算公式 为:In the above-mentioned step S2 of the present embodiment, the calculation formula of the load rate of each server at each moment of the current cycle is:
其中Ri(t)为当前周期t时刻第i台服务器的负载率,为当前周期t时刻第 i台服务器要处理的静态页面负载量,为当前周期t时刻第i台服务器要处理 的动态页面负载量,Ci为第i台服务器的最大处理能力;其中当t取(k-1)T时, 通过上式计算得到当前周期即第(k-1)个周期最后一时刻(k-1)T时刻第i台服务 器的负载率,k=2,3,...;Where R i (t) is the load rate of the i-th server at time t of the current period, is the static page load to be processed by the i-th server at time t of the current period, is the dynamic page load to be processed by the i-th server at time t in the current cycle, and C i is the maximum processing capacity of the i-th server; when t is (k-1)T, the current cycle is calculated by the above formula (k-1) The load rate of the i-th server at the last moment (k-1)T of the cycle, k=2,3,...;
其中当前周期各时刻各台服务器要处理的静态页面负载量计算公式为:The formula for calculating the static page load to be processed by each server at each moment in the current cycle is:
其中ci,1(t),ci,2(t),…ci,j(t)分别对应为当前周期t时刻第i台服务器持有的第1,2,…,j类静态文件访问数量;是访问第j类静态页面产生的负载,Sj为 第j类静态页面的大小,λ是读取静态页面文件及处理发送的资源使用率系数,T 为周期长度;当t取(k-1)T时,通过上式计算得到当前周期即第(k-1)个周期最 后一时刻(k-1)T时刻第i台服务器要处理的静态页面负载量 Among them, c i,1 (t), c i,2 (t), ... c i, j (t) respectively correspond to the first, second, ..., j-type static files held by the i-th server at the moment of the current cycle t number of visits; is the load generated by accessing the jth type of static page, S j is the size of the jth type of static page, λ is the resource utilization coefficient for reading the static page file and processing and sending, T is the cycle length; when t is taken as (k-1 )T, the static page load to be processed by the i-th server at the last moment (k-1)T of the current period (k-1)th period is calculated by the above formula
其中读取静态页面文件及处理发送的资源使用率系数λ取值如下:Among them, the value of the resource utilization coefficient λ for reading static page files and processing and sending is as follows:
当服务器从磁盘中读静态页面文件及处理时,取λ=λ1,λ1为服务器从磁盘 中读静态页面文件及处理发送的资源使用率系数,When the server reads the static page file from the disk and processes it, take λ=λ 1 , where λ 1 is the resource utilization coefficient for the server to read the static page file from the disk and process it,
当服务器从缓存中读静态页面文件及处理时,取λ=λ2;λ2为服务器从缓存 中读静态页面文件及处理发送的资源使用率系数;When the server reads the static page file and processes it from the cache, get λ=λ 2 ; λ 2 is the resource utilization coefficient that the server reads the static page file from the cache and processes and sends it;
其中λ1>λ2。where λ 1 >λ 2 .
当前周期各时刻各台服务器要处理的动态页面负载量计算公式为:The formula for calculating the dynamic page load to be processed by each server at each moment in the current cycle is:
其中为当前周期t时刻前第i台服务器未完成动态页面负载量,Mi为第i 台服务器生成动态页面的性能常数,wi(k-1)为上一周期所获取到的当前周期即 第(k-1)个周期第i台服务器动态页面访问的最优分配权重;为当前周期t时 刻需要缓冲与转发至第i台服务器的动态页面访问数量,为当前周期t时刻 对应个动态页面访问数量在第i台服务器产生的负载量;当t取(k-1)T时, 通过上式计算得到当前周期即第(k-1)个周期最后一时刻(k-1)T时刻第i台服务 器要处理的动态页面负载量即:in is the uncompleted dynamic page load of the i-th server before time t in the current cycle, M i is the performance constant of the dynamic page generated by the i-th server, w i (k-1) is the current cycle obtained in the previous cycle, i.e. the (k-1) The optimal allocation weight of the i-th server's dynamic page access in the cycle; is the number of dynamic page visits that need to be buffered and forwarded to the i-th server at time t of the current period, Corresponding to time t of the current cycle The number of dynamic page visits is the load generated by the i server; when t is (k-1)T, the current cycle is calculated by the above formula, that is, the last moment (k-1) of the (k-1)th cycle The amount of dynamic page load to be processed by the i-th server at time T which is:
得到当前周期最后一时刻各台服务器的负载率为:Get the load rate of each server at the last moment of the current cycle:
其中Ri((k-1)T)为当前周期即第(k-1)个周期最后一时刻(k-1)T时刻第i 台服务器的负载率;Wherein R i ((k-1)T) is the load rate of the i-th server at the last moment (k-1)T of the current cycle, that is, the (k-1)th cycle;
本实施例中,第i台服务器的最大处理能力Ci为:In this embodiment, the maximum processing capacity Ci of the i -th server is:
其中k1~k4各指标对服务器最大处理能力的影响系数,在本实施例中k1~k4的值分别为0.2、0.3、0、0.5;μi为第i台服务器CPU数量,fi第i台服务器CPU频 率,Gi为第i台服务器的内存容量,Di为第i台服务器的I/O速率,Ni为第i台服务 器的网络吞吐量。Among them, the influence coefficients of the indicators k 1 to k 4 on the maximum processing capacity of the server, in this embodiment, the values of k 1 to k 4 are 0.2, 0.3, 0, and 0.5 respectively; μ i is the number of CPUs of the i-th server, f i The CPU frequency of the i-th server, G i is the memory capacity of the i-th server, D i is the I/O rate of the i-th server, N i is the network throughput of the i-th server.
本实施例上述步骤S2中,根据当前周期最后一时刻各台服务器的负载率及 其上一周期最后一时刻所预测的当前周期最后一时刻各台服务器的预测负载率, 通过指数平滑预测法预测下一周期最后一时刻各台服务器的预测负载率:In the above step S2 of this embodiment, according to the load rate of each server at the last moment of the current cycle and the predicted load rate of each server at the last moment of the current cycle predicted at the last moment of the previous cycle, it is predicted by the exponential smoothing prediction method The predicted load rate of each server at the last moment of the next cycle:
其中Ri((k-1)T)为当前周期即第(k-1)个周期最后一时刻(k-1)T时刻第i台 服务器的负载率,为当前周期即第(k-1)个周期的上一周期即第k-2个 周期最后一时刻所预测得到的当前周期即第(k-1)个周期最后一时刻(k-1)T时 刻各台服务器的预测负载率,为下一周期即第k个周期最后一时刻kT时刻 第i台服务器的预测负载率;α为平滑系数,其中α越小,平滑作用越强,在本 实施中α为0.2;其中当前周期为第一个周期时,由于不存在第一周期最后一时 刻各台服务器的预测负载率,因此将第一个周期最后一时刻各台服务器的负载 率作为第二周期最后一时刻各台服务器的预测负载率,即当k=2时, Where R i ((k-1)T) is the load rate of the i-th server at the last moment (k-1)T of the current period (k-1)th period, The last moment (k-1)T of the current period (k-1)th period predicted by the last period of the current period (k-1)th period, i.e. the last moment of the k-2th period The predicted load rate of each server at time, is the predicted load rate of the i-th server at time kT at the last moment of the next cycle, that is, the kth cycle; α is the smoothing coefficient, and the smaller α is, the stronger the smoothing effect is. In this implementation, α is 0.2; the current cycle is In the first period, since there is no predicted load rate of each server at the last moment of the first period, the load rate of each server at the last moment of the first period is taken as the forecast of each server at the last moment of the second period Load rate, that is, when k=2,
根据下一周期最后一时刻各台服务器的预测负载率求取下一周期最后一时 刻服务器平均预测负载率:According to the predicted load rate of each server at the last moment of the next cycle, the average predicted load rate of the server at the last moment of the next cycle is obtained:
其中为下一周期即第k个周期最后一时刻kT时刻服务器平均预测负 载率;n为WEB服务器集群中服务器的总台数。in It is the average predicted load rate of the server at kT time at the last moment of the next period, that is, the kth period; n is the total number of servers in the WEB server cluster.
本实施例上述步骤S1中构建的负载均衡目标函数为:The load balancing objective function constructed in the above step S1 of this embodiment is:
构建的负载均衡目标函数的约束条件为:The constraints of the constructed load balancing objective function are:
Ri(kT)≤0.9,i=1,2,3,...n;R i (kT)≤0.9, i=1,2,3,...n;
其中Ri(kT)为下一周期即第k个周期最后一时刻kT的各台服务器的负载率,为下一周期即第k个周期最后一时刻服务器平均预测负载率,n为WEB服 务器集群服务器的总台数;wi(k)为下一周即第k个周期第i台服务器动态页面访 问的最优分配权重,其中i=1,2,...n;T为周期长度。其中各台服务器各周期各时 刻的负载率应该低于0.9,若超过0.9,说明服务器承受的负载量接近饱和,不应 该对该服务器再分配请求任务。Among them, R i (kT) is the load rate of each server at kT at the last moment of the k-th cycle in the next cycle, is the average predicted load rate of the server at the last moment of the next cycle, that is, the kth cycle, n is the total number of WEB server cluster servers; Optimal distribution of weights, where i=1,2,...n; T is the cycle length. The load rate of each server at each period and time should be lower than 0.9. If it exceeds 0.9, it means that the load on the server is close to saturation, and the request task should not be allocated to the server.
本实施例步骤S2中通过柯西不等式和穷举法求得负载均衡目标函数中的最 优解,即最优分配权重。具体如下:In step S2 of this embodiment, the optimal solution in the load balancing objective function, that is, the optimal distribution weight, is obtained through Cauchy's inequality and exhaustive method. details as follows:
对于上述负载均衡目标函数,根据柯西不等式可得:For the above load balancing objective function, according to Cauchy's inequality:
当且仅当即在下一周期第k个周期最后一时刻各台服务器负载率相等时,等号成立,此时 f(w1(kT),…,wn(kT))取得最小值,可得方程组:if and only if That is, when the load rates of all servers are equal at the last moment of the k-th cycle in the next cycle, the equal sign is established. At this time, f(w 1 (kT),…,w n (kT)) obtains the minimum value, and the equations can be obtained:
利用上式可求出下一周期第k个周期第i台服务器的最优分配权重wi(k);不 存在符合条件的解,需通过实验找到合适的wi(k)使得目标函数尽可能小。Using the above formula, the optimal allocation weight w i (k) of the i-th server in the k-th cycle of the next cycle can be obtained; there is no qualified solution, and it is necessary to find a suitable w i (k) through experiments so that the objective function can Possibly small.
本实施例还公开了一种用于实现上述负载均衡方法的WEB服务器集群的负 载均衡系统,如图2所示,包括客户端、负载均衡器和WEB服务器集群,WEB 服务器集群包括多台服务器,分别为服务器1,服务器2,…,服务器n,即第1 台服务器至第n台服务器;负载均衡器设置在客户端和WEB服务器集群之间;其 中:This embodiment also discloses a load balancing system of a WEB server cluster for realizing the above load balancing method, as shown in Figure 2, including a client, a load balancer and a WEB server cluster, and the WEB server cluster includes multiple servers, They are server 1, server 2, ..., server n, that is, the first server to the nth server; the load balancer is set between the client and the WEB server cluster; where:
客户端,用于通过互联网向负载均衡器发送页面访问请求;The client is used to send a page access request to the load balancer through the Internet;
负载均衡器,用于为每种类型静态页面访问分别指定其所要分配的服务器; 用于构建负载均衡目标函数及约束条件;所述负载均衡目标函数以下一周期最 后一时刻各台服务器的负载率对应最接近于下一周期最后一时刻服务器平均预 测负载率为目标,所述约束条件包括下一周期最后一时刻各台服务器负载率小 于一定值以及下一周期各台服务器动态页面访问分配权重之和为1;The load balancer is used to specify the server to be allocated for each type of static page access; it is used to construct the load balancing objective function and constraints; the load balancing objective function is the load rate of each server at the last moment of the next cycle Corresponding to the target that is closest to the average predicted load rate of the server at the last moment of the next cycle, the constraints include the load rate of each server at the last moment of the next cycle being less than a certain value and the dynamic page access allocation weight of each server in the next cycle sum to 1;
用于接收当前周期各时刻客户端所提出的页面访问请求,在接收到页面访 问请求后,首先对请求访问的页面进行分类;若为静态页面,首先获取请求访 问的静态页面的类型,然后查找该种类型静态页面访问指定的所要分配的服务 器,并且判断该服务器当前是否还能对页面访问提供服务,若是,则将静态页 面访问分配至该服务器;若否,则将静态页面访问分配至WEB服务器集群中上 一周期最后一时刻负载率最小的服务器中,并且将该种类型静态页面访问指定 所要分配的服务器更新为该服务器;若为动态页面,根据上一周期最后一时刻 所获取到的当前周期各台服务器动态页面访问的最优分配权重对当前周期各时 刻的动态页面访问进行分配;It is used to receive the page access request from the client at each moment of the current cycle. After receiving the page access request, first classify the page that is requested to be accessed; if it is a static page, first obtain the type of the static page that is requested to be accessed, and then search This type of static page access specifies the server to be allocated, and judges whether the server can currently provide services for page access. If so, assign the static page access to the server; if not, assign the static page access to the WEB In the server cluster, the server with the smallest load rate at the last moment of the previous cycle, and the server to be allocated for this type of static page access is updated to this server; if it is a dynamic page, according to the obtained at the last moment of the previous cycle The optimal allocation weight of each server's dynamic page access in the current cycle is used to allocate the dynamic page access at each moment in the current cycle;
用于当时间到达当前周期最后一时刻时,采集WEB服务器集群中当前周期最后 一时刻各台服务器的负载率;即负载均衡器周期性采集各台服务器的负载率, 本实施例中负载均衡器在各周期的最后一时刻采集WEB服务器集群中各台服务 器的负载率,采集的即是各周期最后一时刻各台服务器的负载率;It is used to collect the load rate of each server at the last moment of the current cycle in the WEB server cluster when the time reaches the last moment of the current cycle; that is, the load balancer periodically collects the load rate of each server. In this embodiment, the load balancer Collect the load rate of each server in the WEB server cluster at the last moment of each cycle, and what is collected is the load rate of each server at the last moment of each cycle;
用于当时间到达当前周期最后一时刻时,计算下一周期各台服务器动态页 面访问的最优分配权重,具体过程如下:首先根据当前周期最后一时刻各台服 务器的负载率及上一周期最后一时刻所预当前周期最后一时刻测得到的当前周 期最后一时刻各台服务器的预测负载率,预测下一周期最后一时刻各台服务器 的预测负载率,然后求均值得到下一周期最后一时刻服务器平均预测负载率, 最后将下一周期最后一时刻服务器平均预测负载率输入负载均衡目标函数中求 取最优解,从而得到下一周期各台服务器动态页面访问的最优分配权重;When the time reaches the last moment of the current period, it is used to calculate the optimal distribution weight of each server's dynamic page access in the next period. The specific process is as follows: first, according to the load rate of each server at the last moment of the current period and the last period of the previous period Predict the predicted load rate of each server at the last moment of the current cycle measured at the last moment of the current cycle at one moment, predict the predicted load rate of each server at the last moment of the next cycle, and then calculate the average value to obtain the last moment of the next cycle The average predicted load rate of the server, and finally input the average predicted load rate of the server at the last moment of the next cycle into the load balancing objective function to find the optimal solution, so as to obtain the optimal distribution weight of the dynamic page access of each server in the next cycle;
WEB服务器集群中的各台服务器,用于当时间到达当前周期最后一时刻, 对应计算各台服务器的负载率,供负载均衡器进行周期性的采集;用于接收负 载均衡器分配至其中的静态页面访问和动态页面访问;用于根据分配到其中的 静态页面访问和动态页面访问向客户端响应相应的服务。Each server in the WEB server cluster is used to calculate the load rate of each server when the time reaches the last moment of the current cycle, for the load balancer to collect periodically; it is used to receive the static data allocated to it by the load balancer Page access and dynamic page access; used to respond to the corresponding service to the client according to the static page access and dynamic page access assigned thereto.
上述实施例为本发明较佳的实施方式,但本发明的实施方式并不受上述实 施例的限制,其他的任何未背离本发明的精神实质与原理下所作的改变、修饰、 替代、组合、简化,均应为等效的置换方式,都包含在本发明的保护范围之内。The above-mentioned embodiment is a preferred embodiment of the present invention, but the embodiment of the present invention is not limited by the above-mentioned embodiment, and any other changes, modifications, substitutions, combinations, Simplifications should be equivalent replacement methods, and all are included in the protection scope of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710680742.7A CN107426332B (en) | 2017-08-10 | 2017-08-10 | A load balancing method and system for a WEB server cluster |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710680742.7A CN107426332B (en) | 2017-08-10 | 2017-08-10 | A load balancing method and system for a WEB server cluster |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107426332A true CN107426332A (en) | 2017-12-01 |
CN107426332B CN107426332B (en) | 2019-08-20 |
Family
ID=60437790
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710680742.7A Active CN107426332B (en) | 2017-08-10 | 2017-08-10 | A load balancing method and system for a WEB server cluster |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107426332B (en) |
Cited By (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108173937A (en) * | 2017-12-28 | 2018-06-15 | 北京中电普华信息技术有限公司 | Access control method and device |
CN108632384A (en) * | 2018-05-15 | 2018-10-09 | 西安电子科技大学 | Load-balancing method based on the prediction of video request number |
CN109388657A (en) * | 2018-09-10 | 2019-02-26 | 平安科技(深圳)有限公司 | Data processing method, device, computer equipment and storage medium |
CN109446088A (en) * | 2018-10-29 | 2019-03-08 | 新华三技术有限公司 | A kind of method and device for business processing |
CN109831524A (en) * | 2019-03-11 | 2019-05-31 | 平安科技(深圳)有限公司 | A kind of load balance process method and device |
CN110020061A (en) * | 2018-08-21 | 2019-07-16 | 广州市城市规划勘测设计研究院 | A kind of smart city space time information cloud platform service-Engine |
CN111182011A (en) * | 2018-11-09 | 2020-05-19 | 中移(杭州)信息技术有限公司 | A service set allocation method and device |
CN111611067A (en) * | 2019-02-22 | 2020-09-01 | 顺丰科技有限公司 | Load balancing method and device and block chain system |
CN111984868A (en) * | 2020-08-21 | 2020-11-24 | 上海二三四五网络科技有限公司 | Method and device for controlling webpage browsing in browser |
CN112835698A (en) * | 2021-02-09 | 2021-05-25 | 北京工业大学 | A Dynamic Load Balancing Method Based on Heterogeneous Cluster Request Classification Processing |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080222267A1 (en) * | 2007-03-09 | 2008-09-11 | Horn Ray C | Method and system for web cluster server |
CN104102952A (en) * | 2014-06-17 | 2014-10-15 | 国家电网公司 | Load optimal configuration method based on power grid operation efficiency |
CN104994156A (en) * | 2015-07-01 | 2015-10-21 | 北京京东尚科信息技术有限公司 | Load balancing method and system for cluster |
CN106210019A (en) * | 2016-07-04 | 2016-12-07 | 安徽天达网络科技有限公司 | A kind of large-scale height concurrent WEB application system |
-
2017
- 2017-08-10 CN CN201710680742.7A patent/CN107426332B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20080222267A1 (en) * | 2007-03-09 | 2008-09-11 | Horn Ray C | Method and system for web cluster server |
CN104102952A (en) * | 2014-06-17 | 2014-10-15 | 国家电网公司 | Load optimal configuration method based on power grid operation efficiency |
CN104994156A (en) * | 2015-07-01 | 2015-10-21 | 北京京东尚科信息技术有限公司 | Load balancing method and system for cluster |
CN106210019A (en) * | 2016-07-04 | 2016-12-07 | 安徽天达网络科技有限公司 | A kind of large-scale height concurrent WEB application system |
Non-Patent Citations (2)
Title |
---|
王超,等: "基于LVS的数据库集群负载均衡性能测试与分析", 《微型机与应用》 * |
黄倩: "web集群负载均衡系统的设计与实现", 《万方学术论文数据库》 * |
Cited By (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108173937A (en) * | 2017-12-28 | 2018-06-15 | 北京中电普华信息技术有限公司 | Access control method and device |
CN108632384A (en) * | 2018-05-15 | 2018-10-09 | 西安电子科技大学 | Load-balancing method based on the prediction of video request number |
CN110020061A (en) * | 2018-08-21 | 2019-07-16 | 广州市城市规划勘测设计研究院 | A kind of smart city space time information cloud platform service-Engine |
CN109388657A (en) * | 2018-09-10 | 2019-02-26 | 平安科技(深圳)有限公司 | Data processing method, device, computer equipment and storage medium |
CN109388657B (en) * | 2018-09-10 | 2023-08-08 | 平安科技(深圳)有限公司 | Data processing method, device, computer equipment and storage medium |
CN109446088A (en) * | 2018-10-29 | 2019-03-08 | 新华三技术有限公司 | A kind of method and device for business processing |
CN111182011A (en) * | 2018-11-09 | 2020-05-19 | 中移(杭州)信息技术有限公司 | A service set allocation method and device |
CN111182011B (en) * | 2018-11-09 | 2022-06-10 | 中移(杭州)信息技术有限公司 | Service set distribution method and device |
CN111611067A (en) * | 2019-02-22 | 2020-09-01 | 顺丰科技有限公司 | Load balancing method and device and block chain system |
CN111611067B (en) * | 2019-02-22 | 2024-06-14 | 顺丰科技有限公司 | Load balancing method, device and blockchain system |
CN109831524B (en) * | 2019-03-11 | 2023-04-18 | 平安科技(深圳)有限公司 | Load balancing processing method and device |
CN109831524A (en) * | 2019-03-11 | 2019-05-31 | 平安科技(深圳)有限公司 | A kind of load balance process method and device |
CN111984868A (en) * | 2020-08-21 | 2020-11-24 | 上海二三四五网络科技有限公司 | Method and device for controlling webpage browsing in browser |
CN112835698A (en) * | 2021-02-09 | 2021-05-25 | 北京工业大学 | A Dynamic Load Balancing Method Based on Heterogeneous Cluster Request Classification Processing |
CN112835698B (en) * | 2021-02-09 | 2024-09-20 | 北京工业大学 | Dynamic load balancing method for request classification processing based on heterogeneous clusters |
Also Published As
Publication number | Publication date |
---|---|
CN107426332B (en) | 2019-08-20 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107426332B (en) | A load balancing method and system for a WEB server cluster | |
CN112835698B (en) | Dynamic load balancing method for request classification processing based on heterogeneous clusters | |
CN110149395A (en) | One kind is based on dynamic load balancing method in the case of mass small documents high concurrent | |
CN102624922B (en) | Method for balancing load of network GIS heterogeneous cluster server | |
CN110933139A (en) | A system and method for solving high concurrency of web server | |
WO2025055413A1 (en) | Dynamic adaptive client load balancing method and system for microservices | |
CN107832153A (en) | A kind of Hadoop cluster resources self-adapting distribution method | |
CN108111586A (en) | The web cluster system and method that a kind of high concurrent is supported | |
CN104994156A (en) | Load balancing method and system for cluster | |
CN109783235A (en) | A kind of load equilibration scheduling method based on principle of maximum entropy | |
CN115801896B (en) | Computing power network node allocation method, device, electronic device and storage medium | |
CN108733475A (en) | A kind of dynamical feedback dispatching method | |
CN102045396A (en) | Load balancing method of server document | |
CN110708256A (en) | CDN scheduling method, device, network device and storage medium | |
CN115884094B (en) | Multi-scene cooperation optimization caching method based on edge calculation | |
CN108255427B (en) | Data storage and dynamic migration method and device | |
Tu et al. | An optimized cluster storage method for real-time big data in Internet of Things | |
CN102480502A (en) | I/O load balancing method and I/O server | |
CN102081624A (en) | Data inquiring method and data inquiring server | |
CN113377544A (en) | Web cluster load balancing method based on load data dynamic update rate | |
US7721295B2 (en) | Execution multiplicity control system, and method and program for controlling the same | |
CN118605886A (en) | Container application deployment method, device, electronic device and storage medium | |
CN106888237B (en) | A data scheduling method and system | |
CN116489096A (en) | A Gateway Load Balancing Algorithm Optimization Method | |
CN115314500A (en) | Dynamic load balancing method based on improved TOPSIS model |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |