Load balancing method, apparatus, device, and storage medium

CN117914857BActive Publication Date: 2026-09-15SUZHOU CENTEC COMM CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410095163.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-23
Publication Date
2026-09-15
Estimated Expiration
2044-01-23

AI Technical Summary

Technical Problem

[0004]有鉴于此,为至少解决因传统负载均衡技术中哈希值无法体现报文多样性特征,而导致操作单元无法均衡处理待转发报文的技术问题,本发明的目的在于提供一种负载均衡方法、装置、设备和存储介质

Benefits of technology

[0017] The load balancing method, apparatus, device, and storage medium provided in this invention first select at least one target data from different layer fields of the packet to be forwarded, then calculate a one-to-one hash value based on each target data, and then select two hash values ​​corresponding to different layer fields from these hash values ​​to calculate a mixed hash value. Finally, the target operation unit for processing the packet to be forwarded is determined based on the hash value obtained in the first calculation and the mixed hash value obtained in the second calculation. Thus, by adding the step of calculating the mixed hash value, the mixed use of different layer fields in the packet to be forwarded can be realized. For example, for unencapsulated packets, the data from Layer 2 (link layer) and Layer 3 (network layer) packets can be mixed. Similarly, for encapsulated packets, the data from inner and outer layer packets can be mixed. This allows the calculated mixed hash value to better reflect the diversity of the packets and ensures a more even distribution of hash values. This further ensures that the target operation unit determined based on the mixed hash value and the original hash value can achieve a better load balancing effect, which is beneficial to improving the utilization of network resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117914857B_ABST
    Figure CN117914857B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a load balancing method, device, equipment and storage medium, wherein the method comprises: obtaining at least one target data from different layer fields of a to-be-forwarded packet respectively; calculating a one-to-one corresponding hash value according to each target data respectively; calculating a mixed hash value according to two hash values corresponding to different layer fields in the hash values; and determining a target operation unit for processing the to-be-forwarded packet according to the hash values and the mixed hash value.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication technology, and more specifically, to a load balancing method, apparatus, device, and storage medium. Background Technology

[0002] Load balancing is an important means of achieving efficient resource utilization. It is built on the existing network structure and is used to distribute the load (such as workloads or network traffic) evenly across multiple operating units (such as network devices or servers) to expand the bandwidth of network devices and servers, increase throughput, enhance network data processing capabilities, and improve network flexibility and availability.

[0003] Currently, various algorithms that use hash uniformity to achieve load balancing typically calculate a hash value for a packet to be forwarded based on a single field in the packet. The resulting hash value is then used to forward the packet to the corresponding operation unit for processing. However, since the hash value is calculated based on only one field, it fails to reflect the diverse characteristics of the packets. Therefore, the uniform distribution of this hash value is somewhat lacking, leading to situations where operation units cannot process packets evenly, negatively impacting resource utilization. Summary of the Invention

[0004] In view of this, in order to at least solve the technical problem that the operation unit cannot process the packets to be forwarded in a balanced manner because the hash value in the traditional load balancing technology cannot reflect the diversity characteristics of the packets, the purpose of this invention is to provide a load balancing method, apparatus, device and storage medium.

[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of the present invention are as follows:

[0006] A first aspect of the present invention provides a load balancing method, comprising:

[0007] Obtain at least one target data from different layers of the message to be forwarded;

[0008] A hash value is calculated for each target data item.

[0009] A mixed hash value is calculated based on two hash values ​​corresponding to different layer fields in the hash value;

[0010] Based on the hash value and the mixed hash value, the target operation unit for processing the message to be forwarded is determined.

[0011] A second aspect of the present invention provides a load balancing device, comprising:

[0012] The acquisition module is configured to: acquire at least one target data from different layer fields of the message to be forwarded;

[0013] The calculation module is configured to: calculate a one-to-one hash value for each target data; and calculate a mixed hash value based on two hash values ​​corresponding to different layer fields in the hash value.

[0014] The determination module is configured to: determine the target operation unit for processing the message to be forwarded based on the hash value and the mixed hash value.

[0015] A third aspect of the present invention provides an electronic device including a processor and a memory, the memory storing machine-executable instructions executable by the processor, the processor executing the machine-executable instructions to implement the load balancing method provided in the first aspect above.

[0016] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the load balancing method provided in the first aspect above.

[0017] The load balancing method, apparatus, device, and storage medium provided in this invention first select at least one target data from different layer fields of the packet to be forwarded, then calculate a one-to-one hash value based on each target data, and then select two hash values ​​corresponding to different layer fields from these hash values ​​to calculate a mixed hash value. Finally, the target operation unit for processing the packet to be forwarded is determined based on the hash value obtained in the first calculation and the mixed hash value obtained in the second calculation. Thus, by adding the step of calculating the mixed hash value, the mixed use of different layer fields in the packet to be forwarded can be realized. For example, for unencapsulated packets, the data from Layer 2 (link layer) and Layer 3 (network layer) packets can be mixed. Similarly, for encapsulated packets, the data from inner and outer layer packets can be mixed. This allows the calculated mixed hash value to better reflect the diversity of the packets and ensures a more even distribution of hash values. This further ensures that the target operation unit determined based on the mixed hash value and the original hash value can achieve a better load balancing effect, which is beneficial to improving the utilization of network resources.

[0018] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0019] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 This diagram illustrates a structural block diagram of an electronic device provided by an embodiment of the present invention.

[0021] Figure 2 A flowchart of a load balancing method provided by an embodiment of the present invention is shown;

[0022] Figure 3 This diagram illustrates a network scenario provided by an embodiment of the present invention.

[0023] Figure 4 The diagram shows a functional block diagram of a load balancing device provided in an embodiment of the present invention. Detailed Implementation

[0024] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0025] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0026] It should be noted that relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0027] To address the technical problem in traditional load balancing technology where hash values ​​fail to reflect the diversity of packet characteristics, leading to an inability of operation units to handle packets equally, this invention provides a load balancing method. This method first selects at least one target data from different layers of the packet to be forwarded, then calculates a corresponding hash value for each target data. Next, it selects two hash values ​​corresponding to different layers from these target data and calculates a mixed hash value. Finally, it determines the target operation unit for processing the packet based on the hash value obtained in the first calculation and the mixed hash value obtained in the second calculation. Thus, by adding a mixed hash value calculation step, it is possible to... This allows for the mixed use of fields from different layers in the packet to be forwarded. For example, for an unencapsulated packet, data from Layer 2 (link layer) and Layer 3 (network layer) fields can be mixed. Similarly, for an encapsulated packet, data from inner and outer layer fields can be mixed. This enables the calculated mixed hash value to better reflect the diversity of the packet and ensures a more even distribution of hash values. This further ensures that the target operation unit determined based on the mixed hash value and the original hash value can achieve a better load balancing effect, which is beneficial to improving the utilization of network resources.

[0028] The load balancing method provided by this invention can be applied to electronic devices. Please refer to [link / reference]. Figure 1 This is a structural block diagram of an electronic device. The electronic device 100 includes a memory 110, a processor 120, and a communication module 130. The memory 110, processor 120, and communication module 130 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.

[0029] The memory is used to store programs or data. The memory may be, but is not limited to, Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), etc.

[0030] The processor is used to read / write data or programs stored in memory and to perform the corresponding functions.

[0031] The communication module is used to establish communication connections between electronic devices and other communication terminals via a network, and to send and receive data via the network.

[0032] It should be understood that, Figure 1 The structure shown is only a schematic diagram of an electronic device; the electronic device may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.

[0033] In some embodiments, the electronic device may be a load balancing device.

[0034] The following combination Figure 2 The load balancing method provided in the embodiments of the present invention will be described below. Figure 2 This is a flowchart of a load balancing method provided in an embodiment of the present invention, the load balancing method comprising:

[0035] In step S210, at least one target data is obtained from different layer fields of the message to be forwarded;

[0036] In step S220, a hash value corresponding to each target data is calculated.

[0037] In step S230, a mixed hash value is calculated based on the two hash values ​​corresponding to different layer fields in the hash value;

[0038] In step S240, a target operation unit for processing the message to be forwarded is determined based on the hash value and the mixed hash value.

[0039] The load balancing method provided in this embodiment of the invention can be applied to load balancing devices in any type of network structure, such as... Figure 3 As shown, Figure 3 This is a schematic diagram of a network scenario provided by an embodiment of the present invention. Figure 3 In the scenario shown, each client (any one of 310, 320, and 330) can access the data center via the network to request a server in the data center to provide services, such as processing messages. The data center includes a load balancer 340 and multiple servers (350, 360, and 370). Based on this, when the load balancer 340 receives a message to be forwarded from a client, it can determine the target server for processing the message from among the multiple servers, i.e., the target operation unit in step S240, through the steps S210 to S240 described above.

[0040] The following describes the process by which the load balancing device 340 determines the target operating unit through steps S210 to S240:

[0041] Upon receiving a packet to be forwarded, step S340 is used to parse the packet to obtain at least one target data from different layer fields of the packet. For example, in some embodiments, for an unencapsulated packet to be forwarded, at least one target data can be obtained from the network layer and the link layer of the packet. A target data item at the network layer includes at least one of a source IP address and a destination IP address. It should be understood that the source IP address, the destination IP address, or both can be used as a target data item at the network layer. Additionally, a target data item at the link layer includes at least one of a source MAC address and a destination MAC address. For an understanding of a target data item at the link layer, please refer to the description of a target data item at the network layer above; further details will not be provided here. For example, in some embodiments, for an encapsulated packet to be forwarded, at least one target data is obtained from both the inner and outer layers of the packet. The inner layer target data includes at least one of the following: the source IP address, destination IP address, source MAC address, and destination MAC address before encapsulation. The outer layer target data includes at least one of the following: the encapsulated source IP address, destination IP address, source MAC address, and destination MAC address. The source IP address, destination IP address, source MAC address, and destination MAC address before encapsulation can be understood as the data originally carried by the unencapsulated packet to be forwarded. The encapsulated source IP address, destination IP address, source MAC address, and destination MAC address can be understood as the data obtained after converting the packet to be forwarded to adapt to the current communication protocol. In addition, the packet data before and after encapsulation can be interpreted according to relevant technologies, which will not be described in detail here. Therefore, through step S210, target data that reflects different fields of the packet can be obtained.

[0042] After obtaining at least one target data from different layers of the message to be forwarded, step S220 is used to perform a first hash value calculation based on each target data to obtain the hash value corresponding to each target data. The principle of hash value calculation can be found in relevant technologies and will not be explained in detail here. It can be seen that step S220 can obtain hash values ​​that can represent different fields of the message, but at this time each hash value can only represent a single message field.

[0043] Therefore, to obtain hash values ​​that simultaneously represent different fields in the message, a second hash value calculation is performed on the hash value obtained in step S220 via step S230. Specifically, two hash values ​​corresponding to different layer fields are selected from step S220 and calculated to obtain a mixed hash value. The calculation method can be XOR operation, but is not limited to this. In this embodiment, to simplify the calculation process, XOR operation is used to obtain the mixed hash value. Accordingly, step S230 may include the following steps: In step S2310, two hash values ​​corresponding to different layer fields are arbitrarily selected from the hash values ​​and XORed to obtain the mixed hash value. It can be seen that through step S230, a mixed hash value that reflects the diversity of the message can be obtained, thereby realizing the mixed use of different layer message fields in the message to be forwarded.

[0044] After obtaining the mixed hash value, step S240 can be used to process the target operation unit for processing the message to be forwarded based on all hash values ​​and the mixed hash value. The technical principle of determining the target operation unit based on all hash values ​​and the mixed hash value is the same as the technical principle of determining the target operation unit based on hash value in related technologies, so this embodiment of the present invention will not be described in detail.

[0045] As can be seen, by adding a mixed hash value calculation step in the above scheme, the embodiments of the present invention can achieve mixed use of different layer fields in the packet to be forwarded. This allows the calculated mixed hash value to better reflect the diversity of the packet, ensuring a certain degree of uniform distribution of hash values. It also further ensures that the target operation unit determined based on the mixed hash value and the original hash value can achieve a better load balancing effect, which is beneficial to improving the utilization rate of network resources. To ensure that the calculated hash value can more comprehensively reflect the packet characteristics and further ensure the uniform distribution of hash values ​​and achieve a better load balancing effect, in some embodiments, the load balancing method provided by the embodiments of the present invention also optimizes the selection of target data. That is, in step S210, obtaining at least one target data from different layer fields of the packet to be forwarded may include the following steps:

[0046] In step S211, the source IP address and destination IP address are obtained from the network layer of the packet to be forwarded, so as to obtain two first target data of the network layer;

[0047] In step S212, the source MAC address and destination MAC address are obtained from the link layer of the packet to be forwarded, so as to obtain two second target data of the link layer.

[0048] It should be understood that steps S211 and S212 have no strict order; they can be executed sequentially or in parallel. After steps S211 and S212, four target data points are obtained: the source IP address and destination IP address at the network layer of the packet to be forwarded, and the source MAC address and destination MAC address at the link layer. Thus, target data reflecting different layers and fields within the packet to be forwarded can be obtained. Therefore, the four hash values ​​subsequently calculated based on this target data can also respectively reflect the target data at different layers and fields within the packet to be forwarded.

[0049] Based on the embodiments shown in steps S211 and S212, correspondingly, in step S220, calculating the corresponding hash value for each target data may include the following steps:

[0050] In step S221, for each first target data, the corresponding first hash value is calculated based on the first target data;

[0051] In step S222, for each second target data, the corresponding second hash value is calculated based on the second target data.

[0052] It should be understood that steps S221 and S222 have no strict order; they can be executed sequentially or in parallel. Through steps S221 and S222, a hash value is calculated for each target data, resulting in a total of four hash values: two first hash values ​​corresponding to the two first target data sets, and two second hash values ​​corresponding to the two second target data sets.

[0053] After obtaining four hash values, one of the first hash values ​​and one of the second hash values ​​can be selected to calculate a mixed hash value, according to the relevant description above. However, in some embodiments, in order to obtain a more uniform hash value, the load balancing method provided by this embodiment of the invention can also calculate multiple mixed hash values. Accordingly, the process of calculating the mixed hash value based on two hash values ​​corresponding to different layer fields in the hash value in step S230 can adaptively include the following steps:

[0054] In step S2320, the value of XORing each first hash value and each second hash value is calculated to obtain four mixed hash values.

[0055] To facilitate understanding of step S2320, the following example is provided. Suppose that the two first hash values ​​are A and B, and the two second hash values ​​are C and D. Then, through step S2320, the four mixed hash values ​​calculated are: the value after XORing A and C, the value after XORing A and D, the value after XORing B and C, and the value after XORing B and D.

[0056] After obtaining the four mixed hash values, these four mixed hash values, along with the four hash values ​​calculated in the first step, can be directly used as input for step S240 to determine the target operation unit. It is evident that the addition of more mixed hash values ​​allows the hash values ​​used to determine the target operation unit to not only reflect a single field in the message but also to reflect greater diversity within the message.

[0057] However, when there is a need to reduce the number of hash values ​​input to step S240, the mixed hash values ​​can be further processed to make the hash values ​​more uniform while comprehensively reflecting more diversity of messages. In some embodiments, the load balancing method provided by the present invention can also add a step of further processing the four mixed hash values, that is, the method can also include:

[0058] In step S2400, the four mixed hash values ​​are XORed to obtain a first new mixed hash value; and / or, the two mixed hash values ​​that correspond to different first target data and different second target data are XORed to obtain a second new mixed hash value.

[0059] Accordingly, in step S240, the mixed hash value includes at least one of the four mixed hash values, and at least one of the first new mixed hash value and the second new mixed hash value.

[0060] For step S2400 above, assuming the four mixed hash values ​​are G1, G2, G3, and G4, performing an XOR operation on the four mixed hash values ​​yields a first new mixed hash value, i.e., XORing G1 with G2, G3, and G4 to obtain a new mixed hash value H1. Performing an XOR operation on two mixed hash values ​​corresponding to different first target data and different second target data to obtain a second new mixed hash value can be understood as follows: assuming the mixed hash value calculated based on the hash value corresponding to the source IP address and the hash value corresponding to the source MAC address is G1, the mixed hash value calculated based on the hash value corresponding to the source IP address and the hash value corresponding to the target MAC address is G2, the mixed hash value calculated based on the hash value corresponding to the target IP address and the hash value corresponding to the source MAC address is G3, and the mixed hash value calculated based on the hash value corresponding to the target IP address and the hash value corresponding to the target MAC address is G4, then the two mixed hash values ​​corresponding to different first target data and different second target data are either G1 and G4, or G2 and G3, i.e., there are two sets of mixed hash values. A set of mixed hash values ​​can be selected at will. For example, G1 and G4 can be XORed to obtain a new mixed hash value H2, or G2 and G3 can be XORed to obtain a new mixed hash value H3. Alternatively, a second new mixed hash value can be calculated for each set of mixed hash values, resulting in H2 and H3. Accordingly, the mixed hash values ​​in step S240 can include at least one of the four mixed hash values ​​G1, G2, G3, and G4, and at least one of the new mixed hash values ​​H1, H2, and H3.

[0061] Therefore, it can be seen that through step S2400, more fields in different layers can be mixed, further expanding the types of hash values. It can be understood that through step S230, one field in different layers can be mixed, that is, a mixed hash value is obtained by mixing the data of one field in one layer with the data of one field in another layer. Through different steps of S2400, more fields in different layers can be mixed, that is, a new mixed hash value is obtained by mixing the data of two different fields in one layer with the data of two different fields in another layer. Therefore, hash values ​​that can reflect more diversity of messages can be obtained, making the distribution of hash values ​​finally input to step S240 more even, because the hash values ​​input to step S240 include not only the hash values ​​obtained from the first calculation, but also the hash values ​​obtained from the second and third calculations.

[0062] It is worth noting that the technical features or technical solutions in any of the above embodiments of the present invention can be combined with each other, as long as there is no contradiction in the combination.

[0063] To perform the corresponding steps in the above embodiments and various possible methods, an implementation of a load balancing device is given below. Optionally, the load balancing device may employ the methods described above. Figure 1 The device structure of the electronic device is shown. Further, please refer to... Figure 4 , Figure 4 This is a functional block diagram of a load balancing device provided in an embodiment of the present invention. It should be noted that the load balancing device provided in this embodiment has the same basic principle and technical effects as those in the above embodiments. For the sake of brevity, any parts not mentioned in this embodiment can be referred to the corresponding content in the above embodiments. The load balancing device 400 includes:

[0064] The acquisition module 410 is configured to: acquire at least one target data from different layer fields of the message to be forwarded;

[0065] The calculation module 420 is configured to: calculate a one-to-one corresponding hash value for each target data; and calculate a mixed hash value based on two hash values ​​corresponding to different layer fields in the hash value;

[0066] The determination module 430 is configured to: determine the target operation unit for processing the message to be forwarded based on the hash value and the mixed hash value.

[0067] In some embodiments, the acquisition module 410 may include:

[0068] The first acquisition unit is configured to: for an unencapsulated packet to be forwarded, acquire at least one target data from the network layer and the link layer of the packet to be forwarded respectively; wherein, the target data of the network layer includes at least one of the source IP address and the destination IP address, and the target data of the link layer includes at least one of the source MAC address and the destination MAC address.

[0069] And / or, the second acquisition unit is configured to: for an encapsulated packet to be forwarded, acquire at least one target data from the inner layer and the outer layer of the packet to be forwarded, respectively; wherein, the target data of the inner layer includes at least one of the source IP address, the target IP address, the source MAC address and the target MAC address before encapsulation, and the target data of the outer layer includes at least one of the source IP address, the target IP address, the source MAC address and the target MAC address after encapsulation.

[0070] In some embodiments, the calculation module 420 is further configured to: arbitrarily select two hash values ​​corresponding to different layer fields from the hash values, and perform an XOR operation to obtain a mixed hash value.

[0071] In some embodiments, the first acquisition unit may be further configured to: acquire the source IP address and the destination IP address from the network layer of the packet to be forwarded, so as to obtain two first target data of the network layer; and acquire the source MAC address and the destination MAC address from the link layer of the packet to be forwarded, so as to obtain two second target data of the link layer.

[0072] Based on the previous embodiment, in some embodiments, the calculation module 420 may also be configured to: calculate a corresponding first hash value for each first target data; and calculate a corresponding second hash value for each second target data.

[0073] Based on the previous embodiment, in some embodiments, the calculation module 420 may also be configured to: calculate the value after XORing each first hash value and each second hash value to obtain four mixed hash values.

[0074] Based on the previous embodiment, in some embodiments, the calculation module 420 may also be configured to: perform an XOR operation on the four mixed hash values ​​to obtain a first new mixed hash value; and / or, perform an XOR operation on two mixed hash values ​​that correspond to different first target data and different second target data among the four mixed hash values ​​to obtain a second new mixed hash value.

[0075] Accordingly, the mixed hash value mentioned in the determining module 430 includes at least one of the four mixed hash values, and at least one of the first new mixed hash value and the second new mixed hash value.

[0076] Optionally, the above modules can be stored in the form of software or firmware. Figure 1 The memory shown is either stored in or embedded in the operating system (OS) of the electronic device, and can be... Figure 1 The processor executes the commands. Meanwhile, the data and program code required to execute these modules can be stored in memory.

[0077] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0078] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0079] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0080] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A load balancing method, characterized in that, include: Obtain at least one target data from different layers of the message to be forwarded; A hash value is calculated for each target data item. A mixed hash value is calculated based on two hash values ​​corresponding to different layer fields in the hash value; Based on the hash value and the mixed hash value, the target operation unit for processing the message to be forwarded is determined.

2. The method according to claim 1, characterized in that, The step of obtaining at least one target data from different layers of the message to be forwarded includes: For an unencapsulated packet to be forwarded, at least one target data is obtained from the network layer and the link layer of the packet to be forwarded; wherein, a target data in the network layer includes at least one of the source IP address and the destination IP address, and a target data in the link layer includes at least one of the source MAC address and the destination MAC address; or, For a pre-encapsulated packet to be forwarded, at least one target data is obtained from the inner and outer layers of the packet to be forwarded; wherein, the target data of the inner layer includes at least one of the source IP address, destination IP address, source MAC address and destination MAC address before encapsulation, and the target data of the outer layer includes at least one of the source IP address, destination IP address, source MAC address and destination MAC address after encapsulation.

3. The method according to claim 1 or 2, characterized in that, The step of calculating the mixed hash value based on two hash values ​​corresponding to different layer fields in the hash value includes: From the hash values, arbitrarily select two hash values ​​that correspond to different layer fields and perform an XOR operation to obtain a mixed hash value.

4. The method according to claim 1, characterized in that, The step of obtaining at least one target data from different layers of the message to be forwarded includes: Obtain the source IP address and destination IP address from the network layer of the packet to be forwarded, so as to obtain the two first target data of the network layer; Obtain the source MAC address and destination MAC address from the link layer of the packet to be forwarded, so as to obtain two second target data from the link layer.

5. The method according to claim 4, characterized in that: The step of calculating a one-to-one corresponding hash value for each target data item includes: For each first target data, the corresponding first hash value is calculated based on the first target data; For each second target data, the corresponding second hash value is calculated based on the second target data.

6. The method according to claim 5, characterized in that, The step of calculating the mixed hash value based on two hash values ​​corresponding to different layer fields in the hash value includes: Calculate the value after XORing each first hash value with each second hash value to obtain four mixed hash values.

7. The method according to claim 6, characterized in that, After obtaining four mixed hash values, the method further includes: Perform an XOR operation on the four mixed hash values ​​to obtain a first new mixed hash value; and / or, XOR the two mixed hash values ​​that correspond to different first target data and different second target data among the four mixed hash values ​​to obtain a second new mixed hash value. Accordingly, in the step of determining the target operation unit for processing the message to be forwarded based on the hash value and the mixed hash value, the mixed hash value includes at least one of the four mixed hash values, and at least one of the first new mixed hash value and the second new mixed hash value.

8. A load balancing device, characterized in that, include: The acquisition module is configured to: acquire at least one target data from different layer fields of the message to be forwarded; The calculation module is configured to calculate a one-to-one hash value for each target data. A mixed hash value is calculated based on the two hash values ​​corresponding to different layer fields in the hash value; The determination module is configured to: determine the target operation unit for processing the message to be forwarded based on the hash value and the mixed hash value.

9. An electronic device, characterized in that, It includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor to implement the method of any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Method and device for realizing homology and homoclinic in selected group, electronic equipment and storage medium

    CN115914423A

  • Method and system for flexibly generating hash value for network load balancing application, and storage medium and electronic device

    WO2023093726A1