A load balancing method, device, electronic device and storage medium
By adjusting the distribution of the consistent hash ring and using the weight table and service data to evenly distribute the service load, the problem of unbalanced load of each server in the distributed monitoring system is solved, and the system performance and stability are improved.
Patent Information
- Application Number
- CN202011025750.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-25
- Publication Date
- 2025-06-20
- Estimated Expiration
- 2040-09-25
AI Technical Summary
In the security monitoring business scenario, the service load pressure of each server in the distributed monitoring system is unbalanced, resulting in unstable system performance.
By obtaining the preset weight table and service data within the preset time period, the distribution of the consistent hash ring is adjusted so that the service load pressure is evenly distributed among the servers of the monitoring system.
It realizes the load balancing performance of distributed monitoring systems in the security monitoring business scenario, ensures the balance of business load pressure of each server, and improves the overall performance and stability of the system.
Smart Images

Figure CN114339135B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the technical field of video surveillance, and in particular, to a load balancing method, device, electronic device, and storage medium. Background Art
[0002] With the widespread application of video surveillance technology in various industries, the number of deployed monitoring devices such as cameras and the number of accessing customers have increased exponentially. Traditional single-machine servers can no longer meet the requirements, and the solution of distributed deployment of servers has gradually become the mainstream solution for building a monitoring background. When a user accesses a server in a distributed monitoring system, a load balancing server is required to distribute tasks according to certain rules (such as load balancing rules).
[0003] In the load balancing server of a distributed system, an important indicator is to ensure load balancing while maintaining the timing consistency of the same access device (such as a camera) (it is necessary to ensure the order of tasks received by the access device, and it is required that requests sent to the access device on the network are sent in sequence by the same server). Currently, the commonly used method for timing consistency is mainly: through the consistent hashing algorithm, virtual nodes associated with physical nodes (i.e., servers) are placed on the hash ring. Among them, the virtual nodes and physical nodes correspond in the hash space, and one physical node corresponds to several virtual nodes. Then, the hash value is obtained based on the access device code in the client operation request, and the corresponding server is matched on the hash ring according to the obtained hash value. Since the device code of each access device is unchanged, when the client requests this device, the calculated hash value is unchanged, so that the matched virtual node is also unchanged. Therefore, operation requests for the same access device will only be processed by the same server, ensuring the timing consistency of the request operations. At the same time, the access device and the server are bound through an algorithm, and the number of devices bound to each server is made uniform to ensure load balancing.
[0004] In the actual use process of the monitoring system, the usage frequency of each access device and the performance consumption of different services are different, resulting in different business load pressures on each server in the monitoring system in actual situations, that is, true business load balancing has not been achieved. Summary of the Invention
[0005] The embodiments of the present application provide a load balancing method, device, electronic device, and storage medium to achieve the effect of improving the load balancing performance of a distributed monitoring system in the security monitoring business scenario.
[0006] In a first aspect, the embodiments of the present application provide a load balancing method, including:
[0007] In response to a load balancing trigger operation, obtain a pre-set weight table; wherein, the weight table includes service types and the weights corresponding to different requirements for each service type;
[0008] Obtain service data within a preset time period; wherein, the service data includes the types of services triggered within the preset time period and the number of times each type of service is triggered;
[0009] Based on the weight table and the service data, adjust the consistent hashing ring distribution so that the service load pressure is evenly distributed among the servers of the monitoring system.
[0010] In a second aspect, an embodiment of the present application provides a load balancing device, including:
[0011] A weight table acquisition module, configured to obtain a pre-set weight table in response to a load balancing trigger operation; wherein, the weight table includes service types and the weights corresponding to different requirements for each service type;
[0012] A service data acquisition module, configured to obtain service data within a preset time period; wherein, the service data includes the types of services triggered within the preset time period and the number of times each type of service is triggered;
[0013] An equalization module, configured to adjust the consistent hashing ring distribution based on the weight table and the service data so that the service load pressure is evenly distributed among the servers of the monitoring system.
[0014] In a third aspect, an embodiment of the present application further provides an electronic device, including:
[0015] One or more processors;
[0016] A storage device, configured to store one or more programs,
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the load balancing method according to any embodiment of the present application.
[0018] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the load balancing method according to any embodiment of the present application is implemented.
[0019] In the embodiments of the present application, based on the weight table obtained, which includes service types and the weights of different requirements corresponding to each service type, and the service data within a preset time period, the service load pressure of each server can be analyzed. Furthermore, by adjusting the distribution of the consistent hashing ring, the service load pressure can be evenly distributed among the servers in the monitoring system, thereby solving the problem of uneven service load pressure among the servers in the system caused by the different usage frequencies of each access device and the different performance consumptions of different services. Description of the Drawings
[0020] Figure 1a is a schematic structural diagram of the distributed monitoring system in the embodiments of the present application;
[0021] Figure 1b is a schematic flowchart of the load balancing method according to the first embodiment of the present application;
[0022] Figure 1c is a schematic diagram of the consistent hashing ring according to the first embodiment of the present application;
[0023] Figure 2 is a schematic flowchart of the load balancing method according to the second embodiment of the present application;
[0024] Figure 3 is a schematic flowchart of the load balancing method according to the third embodiment of the present application;
[0025] Figure 4 is a schematic structural diagram of the load balancing device according to the fourth embodiment of the present application;
[0026] Figure 5 is a schematic structural diagram of the electronic device according to the fifth embodiment of the present application. Detailed Embodiments
[0027] The present application will be further described in detail below with reference to the drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present application, rather than limiting the present application. Additionally, it should be noted that for the sake of description, only the parts related to the present application are shown in the drawings, rather than all the structures.
[0028] Figure 1a is a schematic structural diagram of the distributed monitoring system in the embodiments of the present application. Refer to Figure 1a, the monitoring system includes a load balancing server for controlling the system load balance, and multiple servers for processing service requests. Multiple access devices are pre-bound under each server. Among them, the load balancing server usually uses the consistent hashing algorithm to achieve the system load balance; the access device can be a camera or an NVR (Network Video Recorder) device. The NVR device is the storage and forwarding part of the network video monitoring system. The NVR device works in cooperation with the video encoder or network camera to complete the functions of video storage and forwarding.
[0029] Figure 1b FIG. 4 is a flowchart of the load balancing method according to the first embodiment of the present application. This embodiment is applicable to the situation of balancing the service load pressure of each server in a distributed monitoring system. This method can be executed by a load balancing device, which can be implemented in software and / or hardware, and can be integrated in an electronic device. The electronic device can be, optionally, the load balancing server in the monitoring system.
[0030] As Figure 1b shown, the load balancing method specifically includes the following processes:
[0031] S101. In response to a load balancing trigger operation, obtain a pre-set weight table.
[0032] In the embodiment of the present application, after the load balancing server is started, it first implements basic client task distribution according to the normal consistent hashing algorithm. Only when a load balancing trigger operation is detected, the load balancing method of the present application is executed. Among them, the load balancing trigger operation can be, optionally, a timing operation or an operation actively triggered by a user (such as a click operation). The weight table includes service types and the weights corresponding to different requirements for each service type. Among them, different requirements include performance requirements, service real-time requirements, and device attention requirements; and the weights are used to quantitatively represent the impact of requirements such as service performance requirements, service real-time requirements, and device attention on the actual service pressure of the system.
[0033] Among them, the performance requirements mainly refer to the situation of resources such as CPU and memory of the server consumed by the business. The judgment standard of the performance requirements is the number of services that the server can execute and complete within a fixed time period (i.e., the specification). The weight of the performance requirements in the weight table can be specified in advance by developers or maintainers familiar with the business specifications according to the version performance test results. Among them, the test results are generated after a single performance evaluation server simulates and evaluates each service. Exemplarily, referring to Table 1, which shows a weight table including the performance requirement weights. Among them, the size of the specification is inversely proportional to the requirement evaluation value. The weights are exemplarily taken as 1 to 3 according to the level of the business specification. For example, for a high-specification monitoring service, its performance weight is 1; for a medium-specification monitoring service, its performance weight is 2; for a low-specification monitoring service, its performance weight is 3. It should be noted that the performance weights can also be set to other values, which are not specifically limited here. Moreover, in addition to being divided into three levels of high, medium, and low, the monitoring service specifications can also be further divided into different grades, and a weight is set for each corresponding grade. The specific number of grades and the performance weights corresponding to each grade are not specifically limited.
[0034] Table 1. Weight Table including Performance Requirement Weights
[0035]
[0036]
[0037] The business real-time requirement refers to the user's requirement for the real-time response speed of the business. For example, for services such as pan-tilt control where users perform real-time operations and wait for results, the real-time requirement is necessarily greater than that of asynchronous operations such as camera parameter configuration (it may take several minutes to restart after some camera configurations are successful). The business real-time weight can be pre-evaluated and set by maintainers familiar with user usage habits. Exemplarily, for monitoring services with higher business real-time requirements, the business real-time requirement weight is greater. Therefore, the weight of the business real-time requirement can be determined according to the business response type, for example, taking values from 1 to 3. The weight can also be other numerical values, which are not specifically limited here. The weight table can be seen in Table 2 below.
[0038] Table 2. Weight Table including Business Real-time Requirement Weights
[0039]
[0040] The device attention requirement means that in monitoring services, some access devices are in important positions and have higher user attention compared to general access devices. Under the condition of the same service and the same access frequency, a faster response is required. Therefore, there are also differences in attention requirements for different access devices. The device attention requirement weight can be specified by the user. Exemplarily, during the morning and evening rush hours in the traffic monitoring industry, a relatively large value can be preset for the attention requirement weight of cameras at busy intersections or accident-prone sections.
[0041] Exemplarily, the device attention demand weight can be set according to actual requirements. For example, the device attention demand is divided into 5 levels, and the value range of the device attention demand weight is 1 to 5, or it can be other values, which are not specifically limited herein. Referring to Table 3, it shows the device real-time demand weight of the access device, and IPC refers to the network camera.
[0042] Table 3. Weight table including device attention demand weight
[0043]
[0044] It should be noted here that the monitoring service types in Table 1 - Table 3 can be expanded using a digital dictionary.
[0045] S102. Obtain service data within a preset time period.
[0046] In the embodiment of the present application, after the load balancing server is started, it will automatically record the task types and the number of times sent to the access device. In addition to obtaining the weight table in response to the load balancing trigger operation, it also obtains the service data within a preset time period. Among them, the service data includes the types of services triggered within the preset time period and the number of times each type of service is triggered. The preset time period is exemplarily a period of time (such as 3 days) before the load balancing trigger operation.
[0047] S103. Based on the weight table and the service data, adjust the distribution of the consistent hash ring so that the service load pressure is evenly distributed among the servers in the monitoring system.
[0048] In the embodiment of the present application, the consistent hash ring is the core of implementing load balancing using the consistent hash algorithm. Referring to Figure 1c , which shows a schematic diagram of the consistent hash ring. Among them, the consistent hash ring includes multiple virtual nodes, and each virtual node uniquely corresponds to a server according to the mapping relationship. For example, virtual nodes N1 and N1 - 1 correspond to the same server, virtual nodes N2 and N2 - 1 correspond to the same server, and virtual nodes N3 and N3 - 1 correspond to the same server. When receiving a client service request, the hash value is obtained according to the device code in the service request and the server is matched on the consistent hash ring. However, in the existing balancing method, the distribution of the hash ring is unchanged, so the actual service load pressure on each server is unbalanced because the usage frequency of each device and the performance consumption of different services are different.
[0049] Based on the above problems, the load balancing method proposed by the inventor can analyze the business load pressure borne by each server within a preset time period according to the weight table and business data, and then adjust the distribution of the consistent hash ring, so that the subsequent business load pressure is evenly distributed among the servers of the monitoring system. It should be noted here that adjusting the distribution of the consistent hash ring mainly means adjusting the number of virtual nodes of each server on the hash ring. For example, reducing the virtual nodes of the server with high business load pressure and increasing the number of virtual nodes of the server with low business load pressure.
[0050] In an alternative embodiment, based on the weight table and the business data, adjusting the distribution of the consistent hash ring so that the business load pressure is evenly distributed among the servers of the monitoring system includes S1031 - S1033:
[0051] S1031. Calculate the business load pressure of each virtual node on the consistent hash ring based on the weight table and the business data.
[0052] In the embodiments of the present application, the weight value can be used to represent the business load pressure of each virtual node and the business load pressure of each server. Optionally, calculating the business load pressure of each virtual node on the consistent hash ring based on the weight table and the business data includes:
[0053] For any virtual node, calculate the business load pressure of this virtual node according to the following formula:
[0054]
[0055] Where, Y represents the business load pressure within the preset time before the server serves the virtual node; n1, n2, n3 respectively represent the triggering times of different types of services within the previous preset time period; P1, P2, P3 respectively represent the performance requirement weights of different types of services; Q1, Q2, Q3 represent the real-time requirement weights of different types of services; X i represents the device attention requirement weight of different access devices, and d represents the number of access devices matching this virtual node.
[0056] S1032. Calculate the business load pressure of each server according to the corresponding relationship between each server and each virtual node.
[0057] Through S1031, the business load pressure of each virtual node can be calculated. Then, according to the corresponding relationship between each server and each virtual node, the virtual nodes corresponding to each server can be determined. Thus, the business load pressure of each server is equal to the sum of the business load pressures of the virtual nodes corresponding to this server.
[0058] S1033. Adjust the number of virtual nodes of each server on the consistent hashing ring according to the business load pressure of each server, so that the business load pressure is evenly distributed among the servers in the monitoring system.
[0059] In an optional implementation, to balance the business load pressure of each server, the number of virtual nodes of each server on the consistent hashing ring can be adjusted. For example, transfer the virtual nodes of the server with high business load pressure to the server with low business load pressure, that is, let the server with low business load pressure share part of the business of the server with high business load pressure.
[0060] In the embodiment of the present application, based on the obtained weight table including the business type and the weights of different requirements corresponding to each business type and the business data within a preset time period, the business load pressure of each server can be analyzed, and then by adjusting the consistent hashing ring distribution, the business load pressure is evenly distributed among the servers in the monitoring system, thereby solving the problem of uneven business load pressure among the servers in the system caused by different usage frequencies of each access device and different performance consumptions of different services.
[0061] Figure 2 It is a flowchart of the load balancing method according to the second embodiment of the present application. This embodiment is optimized on the basis of the above embodiment. Refer to Figure 2 and the method includes:
[0062] S201. In response to a load balancing trigger operation, obtain a pre-set weight table.
[0063] Among them, the weight table includes the business type and the weights of different requirements corresponding to each business type.
[0064] S202. Obtain the business data within a preset time period.
[0065] Among them, the business data includes the type of the triggered business within a preset time period and the number of times each type of business is triggered.
[0066] S203. Based on the weight table and the business data, calculate the business load pressure of each virtual node on the consistent hashing ring.
[0067] S204. According to the correspondence between each server and each virtual node, calculate the business load pressure of each server.
[0068] S205. According to the business load pressure of each server, determine the target virtual nodes that need to be transferred on the consistent hashing ring.
[0069] In an optional implementation, according to the business load pressure of each server, determining the target virtual nodes that need to be transferred on the consistent hashing ring includes:
[0070] Compare the business load pressures of each server in pairs, and select the first server and the second server according to the comparison results; among them, the business load pressure of the first server is greater than that of the second server, and the comparison result of the business load pressures of the first server and the second server is greater than a preset threshold;
[0071] Determine the target virtual nodes to be transferred from the virtual nodes of the first server according to a preset screening rule, and the preset screening rule can optionally be to screen the virtual node with the smallest business load pressure.
[0072] S206. Modify the mapping relationship between the target virtual nodes and the servers in the consistent hashing ring so that the business load pressure is evenly distributed among the servers of the monitoring system.
[0073] Modify the mapping relationship between the target virtual nodes and the servers in the consistent hashing ring, and its purpose is to adjust the number of virtual nodes of each server. In an optional implementation manner, modifying the mapping relationship between the target virtual nodes and the servers in the consistent hashing ring includes:
[0074] Delete the mapping relationship between the target virtual nodes in the consistent hashing ring and the first server, and establish the mapping relationship between the target virtual nodes and the second server.
[0075] Exemplarily, the above process is described in terms of distance. The virtual nodes corresponding to server A are Y A , Y A-1 , Y A-2 ; the virtual nodes corresponding to server B are Y B , Y B-1 , Y B-2 ; the virtual nodes corresponding to server C are Y C , Y C-1 , Y C-2 . R A , R B , R C The values of respectively represent the weight values (i.e., business load pressures) of servers A, B, and C, and the weight value of a virtual node is the business load pressure of the virtual node.
[0076] Table 4. Weight values corresponding to each node and weight values of each server
[0077]
[0078] Adjust the number of virtual nodes of each server on the hashing ring according to the magnitude of the weight values to achieve an even distribution of the proportion of the weight values of each server, that is, to achieve an even distribution of the business load pressures of each server. Taking the above calculation results as an example:
[0079] (1)R A and R C The proportion difference is nearly 26.7%, which is greater than the set threshold y = 10% (the threshold y can prevent virtual nodes from switching back and forth, and the value of y can be set according to actual needs). Among the virtual sub-nodes corresponding to server A, select the virtual node Y with the smallest weight value A-2 , modify the value of the corresponding virtual node in the hash ring mapping relationship cache to C-3(From A), that is, the virtual node Y A-2 The mapping relationship established with server C. Subsequently, business requests matching the virtual node Y A-2 will no longer be processed by server A, but by server C, thereby reducing the business load pressure on server A. Through the above calculations, it can be seen that after transferring the virtual node Y A-2 , the proportion of the business weight value of R A decreases to 43%. It should be noted that the purpose of marking From A is to facilitate the subsequent transfer of virtual nodes from server C to server A, and the virtual nodes marked From A are preferentially transferred.
[0080] (2) Repeat the above steps, compare the proportions of R A and R B , modify the mapping relationship of the virtual node Y A-1 to B-3(FromA). The proportion of the business weight value of R A decreases to 33.3%. The calculation results of the weight values after virtual node transfer are as follows:
[0081] Table 5. Weight values corresponding to each node and weight values of each server after adjustment
[0082]
[0083]
[0084] (3) The weight proportions of servers A, B, and C finally become 33.3%, 36.7%, and 30%. Basically, a hash ring with uneven distribution of virtual node numbers but basically uniform business weight values is formed, thereby realizing the uniform distribution of business load pressure among the servers in the monitoring system. It should be noted that as long as the difference between the weights of any two servers is less than the set threshold (for example, 10%), it is considered that a hash ring with uneven distribution of virtual node numbers but basically uniform business weight values is formed.
[0085] In the embodiments of the present application, by transferring some virtual nodes of the server with large business load pressure to the server with small business load pressure, the business load pressure of each server is ensured to be balanced.
[0086] Further, to ensure the consistency of service request distribution, before modifying the mapping relationship between the target virtual node and the server in the consistent hashing ring, it also includes: pausing the distribution of service request tasks and waiting until the current service request task is sent and completed.
[0087] In addition, for virtual node transfer, the following points need to be noted: (1) The weight value ratio on server A may decrease over time and with task pressure. In this case, when calculating weights, priority should be given to retrieving the transferred virtual nodes from server B and C's virtual nodes for From A. (2) When deleting a server in the monitoring system, all virtual nodes of that server, including the transferred nodes, need to be synchronously deleted. (3) The switching frequency of virtual nodes needs to be restricted to prevent nodes from switching back and forth due to fine-tuning of service pressure.
[0088] Figure 3 It is a flowchart of the load balancing method according to the third embodiment of the present application. This embodiment is optimized based on the above embodiment. Refer to Figure 3 and the method includes:
[0089] S301. Update the weights of performance requirements and service real-time requirements in the weight table according to user experience feedback or in a manner based on manual settings.
[0090] For the weights of performance requirements, in addition to updating according to user experience feedback or in a manner based on manual settings, exemplarily, an evaluation server can also be set up. The evaluation server evaluates the specifications of each service (the number of services that the server can execute and complete within a fixed time period), and then updates the weights of performance requirements according to the evaluation results. It should be noted that updating the weights of performance requirements and service real-time requirements by means of feedback of user experience or manual settings can improve the response speed of a certain device or a certain type of service.
[0091] S302. Update the weights of device attention requirements in the weight table according to the historical access frequency of synchronous services.
[0092] In the embodiment of the present application, the weights of device attention requirements can be updated not only by manual designation but also according to the historical access frequency of synchronous services to update the weights of device attention requirements in the weight table. Exemplarily, taking cameras at busy intersections or accident-prone sections during morning and evening rush hours as an example, the operation habits of users during the morning and evening rush hours can be automatically learned and analyzed, and the weights of device attention requirements in the weight table can be automatically updated according to the historical access frequency of synchronous services. In an alternative embodiment, the weights of device attention requirements in the weight table can be calculated and updated according to the following formula:
[0093]
[0094] where X represents the new weight of device attention requirements;-1 , N -2 , N -3 respectively represent the number of business requests on a certain day in a preset time period; m represents the length of the preset time period, such as the total number of days; z represents the business frequency rating index.
[0095] Furthermore, after obtaining the new device attention weight value, by preloading the weight value table before the peak arrives, the response speed of frequently used devices with high attention can be improved during the peak time period.
[0096] In the embodiment of the present application, the accuracy of business load balancing can be ensured by updating the weight value table.
[0097] Figure 4 is a schematic structural diagram of a load balancing device according to the fourth embodiment of the present application. This embodiment is applicable to the situation of balancing the business load pressure of each server in a distributed monitoring system. Refer to Figure 4 , the device includes:
[0098] A weight value table acquisition module 401, configured to respond to a load balancing trigger operation and acquire a pre-set weight value table; wherein, the weight value table includes service types and weight values corresponding to different requirements for each service type;
[0099] A service data acquisition module 402, configured to acquire service data within a preset time period; wherein, the service data includes the types of services triggered within the preset time period and the number of times each type of service is triggered;
[0100] An equalization module 403, configured to adjust the consistent hashing ring distribution based on the weight value table and the service data, so that the business load pressure is evenly distributed among the servers in the monitoring system.
[0101] In the embodiment of the present application, based on the acquired weight value table including service types and weight values corresponding to different requirements for each service type and the service data within a preset time period, the business load pressure of each server can be analyzed, and then by adjusting the consistent hashing ring distribution, the business load pressure is evenly distributed among the servers in the monitoring system, thereby solving the problem of uneven business load pressure among the servers in the system caused by different usage frequencies of each access device and different performance consumptions of different services.
[0102] On the basis of the above embodiment, optionally, different requirements include performance requirements, service real-time requirements, and device attention requirements. On the basis of the above embodiment, optionally, the first calculation unit is specifically configured to:
[0103] For any virtual node, calculate the business load pressure of the virtual node according to the following formula:
[0104]
[0105] Among them, Y represents the business load pressure within a preset time before the server service virtual node; n1, n2, and n3 respectively represent the triggering times of different types of services within the previous preset time period; P1, P2, and P3 respectively represent the performance requirement weights of different types of services; Q1, Q2, and Q3 represent the real-time requirement weights of different types of services; X i represents the device attention requirement weight of different access devices, and d represents the number of access devices that match this virtual node;
[0106] Correspondingly, the business load pressure of each server is equal to the sum of the business load pressures of the virtual nodes corresponding to this server.
[0107] Based on the above embodiments, optionally, the device further includes:
[0108] A first update module, configured to update the weights of performance requirements and business real-time requirements in the weight table according to user experience feedback or in a manner based on manual settings;
[0109] A second update module, configured to update the weight of the device attention requirement in the weight table according to the historical access frequency of the synchronized services.
[0110] Based on the above embodiments, optionally, the second update module is specifically configured to:
[0111] Calculate and update the weight of the device attention requirement in the weight table according to the following formula:
[0112]
[0113] Among them, X represents the new weight of the device attention requirement; -1 , N -2 , N -3 respectively represent the number of business requests on a certain day in the preset time period; m represents the length of the preset time period; z represents the business frequency rating index.
[0114] Based on the above embodiments, optionally, the balancing module includes:
[0115] A first calculation unit, configured to calculate the business load pressure of each virtual node on the consistent hashing ring based on the weight table and business data;
[0116] A second calculation unit, configured to calculate the business load pressure of each server according to the corresponding relationship between each server and each virtual node;
[0117] A balancing unit, configured to adjust the number of virtual nodes of each server on the consistent hashing ring according to the business load pressure of each server, so that the business load pressure is evenly distributed among the servers of the monitoring system.
[0118] Based on the above embodiments, optionally, the balancing unit includes:
[0119] A node screening subunit, configured to determine target virtual nodes to be transferred on the consistent hashing ring according to the service load pressure of each server;
[0120] A mapping relationship modification subunit, configured to modify the mapping relationship between the target virtual nodes and the servers in the consistent hashing ring.
[0121] Based on the above embodiments, optionally, the node screening subunit is specifically configured to:
[0122] Compare the service load pressures of each server pairwise, and select a first server and a second server according to the comparison results; wherein, the service load pressure of the first server is greater than that of the second server, and the comparison result of the service load pressures of the first server and the second server is greater than a preset threshold;
[0123] Determine the target virtual nodes to be transferred from the virtual nodes of the first server according to a preset screening rule.
[0124] Based on the above embodiments, optionally, the mapping relationship modification subunit is specifically configured to:
[0125] Delete the mapping relationship between the target virtual nodes in the consistent hashing ring and the first server, and establish a mapping relationship between the target virtual nodes and the second server.
[0126] Based on the above embodiments, optionally, the device further includes:
[0127] A waiting module, configured to pause the distribution of service request tasks and wait until the current service request task is sent and completed before modifying the mapping relationship between the target virtual nodes and the servers in the consistent hashing ring.
[0128] The load balancing device provided by the embodiments of the present application can execute the load balancing method provided by any embodiment of the present application, and has corresponding functional modules and beneficial effects for executing the method.
[0129] Figure 5 It is a schematic structural diagram of an electronic device provided in the sixth embodiment of the present application. As Figure 5 shown in the structure, the electronic device provided by the embodiments of the present application includes: one or more processors 502 and a memory 501; the processor 502 in the electronic device can be one or more, Figure 5Take a processor 502 as an example; a memory 501 is used to store one or more programs; the one or more programs are executed by the one or more processors 502, so that the one or more processors 502 implement the load balancing method described in any one of the embodiments of the present application.
[0130] The electronic device may further include: an input device 503 and an output device 504.
[0131] The processor 502, memory 501, input device 503, and output device 504 in the electronic device may be connected through a bus or other means. Figure 5 Take the connection through a bus as an example.
[0132] The storage device 501 in the electronic device, as a computer-readable storage medium, can be used to store one or more programs. The programs can be software programs, computer-executable programs, and modules, such as the program instructions / modules corresponding to the application control method provided in the embodiments of the present application. The processor 502 executes various functional applications and data processing of the electronic device by running the software programs, instructions, and modules stored in the storage device 501, that is, implements the load balancing method in the above method embodiments.
[0133] The storage device 501 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 501 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some instances, the memory 501 may further include a memory remotely set relative to the processor 502, and these remote memories can be connected to the device through a network. Examples of the above network include but are not limited to the Internet, enterprise intranets, local area networks, mobile communication networks, and their combinations.
[0134] The input device 503 can be used to receive input digital or character information, and generate key signal inputs related to the user settings and function control of the electronic device. The output device 504 may include a display device such as a display screen.
[0135] And when one or more programs included in the above electronic device are executed by the one or more processors 502, the programs perform the following operations:
[0136] In response to a load balancing trigger operation, obtain a pre-set weight table; wherein, the weight table includes service types and weights corresponding to different requirements for each service type;
[0137] Obtain service data within a preset time period; wherein, the service data includes the types of services triggered within the preset time period and the number of times each type of service is triggered;
[0138] Based on the weight table and the service data, adjust the distribution of the consistent hashing ring so that the service load pressure is evenly distributed among the servers of the monitoring system.
[0139] Of course, those skilled in the art can understand that when one or more programs included in the above electronic device are executed by one or more processors 502, the programs can also perform the relevant operations in the application control method provided in any embodiment of the present application.
[0140] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it is used to execute a load balancing method, and the method includes:
[0141] In response to a load balancing trigger operation, obtain a preset weight table; wherein, the weight table includes service types and the weights corresponding to different requirements for each service type;
[0142] Obtain service data within a preset time period; wherein, the service data includes the types of services triggered within the preset time period and the number of times each type of service is triggered;
[0143] Based on the weight table and the service data, adjust the distribution of the consistent hashing ring so that the service load pressure is evenly distributed among the servers of the monitoring system.
[0144] Optionally, when the program is executed by the processor, it can also be used to execute the method provided in any embodiment of the present application.
[0145] The computer storage medium of the embodiments of the present application may adopt any combination of one or more computer-readable media. The computer-readable media may be computer-readable signal media or computer-readable storage media. The computer-readable storage media may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (a non-exhaustive list) of the computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable CD-ROM, an optical storage device, a magnetic storage device, or any suitable combination of the above. The computer-readable storage media may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0146] The computer-readable signal media may include data signals propagated in a baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take various forms, including but not limited to: electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal media may also be any computer-readable media other than the computer-readable storage media, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0147] The program code contained on the computer-readable media may be transmitted by any appropriate medium, including but not limited to: wireless, wire, optical cable, radio frequency (RF), etc., or any suitable combination of the above.
[0148] Computer program code for performing the operations of this application can be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages (such as the "C" language or similar programming languages). The program code can be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network (such as including a local area network (LAN) or a wide area network (WAN)), or, it can be connected to an external computer (such as by using an Internet service provider to connect through the Internet).
[0149] Note that the above is only the preferred embodiment of this application and the technical principles applied. Those skilled in the art will understand that this application is not limited to the specific embodiments described herein. Various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of this application. Therefore, although this application has been described in more detail through the above embodiments, this application is not limited to the above embodiments. Without departing from the concept of this application, more other equivalent embodiments can be included, and the scope of this application is determined by the scope of the appended claims.
Claims
1. A load balancing method, characterized in that, The method includes: In response to a load balancing trigger operation, obtaining a pre-set weight table; wherein, the weight table includes service types and weights corresponding to different requirements for each service type; Obtaining service data within a preset time period; wherein, the service data includes the types of services triggered within the preset time period and the number of times each type of service is triggered; Based on the weight table and the service data, calculating the service load pressure of each virtual node on the consistent hashing ring; According to the correspondence between each server and each virtual node, calculating the service load pressure of each server; According to the service load pressure of each server, determining the target virtual node that needs to be transferred on the consistent hashing ring; Modifying the mapping relationship between the target virtual node and the server in the consistent hashing ring, so that the number of virtual nodes of the server with a large service load pressure decreases, and the number of virtual nodes of the server with a light service load pressure increases, so as to evenly distribute the service load pressure among the servers in the monitoring system.
2. The method according to claim 1, characterized in that, The different requirements include performance requirements, service real-time requirements, and device attention requirements.
3. The method according to claim 2, characterized in that, Based on the weight table and the service data, calculating the service load pressure of each virtual node on the consistent hashing ring includes: For any virtual node, calculating the service load pressure of the virtual node according to the following formula: Among them, Y represents the business load pressure within a preset time before the server serves the virtual node; n1, n2, and n3 respectively represent the triggering times of different types of services within the previous preset time period; P1, P2, and P3 respectively represent the performance requirement weights of different types of services; Q1, Q2, and Q3 represent the real-time requirement weights of different types of services; X i represents the device attention requirement weight of different access devices, and d represents the number of access devices that match this virtual node; Correspondingly, the service load pressure of each server is equal to the sum of the service load pressures of the virtual nodes corresponding to the server.
4. The method according to claim 2, characterized in that, The method further includes: Updating the weights of the performance requirements and service real-time requirements in the weight table according to user experience feedback or in a manner based on manual settings; Updating the weight of the device attention requirement in the weight table according to the historical access frequency of the synchronization service.
5. The method according to claim 4, characterized in that, Updating the weight of the device attention requirement in the weight table according to the historical access frequency of the synchronization service includes: Calculating the weight of the device attention requirement in the updated weight table according to the following formula: Among them, X represents the weight of the new device attention demand; N -1 , N -2 , N -3 respectively represent the number of business requests on a certain day in the preset time period; m represents the length of the preset time period; z represents the business frequency rating index.
6. The method according to claim 1, characterized in that, According to the service load pressure of each server, determining the target virtual node that needs to be transferred on the consistent hashing ring includes: Comparing the service load pressures of each server pairwise, and selecting a first server and a second server according to the comparison result; wherein, the service load pressure of the first server is greater than that of the second server, and the comparison result of the service load pressures of the first server and the second server is greater than a preset threshold; Determining the target virtual node that needs to be transferred from the virtual nodes of the first server according to a preset screening rule.
7. The method according to claim 6, characterized in that, Modifying the mapping relationship between the target virtual node and the server in the consistent hashing ring includes: Deleting the mapping relationship between the target virtual node and the first server in the consistent hashing ring, and establishing the mapping relationship between the target virtual node and the second server.
8. The method according to claim 1, characterized in that, Before modifying the mapping relationship between the target virtual node and the server in the consistent hashing ring, the method further includes: Pausing the distribution of service request tasks and waiting until the current service request task is sent.
9. A load balancing device, characterized in that, Including: A weight table acquisition module, configured to obtain a pre-set weight table in response to a load balancing trigger operation; wherein, the weight table includes service types and weights corresponding to different requirements for each service type; A business data acquisition module for acquiring business data within a preset time period; wherein the business data includes the types of businesses triggered within the preset time period and the number of times each type of business is triggered. A balancing module for adjusting the distribution of the consistent hashing ring based on the weight table and the business data, so that the business load pressure is evenly distributed among the servers in the monitoring system. Wherein the balancing module includes: A first calculation unit for calculating the business load pressure of each virtual node on the consistent hashing ring based on the weight table and the business data. A second calculation unit for calculating the business load pressure of each server according to the correspondence between each server and each virtual node. A balancing unit for adjusting the number of virtual nodes of each server on the consistent hashing ring according to the business load pressure of each server, so that the business load pressure is evenly distributed among the servers in the monitoring system. The balancing unit includes: A node screening sub-unit for determining the target virtual nodes to be transferred on the consistent hashing ring according to the business load pressure of each server. A mapping relationship modification sub-unit for modifying the mapping relationship between the target virtual nodes and the servers in the consistent hashing ring, so that the number of virtual nodes of the server with a large business load pressure is reduced, and the number of virtual nodes of the server with a light business load pressure is increased.
10. An electronic device, characterized in that, Includes: One or more processors; A storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the load balancing method according to any one of claims 1-8.
11. A computer-readable storage medium, on which a computer program is stored, characterized in that, When the program is executed by the processor, it implements the load balancing method according to any one of claims 1-8.
Citation Information
Patent Citations
Distributive dynamic load management system and distributive dynamic load management method
CN103188345A