CN115174581A - Load balancing method and router - Google Patents

Load balancing method and router Download PDF

Info

Publication number
CN115174581A
CN115174581A CN202210790600.7A CN202210790600A CN115174581A CN 115174581 A CN115174581 A CN 115174581A CN 202210790600 A CN202210790600 A CN 202210790600A CN 115174581 A CN115174581 A CN 115174581A
Authority
CN
China
Prior art keywords
network card
data packet
service data
routing table
data packets
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202210790600.7A
Other languages
Chinese (zh)
Other versions
CN115174581B (en
Inventor
段靖远
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Instant Wulian Technology Beijing Co ltd
Original Assignee
Instant Wulian Technology Beijing Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Instant Wulian Technology Beijing Co ltd filed Critical Instant Wulian Technology Beijing Co ltd
Priority to CN202210790600.7A priority Critical patent/CN115174581B/en
Publication of CN115174581A publication Critical patent/CN115174581A/en
Application granted granted Critical
Publication of CN115174581B publication Critical patent/CN115174581B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/54Organization of routing tables
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/256NAT traversal
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/50Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The application relates to the application field of CDN, in particular to a load balancing method and a router, the method comprises the steps of obtaining service data packets, wherein the service data packets are data packets which are generated based on request data packets sent by a user side and are sent to the user side by a service side, and each service data packet is associated with associated information comprising a source port, a destination port, a source address and a destination address; configuring the NAT rule of each service data packet based on the relation information; determining output network cards corresponding to the service data packets respectively based on the associated information and a preset load balancing rule, wherein the output network cards are the network cards distributed and transmitted by the service data packets; and sending each service data packet through the corresponding output network card. The method and the device have the effect of balancing the load of the network cards.

Description

Load balancing method and router
Technical Field
The present application relates to the field of CDN applications, and in particular, to a load balancing method and a router.
Background
With the development of internet technology and telecommunication technology, a multi-network card Linux environment service platform is gradually applied to the fields of Content Delivery Networks (CDNs) and the like, and has a higher use cost performance compared with a single-network card Linux environment service platform.
However, in a multi-network-card network, a data packet needs to face the selection problem of multiple network cards during transmission, and if the data packet is not distributed reasonably enough, a high load situation occurs on a certain network card; for example, when the client accesses the server from the single network card in an excessive manner or the server provides an excessive service to the user through the single network card, more data is transmitted through the single network card, so that the load of the network card is higher, and the data transmission speed is also slower.
Disclosure of Invention
In order to balance the load of a plurality of network cards, the application provides a load balancing method and a router.
In a first aspect, the present application provides a load balancing method and a router, which adopt the following technical solutions:
a load balancing method, performed by a router, comprising:
acquiring service data packets, wherein the service data packets are generated based on request data packets sent by a user terminal and are sent to the user terminal by a server terminal, and each service data packet is associated with associated information comprising a source port, a destination port, a source address and a destination address;
configuring an NAT rule of each service data packet based on the relationship information;
determining an output network card corresponding to each service data packet based on each piece of association information and a preset load balancing rule, wherein the output network card is a network card distributed and transmitted by the service data packet;
and sending each service data packet through the corresponding output network card.
By adopting the technical scheme, the output network cards corresponding to the data packets are determined through the associated information, namely if a plurality of service data packets exist, the output network cards of the data packets with the same associated information, namely the data packets to be sent to the same equipment, are the same; for the data packets with different associated information, the corresponding output network cards are different; and then the condition that a plurality of data packets with different destination addresses are all transmitted through one network card is reduced, and when more data is transmitted, the load on the single network card is reduced, so that the effect of more balanced load is realized.
In a possible implementation manner, before acquiring the service data packet, the method further includes:
acquiring a request data packet received by any network card and generating a response data packet;
determining an outgoing network card of the response data packet, wherein the outgoing network card is the network card when the request data packet enters;
and sending the response data packet through the outflow network card.
By adopting the technical scheme, the response data packet corresponding to the request data packet is returned according to the path of the network card when the request data packet enters, so that the data information of the same equipment can be transferred and returned to the equipment.
In a possible implementation manner, the determining an IP of the egress network card of the response packet includes:
based on a rule of iptables, generating a classification label of the request data packet, and associating the classification label with the request data packet, wherein the classification label comprises an IP (Internet protocol) of a network card when the data packet enters and a corresponding routing table ID (identity);
writing the classification label and the table frame into a strategy routing table;
configuring NAT rules of the request data packets;
determining an IP of an egress network card based on the policy routing table to determine the egress network card.
In a possible implementation manner, before writing the classification tag and the table frame into a policy routing table, the method further includes:
judging whether the classification label is a new label or not;
if yes, writing the classification label and the table frame into a strategy routing table;
if not, determining the classification label as the original label corresponding to the new label.
In a possible implementation manner, before configuring the NAT rule for each service packet, the method further includes:
determining a strategy routing table corresponding to each network card based on the IP of each network card;
writing the IP of each network card and the routing table corresponding to each network card into a strategy routing table to obtain a configured strategy routing table;
and configuring a preset load balancing rule for each network card.
In one possible implementation, the load balancing rule includes:
performing hash calculation based on the source address, the source port, the destination address and the destination port of the service data packet to obtain an intermediate parameter M;
calculating the remainder of M/N, wherein N is the number of the network cards, each network card is preset with a number corresponding to the IP of the network card, the number of each network card is determined from 0-N, and the numbers of any two network cards are not repeated;
and if the remainder is N-1, determining the network card with the number of N as the output network card of the service data packet.
In a second aspect, the present application provides a load balancing apparatus, which adopts the following technical solutions:
a load balancing device comprises
The service datagram acquisition module is used for acquiring service data packets, wherein the service data packets are data packets which are generated based on request data packets sent by a user terminal and are sent to the user terminal by a server terminal, and each service data packet is associated with associated information comprising a source port, a destination port, a source address and a destination address;
the first NAT rule configuration module is used for configuring the NAT rule of each service data packet based on the relationship information;
an output network card determining module, configured to determine, based on each piece of association information and a preset load balancing rule, an output network card corresponding to each service data packet, where the output network card is a network card to which the service data packet is allocated for transmission;
and the first sending module is used for sending each service data packet through the corresponding output network card.
In one possible implementation, the apparatus further includes:
the response data packet generating module is used for acquiring the request data packet received by any network card and generating a response data packet;
an outgoing network card determining module, configured to determine an outgoing network card of the response data packet, where the outgoing network card is a network card when the request data packet enters;
and the second sending module is used for sending the response data packet through the outflow network card.
In a possible implementation manner, when the egress network card determining module determines the egress network card of the response packet, the egress network card determining module is specifically configured to:
generating a classification label of the request data packet based on a rule of rules of iptables, and associating the classification label with the request data packet, wherein the classification label comprises an IP (Internet protocol) of a network card when the data packet enters and a corresponding routing table ID (identity);
writing the classification label and the table frame into a strategy routing table;
configuring NAT rules of the request data packets;
determining an IP of an egress network card based on the policy routing table to determine the egress network card.
In one possible implementation, the apparatus further includes:
the judging module is used for judging whether the classification label is a new label or not;
and the original label determining module is used for determining the classification label as the original label corresponding to the new label judged by the classification label.
In one possible implementation, the apparatus further includes:
the strategy routing table determining module is used for determining strategy routing tables corresponding to the network cards based on the IP of the network cards;
the write-in module is used for writing the IP of each network card and the routing table corresponding to each network card into the strategy routing table to obtain a configured strategy routing table;
and the configuration module is used for configuring a preset load balancing rule for each network card.
In one possible implementation, the load balancing rule includes:
performing hash calculation based on a source address, a source port, a destination address and a destination port of the service data packet to obtain an intermediate parameter M;
calculating the remainder of M/N, wherein N is the number of the network cards, each network card is preset with a number corresponding to the IP of the network card, the number of each network card is determined from 0-N, and the numbers of any two network cards are not repeated;
and if the remainder is N-1, determining the network card with the number of N as the output network card of the service data packet.
In a third aspect, the present application provides a router, which adopts the following technical solution:
a router, the router comprising:
at least two network cards;
at least one processor;
a memory;
at least one application, wherein the at least one application is stored in the memory and configured to be executed by the at least one processor, the at least one application configured to: the load balancing method described above is performed.
In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solutions:
a computer-readable storage medium, comprising: a computer program is stored which can be loaded by a processor and which performs the above-described load balancing method.
In summary, the present application includes at least one of the following beneficial technical effects:
determining an output network card corresponding to the data packet through the associated information, namely if a plurality of service data packets exist, determining that the output network cards of the data packets with the same associated information, namely the data packets to be sent to the same equipment, are the same; for the data packets with different associated information, the corresponding output network cards are different; the situation that a plurality of data packets with different destination addresses are transmitted through one network card is further reduced, when more data is transmitted, the load on the single network card is reduced, and the effect of more balanced load is further realized;
and returning a response data packet corresponding to the request data packet according to the path of the network card when the request data packet enters, so that the data information of the same equipment can be transferred and returned to the equipment.
Drawings
Fig. 1 is a flow diagram of a load balancing method in an embodiment of the present application;
fig. 2 is a schematic diagram of a process for sending a service data packet in an embodiment of the present application;
FIG. 3 is a simplified schematic flow chart of sending a response packet in an embodiment of the present application;
fig. 4 is a schematic structural diagram of a load balancing apparatus in an embodiment of the present application;
fig. 5 is a schematic structural diagram of a router in the embodiment of the present application.
Detailed Description
The present application is described in further detail below with reference to figures 1-5.
A person skilled in the art, after reading the present description, may make modifications as required without inventive contribution to the present embodiments, but shall be protected by the patent laws within the scope of the claims of the present application.
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application without making any creative effort belong to the protection scope of the present application.
In addition, the term "and/or" herein is only one kind of association relationship describing an associated object, and means that there may be three kinds of relationships, for example, a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship, unless otherwise specified.
In the CDN domain, the high concurrency problem is generally caused by the client accessing the server from a single route excessively or the server providing an excessive service from a single route, that is, sending out an excessive amount of packets from a single network card will cause the high concurrency problem. The load balancing means that the device prepares a data packet to be actively sent, and the flow is distributed to a plurality of network cards to be sent out through the load balancing rule of iptables, so that the load pressure of a single network card is reduced, and meanwhile, the transmission efficiency and the transmission speed are improved.
The process of sending a packet from one network to another is called routing, which is performed by a router.
The policy routing is a routing policy directly made for a certain data packet. The policy routing can set the behavior of the data packet, such as the next hop, the next interface, and the like, so that under the condition that a plurality of links exist, different links can be used according to different applications of the data packet, and further, efficient load balancing capability is provided.
An embodiment of the present application provides a load balancing method, which is executed by a router, and referring to fig. 1, the method includes steps S101 to S104, where:
step S101, acquiring service data packets, wherein the service data packets are data packets which are generated based on request data packets sent by a user terminal and are sent to the user terminal by a server terminal, and each service data packet is associated with associated information comprising a source port, a destination port, a source address and a destination address;
generally speaking, a user side sends a request data packet to a router, then the router generates a response data packet to return to the user, and meanwhile, the router analyzes the request data packet, obtains a service data packet in a corresponding address, and sends the service data packet to the user. In the embodiment of the present application, the service data packet is also a data packet sent from the server to the client, and the number of the obtained service data packets may be one or multiple. In the embodiment of the present application, an example is given in which one service data packet is transmitted.
And S102, configuring the NAT rule of each service data packet based on the relation information.
nat table requires three chains, namely:
REROUTING, where a rule for performing destination NAT can be defined, because a router only checks a destination IP of a packet when performing routing, so that the destination NAT must be performed before routing in order to correctly route a service packet;
postoutputting-rules for source NAT can be defined herein, and the system executes the rules in the chain after routing the packet.
OUTPUT-defining destination NAT rules for locally generated packets.
In the embodiment of the present application, when any service data packet is sent, its destination IP address and source address should have been already determined; the rules of the destination NAT of the traffic data packet are defined by the forwarding chain. The NAT rule for configuring the packet is the pre-step in routing.
Step S103, determining output network cards corresponding to the service data packets respectively based on the association information and the preset load balancing rule, where the output network cards are network cards to which the service data packets are distributed for transmission.
In the embodiment of the application, in a router with multiple network cards, for a service data packet, it is determined through which network card the data packet should be sent, that is, it is determined to output the network card, according to the associated information.
And step S104, sending each service data packet through the corresponding output network card.
In the embodiment of the application, the output network cards corresponding to the data packets are determined through the associated information, that is, if a plurality of service data packets exist, the output network cards of the data packets with the same associated information, that is, the data packets to be sent to the same device, are the same; for the data packets with different associated information, the corresponding output network cards are different; and then the condition that a plurality of data packets with different destination addresses are all transmitted through one network card is reduced, and when more data is transmitted, the load on a single network card is reduced, so that the effect of more balanced load is realized.
Further, before step S101, there are also problems that a certain network card receives a request packet sent by the user side, and how to send a corresponding response packet to the user side. Therefore, before step S101, steps S001 to S003 are also included, in which:
s001, acquiring a request data packet received by any network card and generating a response data packet;
specifically, in the embodiment of the present application, an example is taken where a user side sends a request packet to a router. Meanwhile, it is common knowledge of those skilled in the art how to generate the response packet after receiving the request packet, and a detailed explanation is not provided in the embodiments of the present application.
S002, determining an outgoing network card of the response data packet, wherein the outgoing network card is the network card when the request data packet enters;
and step S003, sending the response data packet through the outflow network card.
Specifically, when the user side establishes network connection with the router, the TCP link and the long link are used, and at this time, the link between the user side and one network card of the router is continuous, so that in order to ensure that the sent response data packet can be accurately sent to the user side, the response data packet should be sent through the network card receiving the request data packet.
Further, in step S002, the method for determining how to determine the outgoing network card of the response packet includes steps S0021 to S0024, where:
step S0021, generating a classification label of the request data packet based on a rule of iptables, and associating the classification label with the request data packet, wherein the classification label comprises an IP (Internet protocol) of a network card when the data packet enters and a corresponding routing table ID (identity).
And determining the type of the data packet and the IP of the network card which passes through the router when the router is transmitted according to the type of the data packet, and further determining the corresponding routing table.
And step S0022, writing the classification label and the table frame into a strategy routing table.
And writing the classification label into the strategy routing table, and matching the request data packet with the strategy routing table so as to ensure that the subsequent response data packet can realize distribution routing based on the strategy routing table.
And step S0023, configuring NAT rules of the response data packet.
Specifically, the NAT rule configuration corresponding to the answer packet is to determine the destination IP and further determine the network card IP used by the return client.
And step S0024, determining the IP of the outgoing network card based on the strategy routing table so as to determine the outgoing network card.
Specifically, the IP of the network card corresponding to the request book data packet is determined from the policy routing table, and is also determined as the network card IP corresponding to the response data packet returned to the user side, that is, the response data packet and the request book report are transmitted through the same network card, so that the response data packet can be accurately returned to the corresponding user side.
Further, before step S0022, steps SM1 (not shown) -SM3 (not shown) are further included, in which:
step SM1, judging whether the classification label is a new label;
specifically, it is determined whether the classification tag is a new tag, that is, whether the type of request packet appears for the first time, that is, whether the type of request packet is a request packet sent by a new device.
Step SM2, if yes, writing the classification label and the table frame into a strategy routing table;
specifically, if the classification tag is a new tag, that is, a request data packet sent by a new device, the step S0022 is pointed to; when the user end establishes connection with the router, the user end sends a request data packet to the router, the classification label of the data packet is identified and classified into a new label, that is, the classification label and the table frame are written into the policy routing table, because the TCP and the long link are still continuous, all the request data packets sent by the user end later can be determined as the same classification label, that is, all the response data packets corresponding to the user end can be returned through a network card.
And step SM3, if not, determining the classification label as the original label corresponding to the new label.
Further, if the classification label corresponding to a request packet is not a new label, it indicates that the user side is not a new user, and the response packet is already allocated to the corresponding network card to implement the return transmission, specifically, as long as the classification label of the packet is determined to be the original label, that is, the classification label when the user side is identified as the new label for the first time, all the response packets corresponding to the user side can be returned through the allocated network card.
Further, before step S102, step SA (not shown in the figure) -step SC (not shown in the figure) are further included, wherein:
step SA, determining a strategy routing table corresponding to each network card based on the IP of each network card;
in order to select the optimal transmission path from numerous paths, the router stores the topology information of the peripheral network and various path parameters, and the table is called a routing table; the routing table includes addresses to which the routing table can assign packets. For a service data packet, the corresponding routing table can be determined through the destination address. The policy routing table includes
Step SB, writing the IP of each network card and the routing table corresponding to each network card into a strategy routing table to obtain a configured strategy routing table;
in the embodiment of the present application, if a server side is to send a plurality of service data packets to the same user side, after determining a routing table corresponding to a destination IP of a first data packet, all the subsequent service data packets sent to the user side may be directly matched to the routing table; meanwhile, the IP corresponding to each network card is provided with a corresponding routing table, the IP of each network card and the corresponding routing table are cut into the strategy routing table, namely the strategy routing table is configured in advance, so that when the service end sends service data packets to a plurality of user ends, the router can automatically match the corresponding routing table for the data packets sent to each user end based on the strategy routing table, and further the data packets can be conveniently sent through the corresponding network card.
And step SC, configuring a preset load balancing rule for each network card.
Further, the load balancing rules of each network card may be the same or different. In the embodiment of the present application, the load balancing rules of each network card are the same. Specifically, the load balancing rule may include steps SN1 to S3, where:
and SN1, performing hash calculation based on the associated information of the service data packet to obtain an intermediate parameter M.
Specifically, the association information of each service data packet or a plurality of service data packets can be directly obtained when generating the data packet. For a service data packet, hash operation is performed on the associated information in an Iptables to obtain a positive integer. That is, performing hmark-rnd 0xface, where 0xface is a reference value, and the reference value may be preset, and is not limited herein.
And SN2, calculating the remainder of M/N, wherein N is the number of the network cards, each network card is preset with a number corresponding to the IP, the number of each network card is determined from 1-N, and the numbers of any two network cards are not repeated.
Specifically, for example, if there are 5 network cards, the numbers of the network cards are 1, 2, 3, 4, and 5 in sequence.
And SN3, if the remainder is N-1, determining the network card with the number of N as the output network card of the service data packet.
Specifically, if the remainder obtained when M is 8,8/5 is 3, the network card with the number of 4 is determined to be the transmission network card corresponding to the current service data packet.
The above embodiments describe a method for load balancing from the perspective of a method flow, and the following embodiments describe a load balancing apparatus from the perspective of a virtual module or a virtual unit, and are specifically described in the following embodiments.
An embodiment of the present application provides a load balancing apparatus, as shown in fig. 4, the apparatus 400 may specifically include a service datagram acquisition module 401, a first NAT rule configuration module 402, an output network card determination module 403, and a first sending module 404, where:
a service datagram acquiring module 401, configured to acquire service data packets, where a service data packet is a data packet that is generated based on a request data packet sent by a user terminal and is sent from a server to the user terminal, and each service data packet is associated with association information including a source port, a destination port, a source address, and a destination address;
a first NAT rule configuration module 402, configured to configure a NAT rule for each service data packet based on the relationship information;
an output network card determining module 403, configured to determine, based on each piece of association information and a preset load balancing rule, an output network card corresponding to each service data packet, where the output network card is a network card to which the service data packet is allocated for transmission;
the first sending module 404 is configured to send each service data packet through a corresponding output network card.
In one possible implementation, the apparatus 400 further includes:
the response data packet generating module is used for acquiring the request data packet received by any network card and generating a response data packet;
the outgoing network card determining module is used for determining an outgoing network card for responding the data packet, and the outgoing network card is the network card when the data packet is requested to enter;
and the second sending module is used for sending the response data packet through the outflow network card.
In a possible implementation manner, when the egress network card determining module determines the egress network card that responds to the data packet, the egress network card determining module is specifically configured to:
based on the rule of iptables, generating a classification label of the request data packet, and associating the classification label with the request data packet, wherein the classification label comprises an IP (Internet protocol) of a network card when the data packet enters and a corresponding routing table ID (identity);
writing the classification label and the table frame into a strategy routing table;
configuring NAT rules of request data packets;
an IP of the egress network card is determined based on the policy routing table to determine the egress network card.
In one possible implementation, the apparatus 400 further includes:
the judging module is used for judging whether the classification label is a new label or not;
and the original label determining module is used for determining the classification label as the original label corresponding to the new label judged by the classification label.
In one possible implementation, the apparatus 400 further includes:
the strategy routing table determining module is used for determining strategy routing tables corresponding to the network cards based on the IP of the network cards;
the write-in module is used for writing the IP of each network card and the routing table corresponding to each network card into the strategy routing table to obtain a configured strategy routing table;
and the configuration module is used for configuring a preset load balancing rule for each network card.
In one possible implementation, the load balancing rule includes:
performing hash calculation based on a source address, a source port, a destination address and a destination port of the service data packet to obtain an intermediate parameter M;
calculating the remainder of M/N, wherein N is the number of the network cards, each network card is preset with a number corresponding to the IP of the network card, the number of each network card is determined from 0-N, and the numbers of any two network cards are not repeated;
and if the remainder is N-1, determining the network card with the number of N as the output network card of the service data packet.
In an embodiment of the present application, an electronic device is provided, as shown in fig. 5, a router 500 shown in fig. 5 includes: at least two network cards, a processor 501, and a memory 503. Wherein the processor 501 is coupled to the memory 503, such as via the bus 502. Optionally, the electronic device 500 may further include a transceiver 504, and a plurality of network cards 1 … … N. It should be noted that the transceiver 504 is not limited to one in practical applications, and the structure of the electronic device 500 is not limited to the embodiment of the present application.
The Processor 501 may be a CPU (Central Processing Unit), a general-purpose Processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other Programmable logic device, a transistor logic device, a hardware component, or any combination thereof. Which may implement or perform the various illustrative logical blocks, modules, and circuits described in connection with the disclosure. The processor 501 may also be a combination of implementing computing functionality, e.g., comprising one or more microprocessors, a combination of DSPs and microprocessors, and the like.
Bus 502 may include a path that transfers information between the above components. The bus 502 may be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus 502 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 5, but this is not intended to represent only one bus or type of bus.
The Memory 503 may be a ROM (Read Only Memory) or other type of static storage device that can store static information and instructions, a RAM (Random Access Memory) or other type of dynamic storage device that can store information and instructions, an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical Disc storage, optical Disc storage (including Compact Disc, laser Disc, optical Disc, digital versatile Disc, blu-ray Disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to these.
The memory 503 is used for storing application program codes for executing the present application, and the processor 501 controls the execution. The processor 501 is configured to execute application program code stored in the memory 503 to implement the content shown in the foregoing method embodiments.
The router shown in fig. 5 is only an example, and should not bring any limitation to the function and the scope of use of the embodiments of the present disclosure.
The present application provides a computer-readable storage medium, on which a computer program is stored, which, when running on a computer, enables the computer to execute the corresponding content in the foregoing method embodiments.
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and may be performed in other orders unless otherwise indicated herein. Moreover, at least a portion of the steps in the flow chart of the figure may include multiple sub-steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed alternately or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
The foregoing is only a few embodiments of the present application and it should be noted that those skilled in the art can make various improvements and modifications without departing from the principle of the present application, and that these improvements and modifications should also be considered as the protection scope of the present application.

Claims (9)

1. A load balancing method, performed by a router, comprising:
acquiring service data packets, wherein the service data packets are generated based on request data packets sent by a user terminal and are sent to the user terminal by a server terminal, and each service data packet is associated with associated information comprising a source port, a destination port, a source address and a destination address;
configuring an NAT rule of each service data packet based on the relationship information;
determining an output network card corresponding to each service data packet based on each piece of association information and a preset load balancing rule, wherein the output network card is a network card distributed and transmitted by the service data packet;
and sending each service data packet through the corresponding output network card.
2. The method of claim 1, wherein before obtaining the service data packet, the method further comprises:
acquiring a request data packet received by any network card and generating a response data packet;
determining an outgoing network card of the response data packet, wherein the outgoing network card is the network card when the request data packet enters;
and sending the response data packet through the outflow network card.
3. The method according to claim 2, wherein the determining the egress network card of the response packet comprises:
generating a classification label of the request data packet based on a rule of iptables, and associating the classification label with the request data packet, wherein the classification label comprises a network card when the data packet enters and a corresponding routing table ID;
writing the classification label and the table frame into a strategy routing table;
configuring NAT rules of the request data packets;
determining an IP of an egress network card based on the policy routing table to determine the egress network card.
4. A method as claimed in claim 3, wherein before writing the class labels and table frames into a policy routing table, further comprising:
judging whether the classification label is a new label or not;
if yes, writing the classification label and the table frame into a strategy routing table;
if not, determining the classification label as the original label corresponding to the new label.
5. The method according to claim 1, wherein before configuring the NAT rule for each of the service packets, the method further comprises:
determining a strategy routing table corresponding to each network card based on the IP of each network card;
writing the IP of each network card and the routing table corresponding to each network card into a strategy routing table to obtain a configured strategy routing table;
and configuring a preset load balancing rule for each network card.
6. The method according to claim 1 or 5, wherein the load balancing rule comprises:
performing hash calculation based on a source address, a source port, a destination address and a destination port of the service data packet to obtain an intermediate parameter M;
calculating the remainder of M/N, wherein N is the number of the network cards, each network card is preset with a number corresponding to the IP of the network card, the number of each network card is determined from 0-N, and the numbers of any two network cards are not repeated;
and if the remainder is N-1, determining the network card with the number of N as the output network card of the service data packet.
7. A load balancing apparatus, comprising:
the service datagram acquisition module is used for acquiring service data packets, wherein the service data packets are data packets which are generated based on request data packets sent by a user terminal and are sent to the user terminal by a server terminal, and each service data packet is associated with associated information comprising a source port, a destination port, a source address and a destination address;
the first NAT rule configuration module is used for configuring the NAT rule of each service data packet based on the relationship information;
an output network card determining module, configured to determine, based on each piece of the association information and a preset load balancing rule, an output network card corresponding to each service data packet, where the output network card is a network card to which the service data packet is allocated for transmission;
and the first sending module is used for sending each service data packet through the corresponding output network card.
8. A router, the router comprising:
at least two network cards;
at least one processor;
a memory;
at least one application, wherein the at least one application is stored in the memory and configured to be executed by the at least one processor, the at least one application configured to: performing the load balancing method of any one of claims 1-6.
9. A computer-readable storage medium, comprising: a computer program which can be loaded by a processor and which executes the method according to any of claims 1-6.
CN202210790600.7A 2022-07-06 2022-07-06 Load balancing method and router Active CN115174581B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210790600.7A CN115174581B (en) 2022-07-06 2022-07-06 Load balancing method and router

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210790600.7A CN115174581B (en) 2022-07-06 2022-07-06 Load balancing method and router

Publications (2)

Publication Number Publication Date
CN115174581A true CN115174581A (en) 2022-10-11
CN115174581B CN115174581B (en) 2023-04-07

Family

ID=83491515

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210790600.7A Active CN115174581B (en) 2022-07-06 2022-07-06 Load balancing method and router

Country Status (1)

Country Link
CN (1) CN115174581B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103036801A (en) * 2012-12-18 2013-04-10 网神信息技术(北京)股份有限公司 Data package processing method and data package processing device
CN107026795A (en) * 2016-02-02 2017-08-08 上海格尔软件股份有限公司 A kind of method for returning bag extremely source network interface based on iptables and policybased routing
CN111008075A (en) * 2019-12-05 2020-04-14 安超云软件有限公司 Load balancing system, method, device, equipment and medium
CN113918326A (en) * 2021-09-29 2022-01-11 聚好看科技股份有限公司 Request processing method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103036801A (en) * 2012-12-18 2013-04-10 网神信息技术(北京)股份有限公司 Data package processing method and data package processing device
CN107026795A (en) * 2016-02-02 2017-08-08 上海格尔软件股份有限公司 A kind of method for returning bag extremely source network interface based on iptables and policybased routing
CN111008075A (en) * 2019-12-05 2020-04-14 安超云软件有限公司 Load balancing system, method, device, equipment and medium
CN113918326A (en) * 2021-09-29 2022-01-11 聚好看科技股份有限公司 Request processing method and device

Also Published As

Publication number Publication date
CN115174581B (en) 2023-04-07

Similar Documents

Publication Publication Date Title
US10027712B2 (en) System and method for distributed load balancing with distributed direct server return
US9282064B2 (en) Method for processing a plurality of data and switching device for switching communication packets
US9055076B1 (en) System and method for distributed load balancing with load balancer clients for hosts
CN110166570B (en) Service session management method and device, and electronic device
US20200120031A1 (en) Stateless distributed load-balancing
CN111010340B (en) Data message forwarding control method and device and computing device
CN111131539B (en) Message forwarding method and device
CN116633934A (en) Load balancing method, device, node and storage medium
CN113783910A (en) Data forwarding method, device and system
CN109639589B (en) Load balancing method and device
CN109413224B (en) Message forwarding method and device
CN115242711A (en) Message transmission method and device
CN113315848A (en) Access control method, device and equipment
US10229459B1 (en) Method and apparatus for routing in transaction management systems
WO2020249128A1 (en) Service routing method and apparatus
CN115174581B (en) Load balancing method and router
CN113918326A (en) Request processing method and device
CN113010314B (en) Load balancing method and device and electronic equipment
CN114338809A (en) Access control method, device, electronic equipment and storage medium
CN114285907A (en) Data transmission method and device, electronic equipment and storage medium
CN111404705B (en) SDN optimization method and device and computer readable storage medium
KR20230003490A (en) Orchestrated proxy service
CN114268630B (en) Method, device and equipment for realizing random load balancing access based on static ARP (Address resolution protocol) table items
CN113973086B (en) Data transmission method, device and storage medium
CN115412527B (en) Method and device for unidirectional communication between virtual private networks

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant