Message load balancing method and device, network equipment and computer readable storage medium
By generating and reusing optimal scheduling relationships through dynamic scheduling relationships, the problem of unbalanced packet load scheduling in embedded devices is solved, improving the packet processing capacity and resource utilization of network devices, and ensuring forwarding performance and stability.
Patent Information
- Application Number
- CN202511193555.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-25
- Publication Date
- 2025-11-18
AI Technical Summary
Existing embedded devices suffer from unbalanced resource allocation in packet load balancing, resulting in excessive or insufficient resources on some MAC ports, which affects packet forwarding efficiency. This is especially true when the number of cores and MAC ports are disproportionate, which can easily lead to lost data packets.
By obtaining the scheduling relationship identifier, it is determined whether to use the optimal scheduling relationship obtained during the initialization phase as the target scheduling relationship. When the port connectivity status remains unchanged, the existing optimization results are reused. When the connectivity status changes, load balancing is performed based on the ratio of the number of cores to the number of queues, and the target scheduling relationship is dynamically generated to achieve a reasonable match between the cores and the receiving queues.
It improves the packet processing capabilities and resource utilization of network devices, avoids scheduling bottlenecks caused by uneven resource allocation, and enhances overall forwarding performance and stability.
Smart Images

Figure CN120980083A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of data communication, in particular to a packet load balancing method and device, network equipment and computer readable storage medium. BACKGROUND
[0002] At present, with the development of cloud computing and big data technology, load balancing technology is developing towards more intelligent and automated direction. The load balancing solution in cloud environment needs to be able to automatically adapt to the dynamic changes of work load, and realize more fine and efficient resource allocation strategy. In the future, with the increase of MAC chip ports (also known as MAC ports) and bandwidth, the packet load design of MAC port will become an indispensable core competitiveness of embedded system.
[0003] At present, some embedded devices have obvious deficiencies in the intelligentization of packet load. The scheduling queue registered on each processor core (Core) is generally fixed by a soft table to fix the scheduling mode, which will cause the scheduling of some MAC ports to have excess resource allocation and the scheduling resource of some MAC ports to be insufficient, resulting in that the packet forwarding cannot achieve the best effect.
[0004] In addition, there is a case that when the number of cores and the number of MAC ports are not proportional, the load of the packet is not flexible enough. Either the cores allocated to some MAC ports are not enough, or the cores are redundant and idle, which will cause the number of received lost data packets (i.e. rxMiss) due to the short board of the receiving queue of the MAC port in the process of port performance training, so that the whole machine forwarding performance cannot achieve the best state. SUMMARY
[0005] Therefore, the present application aims to provide a packet load balancing method, device, network equipment and computer readable storage medium, which can improve the packet processing capability and resource utilization.
[0006] In order to achieve the above purpose, the technical scheme adopted by the embodiments of the present application is as follows: In a first aspect, the present application provides a packet load balancing method, which comprises: obtaining a pre-configured scheduling relationship identifier; if the scheduling relationship identifier represents the use of the optimal scheduling relationship and the current connectivity state of each port is the same as the connectivity state at the initial training, determining the optimal scheduling relationship as the target scheduling relationship; the optimal scheduling relationship is the scheduling relationship obtained by the system at the initial training; the port is the port of the MAC chip; If the scheduling relationship identifier indicates that the optimal scheduling relationship is not used or the current connectivity state of each port is different from the connectivity state at the time of initial training, load balancing is performed based on the number of cores and the number of receiving queues of each port to obtain the target scheduling relationship; Each core node schedules the corresponding receiving queue for message processing according to the target scheduling relationship.
[0007] In an optional implementation, the step of load balancing based on the number of cores and the number of receive queues on each port to obtain the target scheduling relationship includes: Determine if the number of receive queues is an integer ratio to the number of cores; If the ratio is an integer, all receiving queues are equally distributed to each core according to the ratio value to obtain the target scheduling relationship; If the ratio is not an integer, the queues are allocated to the cores sequentially according to the obtained pre-allocated quantity until the number of unallocated receive queues and unallocated cores are the same. Then, the unallocated queues are evenly distributed to the unallocated cores to obtain the target scheduling relationship. The pre-allocated quantity is obtained by adjusting the number of receive queues created for each port. After the total number of received queues created is greater than the total number of cores, the ratio of the total number of receive queues to the total number of cores is rounded up.
[0008] In an optional implementation, the method further includes: periodically adjusting the service load of the ports based on the number of packet losses received at each port, specifically including: Iterate through and count the number of packets lost when the receive queue of each port is scheduled in the current period; If there is a first port where the number of packet losses in the current period is greater than the number of packet losses in the previous period, reduce the proportion of packets sent to the first port according to the preset adjustment ratio. If there is a second port where the number of packet losses in the current period is equal to the number of packet losses in the previous period, the proportion of packets sent to the second port is increased according to a preset adjustment ratio.
[0009] In an optional implementation, the optimal scheduling relationship is obtained in the following way: Multiple candidate scheduling relationships are generated based on the number of cores and the number of ports; The packet loss count of all ports is cleared to zero. Messages are sent and received based on each of the candidate scheduling relationships, and the packet loss count of the receiving queue of each port corresponding to each candidate scheduling relationship is counted. Calculate the receiving packet loss variance sort and the receiving packet loss total sort for each candidate scheduling relationship based on the number of packet losses in the receiving queues of all ports corresponding to each candidate scheduling relationship, and calculate the comprehensive ranking evaluation value of each candidate scheduling relationship according to the receiving packet loss variance sort and the receiving packet loss total sort based on the preset weights. The candidate scheduling relationship with the smallest comprehensive ranking evaluation value is determined as the optimal scheduling relationship.
[0010] In an optional implementation, sending and receiving messages based on each candidate scheduling relationship, and counting the number of packet losses in the receive queue of each port corresponding to each candidate scheduling relationship, includes: Configure the switch chip panel port to establish a loopback connection and perform message flooding; the flooded messages are sent to each receive queue, and after being received by the corresponding core, they are sent out from that receive queue; after waiting for a preset statistical time, the number of lost packets in each receive queue is counted.
[0011] In an optional implementation, if the number of ports is an integer ratio to the number of cores, generating multiple candidate scheduling relationships based on the number of cores and the number of ports includes: A positive integer not exceeding the chip queue threshold is selected sequentially as the number of queues for the receiving queue corresponding to each port; Create a corresponding receive queue for each port according to the number of queues; Based on the number of queues, the number of ports, and the number of cores, all receiving queues are equally distributed to each core, resulting in multiple candidate scheduling relationships.
[0012] In an optional implementation, if the number of ports is not an integer proportion to the number of cores, generating multiple candidate scheduling relationships based on the number of cores and the number of ports includes: The total number of receive queues is determined by the least common multiple of the number of cores and the number of ports; a corresponding receive queue is created for each port according to the ratio of the total number of receive queues to the number of ports; and a receive queue is allocated to each core according to the ratio of the total number of receive queues to the number of cores to obtain a first candidate scheduling relationship. When the number of cores is greater than the number of ports, a core with the same number of ports is randomly selected from multiple cores, and the selected core is matched one-to-one with the port; positive integers not exceeding the chip queue threshold are selected sequentially as the number of receive queues corresponding to each port; a corresponding receive queue is created for each port according to the number of receive queues, and the created receive queues are assigned to the job cores matched with the port to obtain the second candidate scheduling relationship; The total number of queues is determined based on the number of cores and the number of ports, such that the total number of queues is greater than the number of cores; the ratio of the total number of queues to the number of cores is rounded up to obtain the pre-allocated quantity; a corresponding receiving queue is created for each port according to the ratio of the total number of queues to the number of ports; the receiving queues are allocated to the cores sequentially according to the pre-allocated quantity until the number of remaining receiving queues is the same as the number of remaining cores, and the remaining receiving queues are evenly distributed to the remaining cores to obtain the third candidate scheduling relationship; The first candidate scheduling relationship, the second candidate scheduling relationship, and the third candidate scheduling relationship constitute multiple candidate scheduling relationships.
[0013] In a second aspect, the present invention provides a message load balancing device, the device comprising: The acquisition module is used to acquire pre-configured scheduling relationship identifiers; The determination module is used to identify the optimal scheduling relationship as the target scheduling relationship, where the scheduling relationship identifier indicates that the optimal scheduling relationship is used and the current connectivity state of each port is the same as the connectivity state during initial training; the optimal scheduling relationship is the scheduling relationship initially obtained by the system through training; the port is the port of the MAC chip. The determination module is further configured to perform load balancing based on the number of cores and the number of receiving queues at each port if the scheduling relationship identifier indicates that the optimal scheduling relationship is not used or the current connectivity state of each port is different from the connectivity state at the time of initial training, in order to obtain the target scheduling relationship. The scheduling module is used by each core to schedule the corresponding receiving queue for message processing according to the target scheduling relationship.
[0014] Thirdly, the present invention provides a network device including a processor and a memory, wherein the memory stores a computer program executable by the processor, and the processor can execute the computer program to implement the packet load balancing method described in any of the foregoing embodiments.
[0015] Fourthly, 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 message load balancing method as described in any of the foregoing embodiments.
[0016] Compared to existing technologies, the packet load balancing method, apparatus, network device, and computer-readable storage medium provided in this invention determine whether to use the optimal scheduling relationship obtained during the initialization phase as the target scheduling relationship by obtaining a scheduling relationship identifier. This allows for direct reuse of existing optimization results when port connectivity remains unchanged, improving scheduling efficiency after network device startup. When the optimal scheduling relationship is not enabled or port connectivity has changed, load balancing is performed based on the ratio between the number of cores and the number of queues, dynamically generating the target scheduling relationship. Each core processes packets in its corresponding receive queue based on the target scheduling relationship, achieving a reasonable match between cores and receive queues in a multi-core, multi-queue environment. This avoids scheduling bottlenecks caused by uneven resource allocation, improving the packet processing capacity and resource utilization of the network device.
[0017] 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
[0018] 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.
[0019] Figure 1 This diagram illustrates a prior art method that relies on static soft table configuration scheduling relationships.
[0020] Figure 2 This diagram illustrates a flowchart of a message load balancing method provided in an embodiment of the present invention.
[0021] Figure 3 This diagram illustrates another flowchart of the message load balancing method provided in an embodiment of the present invention.
[0022] Figure 4 This diagram illustrates a construction scheduling relationship provided by an embodiment of the present invention.
[0023] Figure 5 This illustration shows another schematic diagram of the construction scheduling relationship provided by an embodiment of the present invention.
[0024] Figure 6 This illustration shows another schematic diagram of the construction scheduling relationship provided by an embodiment of the present invention.
[0025] Figure 7 This illustration shows another schematic diagram of the construction scheduling relationship provided by an embodiment of the present invention.
[0026] Figure 8 This illustration shows another schematic diagram of the construction scheduling relationship provided by an embodiment of the present invention.
[0027] Figure 9 This diagram shows a block illustration of a message load balancing device provided in an embodiment of the present invention.
[0028] Figure 10 A block diagram of a network device provided in an embodiment of the present invention is shown.
[0029] Icons: 300 - Message load balancer; 301 - Acquisition module; 302 - Determination module; 303 - Scheduling module; 400 - Network device; 410 - Processor; 420 - Memory; 430 - MAC chip; 440 - Switching chip. Detailed Implementation
[0030] 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.
[0031] 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.
[0032] 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.
[0033] In network devices, multi-core processors bind to multiple ports of a MAC (Media Access Control) chip through a multi-queue mechanism. Each core is responsible for processing packets in the receive queue created by the port of its bound MAC chip. The ports of the MAC chip, in turn, correspond one-to-one with the uplink ports of the switching chip, forming a data path for receiving packets. Figure 1 As shown. Figure 1 In this system, the switching chip includes multiple panel ports (ports visible to the user on the front panel of the network device), which establish data paths with other network devices. The aggregation group of the switching chip includes multiple uplink ports. Each uplink port transmits received packets to the port of the MAC chip, and then the port of the MAC chip stores the received packets in its receive queue. The CPU core retrieves packets from the corresponding receive queue through queue scheduling.
[0034] However, in existing technologies, the scheduling relationship between cores and port queues is typically configured using static software tables, lacking scientific data support and unable to determine whether the current binding is optimal, relying entirely on experience. Furthermore, the scheduling relationship between cores and port queues cannot be dynamically adjusted during device operation, lacking responsiveness to real-time load conditions. When the number of cores and ports is disproportionate, existing mechanisms cannot flexibly reallocate resources, resulting in some cores being idle and some ports being overloaded, causing a decrease in overall forwarding efficiency, and even packet loss due to port packet reception bottlenecks, affecting the overall forwarding performance of the machine.
[0035] Based on this, embodiments of the present invention provide a message load balancing method, apparatus, network device, and computer-readable storage medium. The method can flexibly configure the scheduling relationship between the receiving queues of the core and ports under different operating states, thereby improving the message processing capability and resource utilization of the network device.
[0036] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0037] Please refer to Figure 2 , Figure 2 A schematic flowchart of a message load balancing method provided by an embodiment of the present invention is shown. The method includes the following steps: Step S100: Obtain the pre-configured scheduling relationship identifier.
[0038] In this embodiment of the invention, the network device can operate in normal mode and intelligent mode, and the two modes can be switched via commands. When the network device is operating in normal mode, each core scheduling queue is bound to a fixed soft table after the network device starts. The scheduling method of the soft table can be manually adjusted via commands or issued using default configuration, and the configuration will not be lost upon restart.
[0039] In intelligent mode, adaptive training mode and automatic adjustment mode are supported, distinguished by a scheduling relationship identifier. If the scheduling relationship identifier indicates that the optimal scheduling relationship is used, it is in adaptive training mode; otherwise, it is in automatic adjustment mode. The scheduling relationship identifier is a parameter set by the network device before operation via a configuration file or command line. It indicates whether the optimal scheduling relationship obtained during the adaptive training phase is used for packet scheduling after the network device starts up.
[0040] Step S110: If the scheduling relationship identifier indicates the use of the optimal scheduling relationship and the current connectivity state of each port is the same as the connectivity state during initial training, the optimal scheduling relationship is determined as the target scheduling relationship; the optimal scheduling relationship is the scheduling relationship obtained by the system through initial training; the port is the port of the MAC chip.
[0041] In this embodiment of the invention, when the scheduling relationship identifier indicates the use of the optimal scheduling relationship, the current connectivity state of each port is obtained. The current connectivity state includes the port number and connectivity state (link state) of each port in the MAC chip. The current connectivity state is compared with the connectivity state recorded during the adaptive training phase (i.e., the connectivity state during initial training). If the two are consistent, it indicates that the link state of each port of the network device has not changed. In this case, using the optimal scheduling relationship obtained through pre-training as the target scheduling relationship has high applicability and stability. Here, the optimal scheduling relationship refers to a set of scheduling methods obtained through the adaptive training mode during the device initialization phase. This scheduling method corresponds to a small number of packet losses and a balanced packet loss distribution during the training process.
[0042] Step S120: If the scheduling relationship identifier indicates that the optimal scheduling relationship is not used or the current connectivity state of each port is different from the connectivity state during initial training, load balancing is performed based on the number of cores and the number of receiving queues for each port to obtain the target scheduling relationship.
[0043] In this embodiment of the invention, if the current connectivity state is inconsistent with the connectivity state during initial training, it indicates that the link state of some ports of the network device has changed (e.g., the link state of the port changes from up to down). The original optimal scheduling relationship may no longer be applicable, which will trigger the replanning of the scheduling relationship to avoid invalid scheduling and further improve packet processing efficiency.
[0044] When the scheduling relationship identifier does not use the optimal scheduling relationship or the current connectivity state is different from the connectivity state at the time of initial training, a new scheduling relationship is dynamically calculated and generated as the target scheduling relationship based on the ratio between the number of available cores and the number of receiving queues in the current running state.
[0045] It should be understood that this step aims to achieve a reasonable match between core resources and the receiving queue, avoiding situations where some cores are idle or some ports lack sufficient scheduling resources, thereby improving overall packet processing performance. The load balancing calculation process includes determining whether the cores and the receiving queue are in an integer ratio, and generating scheduling relationships based on whether the ratio is integer or not using different allocation strategies.
[0046] It should be noted that the target scheduling relationship can be a table-like storage structure, where each record represents the scheduling relationship between a core and at least one receive queue. The receive queue is a data structure used to store packets received on its port. In actual operation, the core retrieves packets from the corresponding receive queue through the queue list recorded in the target scheduling relationship for processing, thereby achieving load balancing scheduling in a multi-core, multi-queue environment.
[0047] In step S130, each core schedules the corresponding receiving queue for message processing according to the target scheduling relationship.
[0048] In this embodiment of the invention, when the core performs message scheduling, it sequentially retrieves messages from the receiving queue recorded in the target scheduling relationship and processes the retrieved messages.
[0049] As one possible implementation, suppose a receive queue A is set up on port A. All packets received by port A will be stored in receive queue A. The core mechanism that establishes a scheduling relationship with receive queue A retrieves packets from receive queue A for processing. If receive queue A is full, packets received by port A will be discarded, and the packet loss count for port A will increase.
[0050] As another possible implementation, suppose a receive queue B and a receive queue C are set up on port B. Then, according to preset rules, the received packets on port B are distributed and stored in receive queues B and C. The core that establishes a scheduling relationship with receive queue B retrieves packets from receive queue B for processing, and the core that establishes a scheduling relationship with receive queue C retrieves packets from receive queue C for processing. When receive queues B and C are full, the packets received by port B will be discarded, increasing the corresponding packet loss count for port B.
[0051] In summary, the packet load balancing method provided in this embodiment of the invention determines whether to use the optimal scheduling relationship obtained during the initialization phase as the target scheduling relationship by obtaining the scheduling relationship identifier. This allows for direct reuse of existing optimization results when the port connectivity status remains unchanged, improving scheduling efficiency after network device startup. When the optimal scheduling relationship is not enabled or the port connectivity status has changed, load balancing is performed based on the ratio between the number of cores and the number of queues, dynamically generating the target scheduling relationship. Each core processes packets in its corresponding receive queue based on the target scheduling relationship, achieving a reasonable match between cores and receive queues in a multi-core, multi-queue environment. This avoids scheduling bottlenecks caused by uneven resource allocation and improves the packet processing capacity and resource utilization of the network device.
[0052] It should be noted that in special environments or application scenarios, it is necessary to adjust to a specific scheduling relationship. The scheduling method can be specified using the default configuration, and the configuration will be retained after the network device restarts. When the automatically generated scheduling relationship cannot meet the requirements, the scheduling relationship can be configured manually.
[0053] Alternatively, the following is one possible implementation for dynamically generating target scheduling relationships. Figure 2 The sub-steps of step S120 may include: Step S120-1: Determine whether the number of receiving queues is in an integer ratio to the number of cores.
[0054] In this embodiment of the invention, the ratio (i.e., the proportion value) between the number of receiving queues and the number of cores is calculated to determine whether the two are divisible or have an integer multiple relationship. If the proportion value is an integer, the number of receiving queues is considered to be in an integer proportion to the number of cores, and an equal distribution strategy can be directly used for allocation. If the proportion value is not an integer, the number of queues is considered to be in an integer proportion to the number of cores, and a more complex allocation mechanism is required to achieve load balancing.
[0055] Step S120-2: If the ratio is an integer, distribute all receiving queues equally to each core according to the ratio value to obtain the target scheduling relationship.
[0056] In this embodiment of the invention, when the determination result is an integer ratio, the ratio of the number of queues to the number of cores is taken as the number to be allocated, and the allocated number of receive queues is assigned to each core sequentially. A target scheduling relationship is obtained based on the cores and the receive queues allocated to them. This target scheduling relationship ensures that each core is bound to the same number of receive queues, thereby avoiding overload or idleness of some cores and improving the resource utilization of network devices. For example, when the number of receive queues is 12 and the number of cores is 4, the ratio is 3, and each core will be bound to 3 receive queues, thus achieving a balanced distribution of receive queues among the cores.
[0057] Step S120-3: If the ratio is not an integer, allocate queues to the cores sequentially according to the obtained pre-allocated quantity until the number of unallocated receive queues and the number of unallocated cores are the same. Then, distribute the unallocated queues equally to the unallocated cores to obtain the target scheduling relationship. The pre-allocated quantity is obtained by adjusting the number of receive queues created on each port. After the total number of all received queues created is greater than the total number of cores, the ratio of the total number of receive queues to the total number of cores is rounded up.
[0058] In this embodiment of the invention, a pre-allocated number is obtained by rounding up the ratio of the number of receive queues to the number of cores. Then, receive queues are allocated to cores sequentially according to the pre-allocated number until the number of unallocated receive queues equals the number of unallocated cores. Subsequently, the unallocated queues are evenly distributed to the remaining unallocated cores. To further ensure load balancing across cores, the load ratio of the port containing the receive queues bound to the core is adjusted to a ratio of 1 to the allocated number, based on the pre-allocated number.
[0059] Assuming there are 7 cores and 8 receive queues, the pre-allocation quantity is 2 (i.e., 8 divided by 7 and rounded up). Two receive queues are allocated to one core, and the uplink load ratio of the port where the receive queue is located is set to 50%. The remaining 6 cores each share one receive queue, and the uplink load ratio of the port where the receive queue is located is set to 100%.
[0060] As can be seen, in this embodiment of the invention, when the number of cores and the number of receive queues are in an integer ratio, all receive queues are evenly distributed among the cores according to the ratio, thereby achieving a balanced configuration of receive queues among the cores and ensuring the rational utilization of scheduling resources. When the ratio is not an integer, a pre-allocated number is dynamically calculated based on the current number of cores and the number of receive queues, and receive queues are continuously allocated to cores according to the pre-allocated number until the number of unallocated receive queues equals the number of unallocated cores. The remaining receive queues are then evenly distributed among the remaining cores, and the load ratio of the corresponding ports is adjusted according to the pre-allocated number, thereby further improving the balance of resource allocation. By distinguishing between integer ratios and adopting different allocation strategies, a reasonable scheduling relationship can be established between cores and receive queues, making the load of each core more balanced, avoiding resource waste or scheduling bottlenecks, and thus improving the packet processing efficiency and system stability of network devices.
[0061] Optionally, the method also includes periodically adjusting the service load of the port based on the number of packet losses received by each port. As for how to dynamically adjust the service load of the port, a possible implementation method is provided below.
[0062] The first step is to iterate through and count the number of packets lost when the receiving queues of each port are scheduled in the current period.
[0063] In this embodiment of the invention, a periodic task is set up to perform a dynamic adjustment operation of the service load once every certain time interval (e.g., t minutes). Specifically, the number of packet loss of received packets recorded by the hardware statistics module for each port in the current period is read sequentially, and the number of packet loss in the current period is saved for use in the port load adjustment operation of the next period. Among them, the number of packet loss is an important indicator for measuring whether the port scheduling resources are sufficient, and its increase or decrease reflects the change of scheduling pressure on the port under the current load ratio.
[0064] The second step is to reduce the proportion of packets sent to the first port if the number of packet losses in the current period is greater than the number of packet losses in the previous period.
[0065] In this embodiment of the invention, the number of packet losses in the current period is compared with the number of packet losses in the previous period to identify ports where the number of packet losses is increasing. If the number of packet losses in the current period for a port is greater than the number of packet losses in the previous period, it indicates that the port is experiencing packet loss in the current period, and this port is defined as the first port. An increase in the number of packet losses for the first port indicates that the current service load of the first port is high and the scheduling resources are insufficient, which may affect the overall forwarding performance. Therefore, the load ratio corresponding to the first port is reduced according to a preset adjustment ratio (e.g., 5%), that is, the proportion of packets sent from the uplink port of the switching chip to the first port is reduced, so as to reduce the scheduling pressure of the first port and avoid further increase in the packet loss rate.
[0066] The third step is to increase the proportion of packets sent to the second port according to the preset adjustment ratio if there is a second port where the number of packets lost in the current period is equal to the number of packets lost in the previous period.
[0067] In this embodiment of the invention, if the number of packet losses in the current period corresponding to a port is equal to the number of packet losses in the previous period, it indicates that the port has not experienced packet loss in the current period, and this port is defined as the second port. The fact that the second port has not experienced packet loss in the current period indicates that the second port currently has sufficient scheduling resources and the ability to handle more service load. Therefore, the load ratio of the second port is appropriately increased according to a preset adjustment ratio (e.g., 5%), that is, the proportion of packets sent from the uplink port of the switching chip to the second port is increased, in order to improve the resource utilization and forwarding efficiency of the network device.
[0068] As can be seen, the embodiments of the present invention dynamically adjust the uplink load ratio of packets on the switching chip side according to the actual packet loss trend of received packets at the port without manual intervention, so as to realize the dynamic adjustment of the load distribution of each MAC port, making the scheduling resources more reasonable, realizing the on-demand load of packets between the uplink port of the switching chip and the port of the MAC chip, thereby effectively reducing the packet loss rate and improving the packet forwarding efficiency and stability of network devices.
[0069] Optionally, regarding how to generate the optimal scheduling relationship during the initialization phase, the following is a possible implementation method. Please refer to... Figure 3 The message load balancing method also includes the following steps: Step S200: Generate multiple candidate scheduling relationships based on the number of cores and the number of ports.
[0070] In this embodiment of the invention, the optimal scheduling relationship is determined by selecting the scheduling method with the best performance after comprehensive evaluation based on multiple candidate scheduling relationships generated through adaptive training mode during the initialization phase and the packet loss situation of each port during actual training. First, the scheduling relationship between the receiving queues on the cores and ports is constructed according to the number of cores and the number of ports, and the corresponding candidate scheduling relationships are obtained in sequence.
[0071] Step S210: Clear the packet loss count of all ports to zero, send and receive messages based on each candidate scheduling relationship, and count the packet loss count of the receiving queue of each port corresponding to each candidate scheduling relationship.
[0072] In this embodiment of the invention, after each candidate scheduling relationship is generated, the packet loss count of all ports is reset to zero to ensure the consistency of training conditions. Next, the generated candidate scheduling relationships are simulated. Packets are sent to the receiving queue according to the candidate scheduling relationship and processed by the corresponding core. The corresponding core then sends the received packets out of the original receiving queue. After a period of time, the packet loss count of each port under the candidate scheduling relationship is recorded by simulating a real business load environment.
[0073] Step S220: Calculate the receiving packet loss variance sort and the receiving packet loss total sort for each candidate scheduling relationship based on the number of packet losses in the receiving queues of all ports corresponding to each candidate scheduling relationship, and calculate the comprehensive ranking evaluation value of each candidate scheduling relationship according to the receiving packet loss variance sort and the receiving packet loss total sort based on the preset weights.
[0074] In this embodiment of the invention, the number of packet loss for each port under each candidate scheduling relationship is obtained through the above training. The number of packet loss for each port under each candidate scheduling relationship is summed to obtain the total number of received packet loss for each candidate scheduling relationship. The total number of received packet loss is then sorted in ascending order to obtain the sorted total number of received packet loss for each total number of received packet loss.
[0075] The variance of the number of packets lost at each port under each candidate scheduling relationship is calculated to obtain the received packet loss variance corresponding to each candidate scheduling relationship. The received packet loss variances are then sorted in ascending order to obtain the received packet loss variance sorting corresponding to each received packet loss variance.
[0076] Obtain preset weights, including sum weight and variance weight. Calculate the comprehensive evaluation value for each candidate scheduling relationship based on the sum weight, variance weight, the received packet loss variance ranking, and the received packet loss sum ranking corresponding to each candidate scheduling relationship. The formula for calculating the comprehensive evaluation value is as follows:
[0077] in, For comprehensive evaluation, For the total weight, For variance weights, Sort by the total number of lost packets received. Sort by packet loss variance. .
[0078] Step S230: The candidate scheduling relationship with the smallest comprehensive ranking evaluation value is determined as the optimal scheduling relationship.
[0079] In this embodiment of the invention, the comprehensive evaluation values corresponding to each candidate scheduling relationship are compared, and the candidate scheduling relationship with the smallest comprehensive evaluation value is determined as the optimal scheduling relationship. The optimal scheduling relationship represents a scheduling relationship with a small number of packet losses and a balanced packet loss distribution under the current core and port configuration. The optimal scheduling relationship determined thereby will be used as the recommended configuration during the initialization phase and recorded in the global table. In subsequent operation, it can be determined whether to continue using the optimal scheduling relationship or to redistribute the load balancer based on the scheduling relationship identifier and port connectivity status.
[0080] As can be seen, this embodiment of the invention generates multiple candidate scheduling relationships based on the number of cores and ports, and trains each candidate scheduling relationship on packet transmission and reception under the same training conditions to count the number of packet losses on each port. This allows for the selection of a scheduling relationship that performs optimally in terms of total packet loss and balanced packet loss distribution under specific port connectivity conditions. This provides a high-performance initial scheduling configuration for subsequent operation phases, improving packet processing efficiency and reducing packet loss risk. Compared to manually training to determine scheduling relationships, this embodiment of the invention determines the optimal scheduling relationship through an adaptive training mode, reducing manual training time and accelerating the convergence time of performance training.
[0081] Optionally, the following is a possible implementation method for counting the number of lost packets in the receive queue of each port. Figure 2 The sub-steps of step S210 may include: Configure the switch chip panel port to establish a loopback connection and perform message flooding; the flooded messages are sent to each receive queue, and after being received by the corresponding core, they are sent out from that receive queue; after waiting for a preset statistical time, the number of lost packets in each receive queue is counted.
[0082] In this embodiment of the invention, the switch chip's panel port is configured to self-loop, and active packet flooding is performed to form a continuous packet storm. The self-loop connection of the switch chip's panel port refers to a configuration where the physical port of the switch chip is connected in a closed loop with the internal CPU path of the device, allowing packets to be continuously sent back to the transmission path.
[0083] Relying on the configured self-loop path, storm packets can be sent to each receive queue and processed by the core bound to that queue. After processing, the packet is sent out again from the original receive queue, forming a closed-loop flow. After waiting for a preset statistical time, the number of packet losses for each receive queue is counted by reading the rxMiss counter in the hardware register.
[0084] As can be seen, the embodiments of the present invention perform message flooding through the self-loop connection of the switching chip panel port. Without relying on the external network environment, the queue scheduling performance under the candidate scheduling relationship is independently evaluated. This provides an accurate data foundation for subsequent calculation of the comprehensive evaluation value based on the sorting of the total received packet loss and the sorting of the received packet loss variance, ensuring that the selected optimal scheduling relationship has the best load balancing capability.
[0085] Alternatively, when the number of ports is an integer ratio to the number of cores, the following is a possible implementation for generating candidate scheduling relationships. Figure 2 The sub-steps of step S200 may include: Step S200-1: Select positive integers that do not exceed the chip queue threshold as the number of queues for the receiving queue corresponding to each port.
[0086] In this embodiment of the invention, when the ratio of the number of ports to the number of cores is an integer, it is considered that the number of ports and the number of cores are in an integer ratio; otherwise, it is considered that the number of ports and the number of cores are not in an integer ratio. When the number of ports and the number of cores are in an integer ratio, all ports are equally distributed to each core, and a positive integer not exceeding the chip queue threshold is selected sequentially as the number of queues for the receiving queue corresponding to each port.
[0087] Step S200-2: Create a corresponding receive queue for each port according to the number of queues.
[0088] Step S200-3: Based on the number of queues, ports, and cores, all receiving queues are equally distributed to each core to obtain multiple candidate scheduling relationships.
[0089] In this embodiment of the invention, for each number of queues, a corresponding number of receive queues are created for each port, and the created receive queues are evenly distributed to each core to obtain the candidate scheduling relationship corresponding to each number of queues.
[0090] As one possible implementation, Figure 4For example, ports A and B are assigned to core 1, and ports C and D are assigned to core 2. Assuming the chip queue threshold is 3, values 1, 2, and 3 are used sequentially as the number of receive queues that can be created for each port. When the number of queues is 1, a receive queue is created for each of the four ports. The receive queues for ports A and B are assigned to core 1, and the receive queues for ports C and D are assigned to core 2, generating candidate scheduling relationships corresponding to a single port with 1 queue.
[0091] When the number of queues is 2, two receive queues are created for each of the four ports. The two receive queues of port A and port B are assigned to core 1, and the two receive queues of port C and port D are assigned to core 2, generating candidate scheduling relationships corresponding to the number of queues for each port.
[0092] When the number of queues is 3, three receive queues are created for each of the four ports. The three receive queues of port A and port B are assigned to core 1, and the three receive queues of port C and port D are assigned to core 2, generating candidate scheduling relationships corresponding to the number of queues of 3 per port.
[0093] Therefore, based on a chip queue threshold of 3, three candidate scheduling relationships can be generated. It should be noted that the number of queues is a positive integer not exceeding the chip queue threshold; it can be consecutive positive integers or non-consecutive positive integers. For example, if the chip queue threshold is 4, 1, 2, 3, and 4 can be selected as the number of queues in sequence, or 2 and 4 can be selected as the number of queues; this invention does not limit the selection.
[0094] As can be seen, in the embodiments of the present invention, when the number of ports and cores are in an integer ratio, multiple load distribution modes can be flexibly constructed by iterating and adjusting the number of queues corresponding to a single port, thereby covering the scheduling configuration requirements under different scheduling intensities. This provides sufficient candidate samples for subsequent evaluation and selection of the optimal scheduling relationship, and improves the system's adaptability and load balancing effect under different business scenarios.
[0095] Alternatively, when the number of ports is not in an integer ratio to the number of cores, the following is a possible implementation for generating candidate scheduling relationships. Figure 2 The sub-steps of step S200 may include: Step S200-4: Determine the total number of receive queues by the least common multiple of the number of cores and the number of ports; create a corresponding receive queue for each port according to the ratio of the total number of receive queues to the number of ports; allocate a receive queue to each core according to the ratio of the total number of receive queues to the number of cores to obtain the first candidate scheduling relationship.
[0096] In this embodiment of the invention, the least common multiple (LCM) is calculated based on the number of cores and the number of ports, and this LCM is determined as the total number of receive queues. The LCM is the smallest positive integer that is divisible by both the number of cores and the number of ports. Figure 5 For example, assuming the number of cores is 3 and the number of ports is 2, then the total number of receive queues is 6.
[0097] After determining the total number of receive queues, the number of receive queues that should be created for each port is calculated based on the ratio of the total number of receive queues to the number of ports. Continuing... Figure 5 For example, if the total number of receive queues is 6 and the number of ports is 2, then 3 receive queues are created for each port.
[0098] Based on the ratio of the total number of receive queues to the number of cores, the receive queues are evenly distributed among the cores to obtain the first candidate scheduling relationship. Continuing with... Figure 5 For example, there are three cores: Core 1, Core 2, and Core 3, and two ports: Port A and Port B. Port A and Port B each create three receive queues, labeled 1, 2, and 3 respectively. Based on the ratio of the total number of receive queues to the number of cores, two receive queues are allocated to each core. For instance, queues 1 and 2 of Port A are assigned to Core 1, queue 3 of Port A and queue 1 of Port B are assigned to Core 2, and queues 2 and 3 of Port B are assigned to Core 3.
[0099] It should be understood that the queue is evenly divided and allocated by using the least common multiple of the number of cores and the number of ports. This allows for the construction of a structurally balanced and reasonably distributed scheduling relationship even when the number of ports and cores is not in an integer ratio. This provides candidate samples with good load distribution characteristics for subsequent scheduling relationship evaluation and improves the load balancing capability of network devices under non-integer ratio configurations.
[0100] Step S200-5: When the number of cores is greater than the number of ports, randomly select the same number of cores as the number of ports from multiple cores, and match the selected cores with the ports one-to-one; sequentially select positive integers not exceeding the chip queue threshold as the number of receive queues corresponding to each port; create a corresponding receive queue for each port according to the number of receive queues, and assign the created receive queues to the job cores that match the ports to obtain the second candidate scheduling relationship.
[0101] In this embodiment of the invention, when the number of cores exceeds the number of ports, cores equal in number to the number of ports can be randomly selected to participate in packet scheduling to achieve load balancing. This avoids the scheduling complexity caused by all cores participating in the scheduling relationship construction and improves the executability and stability of the scheduling relationship. A one-to-one matching relationship is established between job cores and ports, such as...Figure 6 As shown. Figure 6 Cores 1 to 4 are selected as cores to participate in message scheduling (i.e., job cores); cores 5 to 7 are idle cores and do not participate in message scheduling.
[0102] The number of receive queues is a positive integer not exceeding the chip queue threshold. It can be a consecutive positive integer or a non-consecutive positive integer. For example, if the chip queue threshold is 4, 1, 2, 3, and 4 can be selected as the number of receive queues in sequence, or 2 and 4 can be selected. This invention does not limit the selection. For each number of receive queues, a corresponding receive queue is created for each port, and the port's receive queue is assigned to the matching job core, thereby constructing a second candidate scheduling relationship.
[0103] It should be understood that by limiting the number of cores actually involved in scheduling, the complexity and redundancy of resource allocation can be avoided in the case of core surplus. At the same time, combined with the adjustable number of receiving queues, the diversity of candidate scheduling relationships can be further enriched, and the flexibility and load balancing effect of the system in core resource redundancy scenarios can be improved.
[0104] Step S200-6: Determine the total number of queues based on the number of cores and the number of ports, so that the total number of queues is greater than the number of cores; round up the ratio of the total number of queues to the number of cores to obtain the pre-allocated number; create a corresponding receive queue for each port according to the ratio of the total number of queues to the number of ports; allocate receive queues to the cores in sequence according to the pre-allocated number until the number of remaining receive queues is the same as the number of remaining cores, and then distribute the remaining receive queues equally to the remaining cores to obtain the third candidate scheduling relationship.
[0105] In this embodiment of the invention, a suitable total number of queues is calculated based on the relationship between the number of cores and the number of ports. The total number of queues needs to meet two conditions: first, it must be greater than the minimum number of cores to ensure that each core can participate in packet scheduling; second, the total number of queues must be divisible by the number of ports.
[0106] After determining the total number of queues, calculate the ratio of the total number of queues to the number of cores, and round this ratio up to obtain an integer as the pre-allocated quantity. Based on the ratio of the total number of queues to the number of ports, create the same number of receive queues for each port to achieve a balanced distribution on the port side.
[0107] After the port-side receive queue is created, the cores are allocated queues according to the pre-allocated number. When the number of remaining queues is the same as the number of remaining cores, the remaining queues are divided equally, so that each remaining core is allocated one queue, and a third candidate scheduling relationship is generated.
[0108] As one possible implementation, Figure 7 For example, the processor contains 7 cores and the MAC chip contains 4 ports. The total number of queues is calculated based on the number of cores and ports. The total number of queues is 8, which is the smallest integer greater than the number of cores (7). The pre-allocation quantity is calculated based on the total number of queues (8) and the number of cores (7). The pre-allocation quantity is 2. Assuming that 2 receive queues are allocated to core 1, then there are 6 receive queues and 6 cores left. The 6 receive queues are then allocated to the 6 cores respectively.
[0109] As another possible implementation, Figure 8 For example, the processor contains 6 cores and the MAC chip contains 4 ports. The total number of queues is calculated based on the number of cores and ports, and the total number of queues is 8, which is the smallest integer greater than the number of cores (6). The pre-allocation quantity is calculated based on the total number of queues (8) and the number of cores (6), and the pre-allocation quantity is 2. Assuming that 2 receive queues are allocated to core 1 and core 2 respectively, then there are 4 receive queues and 4 cores left. The 4 receive queues are then allocated to the 4 cores respectively.
[0110] It should be noted that when two receive queues are assigned to the same core, the load ratio of the ports where the two receive queues reside is set to 50%. When one queue is assigned to one core, the load ratio of the port where the queue resides is set to 100%.
[0111] It should be understood that by setting the total number of queues to be greater than the number of cores and divisible by the number of ports, reasonable queue allocation can still be achieved even when the ratio of ports to cores is not an integer. This balances load differences between cores with allocation fairness, further expands the coverage of candidate scheduling relationships, and improves the load balancing capabilities and resource configuration flexibility of network devices in non-integer allocation scenarios.
[0112] Step S200-7: The first candidate scheduling relationship, the second candidate scheduling relationship, and the third candidate scheduling relationship constitute multiple candidate scheduling relationships.
[0113] In this embodiment of the invention, the first candidate scheduling relationship, the second candidate scheduling relationship, and the third candidate scheduling relationship correspond to different resource allocation strategies and are applicable to different ratios of cores and ports. By comprehensively applying different scheduling methods, multiple candidate scheduling relationships can be generated even when the ratio of ports to cores is not an integer. This provides sufficient evaluation samples for performance training in the subsequent initialization phase, thereby ensuring that the optimal scheduling relationship with the fewest packet losses and the most balanced packet loss distribution can be selected.
[0114] As can be seen, in cases where the number of ports and cores is disproportionate, the embodiments of the present invention construct diverse scheduling relationships based on multiple preset scheduling methods, thereby effectively covering the binding modes of cores and receiving queues under different load distribution scenarios. This provides sufficient candidate samples for subsequent evaluation and selection of the optimal scheduling relationship that performs well in terms of total packet loss and distribution balance, further improving the load balancing capability and adaptability of network devices in complex operating environments.
[0115] Based on the same inventive concept, the basic principle and technical effects of the message load balancing device provided in this embodiment are the same 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.
[0116] Please refer to Figure 9 , Figure 9 This is a block diagram illustrating a message load balancing device 300 according to an embodiment of the present invention. The message load balancing device 300 includes an acquisition module 301, a determination module 302, and a scheduling module 303.
[0117] The acquisition module 301 is used to acquire the pre-configured scheduling relationship identifier; The determination module 302 is used to identify the scheduling relationship, which represents the use of the optimal scheduling relationship and the current connectivity state of each port being the same as the connectivity state during initial training. The optimal scheduling relationship is determined as the target scheduling relationship. The optimal scheduling relationship is the scheduling relationship obtained by the system through initial training. The port is the port of the MAC chip. The determination module 302 is also used to perform load balancing based on the number of cores and the number of receiving queues at each port if the scheduling relationship identifier indicates that the optimal scheduling relationship is not used or the current connectivity state of each port is different from the connectivity state at the time of initial training, in order to obtain the target scheduling relationship. The scheduling module 303 is used by each core to schedule the corresponding receiving queue for message processing according to the target scheduling relationship.
[0118] In summary, the packet load balancing device provided in this embodiment of the invention determines whether to use the optimal scheduling relationship obtained during the initialization phase as the target scheduling relationship by acquiring the scheduling relationship identifier. This allows for direct reuse of existing optimization results when the port connectivity status remains unchanged, improving scheduling efficiency after network device startup. When the optimal scheduling relationship is not enabled or the port connectivity status has changed, load balancing is performed based on the ratio between the number of cores and the number of queues, dynamically generating the target scheduling relationship. Each core processes packets in its corresponding receive queue based on the target scheduling relationship, achieving a reasonable match between cores and receive queues in a multi-core, multi-queue environment. This avoids scheduling bottlenecks caused by uneven resource allocation and improves the packet processing capacity and resource utilization of the network device.
[0119] Optionally, module 302 is specifically used to determine whether the number of receive queues and the number of cores are in an integer ratio. If they are in an integer ratio, all receive queues are evenly distributed to each core according to the ratio to obtain the target scheduling relationship. If they are not in an integer ratio, queues are allocated to the cores sequentially according to the obtained pre-allocated number until the number of unallocated receive queues and the number of unallocated cores are the same, and the unallocated queues are evenly distributed to the unallocated cores to obtain the target scheduling relationship. The pre-allocated number is obtained by adjusting the number of receive queues created on each port, and after the total number of all created receive queues is greater than the total number of cores, the ratio of the total number of receive queues to the total number of cores is rounded up.
[0120] Optionally, the scheduling module 303 is also used to periodically adjust the service load of the port based on the number of packet losses received by each port.
[0121] Optionally, the scheduling module 303 is specifically used to traverse and count the number of packet losses received when the receiving queue of each port is scheduled in the current period; if there is a first port where the number of packet losses in the current period is greater than the number of packet losses in the previous period, the proportion of packets sent to the first port is reduced according to a preset adjustment ratio; if there is a second port where the number of packet losses in the current period is equal to the number of packet losses in the previous period, the proportion of packets sent to the second port is increased according to a preset adjustment ratio.
[0122] Optionally, the determining module 302 is further configured to generate multiple candidate scheduling relationships based on the number of cores and the number of ports; clear the packet loss count of all ports to zero; send and receive messages based on each candidate scheduling relationship; and count the packet loss count of the receiving queue of each port corresponding to each candidate scheduling relationship; calculate the receiving packet loss variance sorting and receiving packet loss sum sorting for each candidate scheduling relationship based on the packet loss count of the receiving queue of all ports corresponding to each candidate scheduling relationship; and calculate the comprehensive ranking evaluation value of each candidate scheduling relationship according to the receiving packet loss variance sorting and receiving packet loss sum sorting for each candidate scheduling relationship with preset weights; and determine the candidate scheduling relationship with the smallest comprehensive ranking evaluation value as the optimal scheduling relationship.
[0123] Optionally, module 302 is specifically used to configure the switch chip panel port self-loop connection and perform message flooding; the flooded messages are sent to each receiving queue and, after being received by the corresponding core, are sent out from the receiving queue; after waiting for a preset statistical time, the number of lost packets in each receiving queue is counted.
[0124] Optionally, the determining module 302 is specifically used to select, if the number of ports is in an integer ratio to the number of cores, a positive integer not exceeding the chip queue threshold as the number of receiving queues for each port; create a corresponding receiving queue for each port according to the number of queues; and distribute all receiving queues equally to each core according to the number of queues, the number of ports, and the number of cores to obtain multiple candidate scheduling relationships.
[0125] Optionally, the determining module 302 is specifically used to determine the total number of receiving queues by the least common multiple of the number of cores and the number of ports if the number of ports is not an integer ratio; to create a corresponding receiving queue for each port according to the ratio of the total number of receiving queues to the number of ports; and to allocate a receiving queue to each core according to the ratio of the total number of receiving queues to the number of cores, thereby obtaining the first candidate scheduling relationship. When the number of cores is greater than the number of ports, a core with the same number of ports is randomly selected from multiple cores, and the selected cores are matched one-to-one with the ports; positive integers not exceeding the chip queue threshold are selected sequentially as the number of receive queues corresponding to each port; a corresponding receive queue is created for each port according to the number of receive queues, and the created receive queues are assigned to the job cores that match the ports to obtain the second candidate scheduling relationship; The total number of queues is determined based on the number of cores and ports, ensuring that the total number of queues is greater than the number of cores. The ratio of the total number of queues to the number of cores is rounded up to obtain the pre-allocated number. A corresponding receive queue is created for each port according to the ratio of the total number of queues to the number of ports. Receive queues are allocated to cores sequentially according to the pre-allocated number until the number of remaining receive queues is the same as the number of remaining cores. The remaining receive queues are then evenly distributed among the remaining cores to obtain the third candidate scheduling relationship. The first, second, and third candidate scheduling relationships constitute multiple candidate scheduling relationships.
[0126] Please refer to Figure 10 , Figure 10 This is a block diagram of a network device 400 provided in an embodiment of the present invention. The network device 400 includes a processor 410, a memory 420, a MAC chip 430, and a switching chip 440, wherein the switching chip 440 is used to send messages to the MAC chip 430.
[0127] The memory 420 is used to store programs or data. The memory 420 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.
[0128] The processor 410 is used to read / write data or programs stored in the memory 420 and perform corresponding functions. For example, when a computer program stored in the memory 420 is executed by the processor 410, the message load balancing method disclosed in the above embodiments can be implemented.
[0129] It should be understood that, Figure 10 The structure shown is only a schematic diagram of network device 400. Network device 400 may also include more than [other components]. Figure 10 The more or fewer components shown, or having the same Figure 10 The different configurations shown. Figure 10 The components shown can be implemented using hardware, software, or a combination thereof.
[0130] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed by processor 410, implements the message load balancing method disclosed in the above embodiments.
[0131] This invention also provides a program product that, when executed by processor 410, implements the message load balancing method disclosed in the above embodiments.
[0132] In the several embodiments provided by this invention, 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 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.
[0133] 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.
[0134] 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, ROM (Read-Only Memory), RAM (Random Access Memory), magnetic disks, or optical disks.
[0135] 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 message load balancing method, characterized in that, The method includes: Obtain the pre-configured scheduling relationship identifier; If the scheduling relationship identifier indicates that the optimal scheduling relationship is used and the current connectivity state of each port is the same as the connectivity state during initial training, then the optimal scheduling relationship is determined as the target scheduling relationship; the optimal scheduling relationship is the scheduling relationship obtained by the system through initial training; the port is the port of the MAC chip; If the scheduling relationship identifier indicates that the optimal scheduling relationship is not used or the current connectivity state of each port is different from the connectivity state at the time of initial training, load balancing is performed based on the number of cores and the number of receiving queues of each port to obtain the target scheduling relationship; Each core node schedules the corresponding receiving queue for message processing according to the target scheduling relationship.
2. The message load balancing method according to claim 1, characterized in that, The process of load balancing based on the number of cores and the number of receive queues on each port to obtain the target scheduling relationship includes: Determine if the number of receive queues is an integer ratio to the number of cores; If the ratio is an integer, all receiving queues are equally distributed to each core according to the ratio value to obtain the target scheduling relationship; If the ratio is not an integer, the queues are allocated to the cores sequentially according to the obtained pre-allocated quantity until the number of unallocated receive queues and unallocated cores are the same. Then, the unallocated queues are evenly distributed to the unallocated cores to obtain the target scheduling relationship. The pre-allocated quantity is obtained by adjusting the number of receive queues created for each port. After the total number of received queues created is greater than the total number of cores, the ratio of the total number of receive queues to the total number of cores is rounded up.
3. The message load balancing method according to claim 1, characterized in that, The method further includes: periodically adjusting the service load of the ports based on the number of packet losses received at each port, specifically including: Iterate through and count the number of packets lost when the receive queue of each port is scheduled in the current period; If there is a first port where the number of packet losses in the current period is greater than the number of packet losses in the previous period, reduce the proportion of packets sent to the first port according to the preset adjustment ratio. If there is a second port where the number of packet losses in the current period is equal to the number of packet losses in the previous period, the proportion of packets sent to the second port is increased according to a preset adjustment ratio.
4. The message load balancing method according to claim 1, characterized in that, The optimal scheduling relationship is obtained through the following method: Multiple candidate scheduling relationships are generated based on the number of cores and the number of ports; The packet loss count of all ports is cleared to zero. Messages are sent and received based on each of the candidate scheduling relationships, and the packet loss count of the receiving queue of each port corresponding to each candidate scheduling relationship is counted. Calculate the receiving packet loss variance sort and the receiving packet loss total sort for each candidate scheduling relationship based on the number of packet losses in the receiving queues of all ports corresponding to each candidate scheduling relationship, and calculate the comprehensive ranking evaluation value of each candidate scheduling relationship according to the receiving packet loss variance sort and the receiving packet loss total sort based on the preset weights. The candidate scheduling relationship with the smallest comprehensive ranking evaluation value is determined as the optimal scheduling relationship.
5. The message load balancing method according to claim 4, characterized in that, Sending and receiving messages based on each of the candidate scheduling relationships, and counting the number of packet losses in the receive queue of each port corresponding to each candidate scheduling relationship, including: Configure the switch chip panel port to establish a loopback connection and perform message flooding; the flooded messages are sent to each receive queue, and after being received by the corresponding core, they are sent out from that receive queue; after waiting for a preset statistical time, the number of lost packets in each receive queue is counted.
6. The message load balancing method according to claim 4, characterized in that, If the number of ports is an integer ratio to the number of cores, the generation of multiple candidate scheduling relationships based on the number of cores and the number of ports includes: A positive integer not exceeding the chip queue threshold is selected sequentially as the number of queues for the receiving queue corresponding to each port; Create a corresponding receive queue for each port according to the number of queues; Based on the number of queues, the number of ports, and the number of cores, all receiving queues are equally distributed to each core, resulting in multiple candidate scheduling relationships.
7. The message load balancing method according to claim 4, characterized in that, If the number of ports is not an integer proportion to the number of cores, the generation of multiple candidate scheduling relationships based on the number of cores and the number of ports includes: The total number of receive queues is determined by the least common multiple of the number of cores and the number of ports; a corresponding receive queue is created for each port according to the ratio of the total number of receive queues to the number of ports; and a receive queue is allocated to each core according to the ratio of the total number of receive queues to the number of cores to obtain a first candidate scheduling relationship. When the number of cores is greater than the number of ports, a core with the same number of ports is randomly selected from multiple cores, and the selected core is matched one-to-one with the port; positive integers not exceeding the chip queue threshold are selected sequentially as the number of receive queues corresponding to each port; a corresponding receive queue is created for each port according to the number of receive queues, and the created receive queues are assigned to the job cores matched with the port to obtain the second candidate scheduling relationship; The total number of queues is determined based on the number of cores and the number of ports, such that the total number of queues is greater than the number of cores; the ratio of the total number of queues to the number of cores is rounded up to obtain the pre-allocated quantity; a corresponding receiving queue is created for each port according to the ratio of the total number of queues to the number of ports; the receiving queues are allocated to the cores sequentially according to the pre-allocated quantity until the number of remaining receiving queues is the same as the number of remaining cores, and the remaining receiving queues are evenly distributed to the remaining cores to obtain the third candidate scheduling relationship; The first candidate scheduling relationship, the second candidate scheduling relationship, and the third candidate scheduling relationship constitute multiple candidate scheduling relationships.
8. A message load balancing device, characterized in that, The device includes: The acquisition module is used to acquire pre-configured scheduling relationship identifiers; The determination module is used to identify the optimal scheduling relationship as the target scheduling relationship, where the scheduling relationship identifier indicates that the optimal scheduling relationship is used and the current connectivity state of each port is the same as the connectivity state during initial training; the optimal scheduling relationship is the scheduling relationship initially obtained by the system through training; the port is the port of the MAC chip. The determination module is further configured to perform load balancing based on the number of cores and the number of receiving queues at each port if the scheduling relationship identifier indicates that the optimal scheduling relationship is not used or the current connectivity state of each port is different from the connectivity state at the time of initial training, in order to obtain the target scheduling relationship. The scheduling module is used by each core to schedule the corresponding receiving queue for message processing according to the target scheduling relationship.
9. A network device, characterized in that, It includes a processor and a memory, the memory storing a computer program that can be executed by the processor to implement the message load balancing method according to 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 the processor, it implements the message load balancing method as described in any one of claims 1-7.