Data processing method and apparatus, and electronic device
By employing strategies of parallel or sequential processing based on the number of data packets, the inefficiency of multi-core processors when handling large numbers of data packets is addressed, achieving more efficient data packet processing and balanced utilization of storage resources.
Patent Information
- Application Number
- CN202211386041.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-07
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2042-11-07
AI Technical Summary
Existing multi-core processors suffer from low processing efficiency when handling large amounts of data packets due to locking and load balancing strategies, resulting in multiple processor cores being unable to work simultaneously and wasting resources.
By detecting whether the number of data packets exceeds a target threshold, if it does, multiple processor cores are controlled to process the data packets in parallel to ensure that each processor core works independently; if it does not exceed the threshold, the data packets are processed in the order they arrived.
It improves the processing efficiency of multi-core processors when handling large amounts of data packets, avoids wasting processor core resources, and achieves more efficient data packet processing and balanced utilization of storage resources.
Smart Images

Figure CN115640135B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and more specifically, to a data processing method, apparatus, and electronic device. Background Technology
[0002] Currently, most hardware load balancing devices use multi-core processors for data processing. However, in existing technologies, multi-core processors typically use a locking load balancing strategy to process multiple received data packets. In this approach, the multi-core processor locks the common data used for computation, making this common data a "critical resource." In other words, under this processing method, the processor's multiple cores essentially work serially; at any given time, only one core can process the data packets, while the others remain idle. If the current processor receives a large load (i.e., a large number of data packets to be processed), the inability of multiple cores to work simultaneously leads to low data packet processing efficiency.
[0003] There is currently no effective solution to the above problems. Summary of the Invention
[0004] This application provides a data processing method, apparatus, and electronic device to at least solve the technical problem of low data packet processing efficiency in the prior art.
[0005] According to one aspect of the embodiments of this application, a data processing method is provided, comprising: acquiring a plurality of data packets to be processed, wherein each data packet corresponds to a processor core of a processor, and the processor includes a plurality of processor cores; detecting whether the total number of the plurality of data packets is greater than a target threshold; if the total number is greater than the target threshold, controlling the plurality of processor cores to process the corresponding data packets in parallel to obtain a processing result for each data packet, wherein the plurality of processor cores are independent of each other.
[0006] Furthermore, the data processing method also includes: after detecting whether the total number of multiple data packets is greater than the target threshold, if the total number is less than or equal to the target threshold, controlling each processor core to process the data packets corresponding to each processor core according to the target processing order to obtain the processing result of each data packet, wherein the target processing order is determined by the time when the data packet enters the processor core.
[0007] Furthermore, the data processing method also includes: obtaining the processor's packet processing rate before detecting whether the total number of multiple data packets exceeds a target threshold; and determining the target threshold based on the packet processing rate.
[0008] Furthermore, the data processing method also includes: obtaining the number of data packets processed by the processor within a preset time period to obtain a first number; determining the duration of the preset time period as a target duration; and calculating the ratio of the first number to the target duration to obtain the data packet processing rate.
[0009] Furthermore, the data processing method also includes: determining the number of data packets that the processor can process per second based on the data packet processing rate to obtain a second quantity; receiving an adjustment instruction sent by the terminal device; and adjusting the second quantity according to the adjustment instruction to obtain a target threshold.
[0010] Furthermore, the data processing method also includes: Step 1, caching multiple data packets according to the target processing order to obtain a target sequence; Step 2, determining the target data packet from the target sequence according to the processing order of each data packet in the target sequence; Step 3, determining the processor kernel corresponding to the target data packet as the target processor kernel; Step 4, controlling the target processor kernel to process the target data packet to obtain the processing result of the target data packet; Step 5, deleting the target data packet from the target sequence to obtain an updated target sequence; Step 6, repeating the process from Step 2 to Step 5 until the processing result of each data packet is obtained.
[0011] Furthermore, the data processing method also includes: caching at least one data packet corresponding to each processor core according to the target processing order to obtain a data packet sequence corresponding to each processor core; and controlling each processor core to process the corresponding data packet sequence in parallel to obtain the processing result of each data packet.
[0012] Furthermore, the data processing method also includes: after acquiring multiple data packets to be processed, acquiring the processor utilization rate at the current time; if the utilization rate is greater than a preset threshold, controlling multiple processor cores to process the corresponding data packets in parallel to obtain the processing result of each data packet; if the utilization rate is less than or equal to the preset threshold, controlling each processor core to process the data packets corresponding to each processor core according to the target processing order to obtain the processing result of each data packet.
[0013] According to another aspect of the embodiments of this application, a data processing apparatus is also provided, comprising: an acquisition module for acquiring a plurality of data packets to be processed, wherein each data packet corresponds to a processor core of a processor, and the processor includes a plurality of processor cores; a detection module for detecting whether the total number of the plurality of data packets is greater than a target threshold; and a first processing module for controlling the plurality of processor cores to process the corresponding data packets in parallel when the total number is greater than the target threshold, thereby obtaining a processing result for each data packet, wherein the plurality of processor cores are independent of each other.
[0014] According to another aspect of the embodiments of this application, an electronic device is also provided, including one or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors cause the one or more processors to implement the data processing method described above.
[0015] In this application, multiple processor cores are controlled to process the corresponding data packets in parallel by detecting whether the total number of data packets to be processed is greater than a target threshold. First, multiple data packets to be processed are acquired. Then, it is detected whether the total number of data packets exceeds the target threshold. If the total number exceeds the target threshold, multiple processor cores are controlled to process the corresponding data packets in parallel to obtain the processing result for each data packet. The multiple processor cores operate independently of each other. Furthermore, each data packet corresponds to one processor core, and the processor includes multiple processor cores.
[0016] As can be seen from the above, the solution of this application controls each processor core to process the corresponding data packets in parallel when the total number of data packets to be processed exceeds the target threshold. This is equivalent to multiple processor cores working simultaneously and processing their respective data packets in parallel. Compared with the prior art, where multiple processor cores still process data packets serially when the total number of data packets to be processed is large, the technical solution of this application can improve the utilization of multiple processor cores. This not only improves the processing efficiency of data packets but also avoids the waste of processor core resources.
[0017] Therefore, the technical solution of this application achieves the goal of making full use of the existing processor core to process data packets when the number of data packets to be processed is large, thereby improving the data packet processing efficiency and solving the technical problem of low data packet processing efficiency in the prior art. Attached Figure Description
[0018] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0019] Figure 1 This is a flowchart of an optional data processing method according to an embodiment of this application;
[0020] Figure 2 This is a flowchart of an optional data processing method based on a local load balancing strategy according to an embodiment of this application;
[0021] Figure 3 This is a flowchart of an optional data processing method based on a locking and balancing strategy according to an embodiment of this application;
[0022] Figure 4 This is a schematic diagram of a processing result transmission process based on a local load balancing strategy according to an embodiment of this application;
[0023] Figure 5 This is a flowchart illustrating a method for processing data packets according to a locking and load balancing strategy, based on an embodiment of this application.
[0024] Figure 6 This is a schematic diagram of an optional data processing apparatus according to an embodiment of this application;
[0025] Figure 7 This is a schematic diagram of an optional electronic device according to an embodiment of this application. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0028] Example 1
[0029] According to an embodiment of this application, an embodiment of a data processing method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0030] Figure 1 This is a flowchart of an optional data processing method according to an embodiment of this application, such as... Figure 1As shown, the method includes the following steps:
[0031] Step S101: Obtain multiple data packets to be processed.
[0032] In step S101, each data packet corresponds to one processor core of the processor, and the processor includes multiple processor cores.
[0033] Specifically, the aforementioned data packet can be a TCP (transmission control protocol) request, and the aforementioned processor is a common multi-core processor, that is, a processor that includes multiple processor cores.
[0034] In an optional embodiment, the processor can serve as the execution subject of the data processing method in this application embodiment. After the processor obtains multiple data packets to be processed, the processor will assign each data packet to a different processor core for processing. For example, the processor H includes three processor cores, namely processor core A, processor core B and processor core C. At this time, the processor H receives three data packets to be processed in succession, namely data packet 1, data packet 2 and data packet 3. Then the processor H will assign data packet 1 to processor core A for processing, data packet 2 to processor core B for processing, and data packet 3 to processor core C for processing.
[0035] Step S102: Detect whether the total number of multiple data packets is greater than the target threshold.
[0036] In step S102, the target threshold can be set by a technician or obtained by the processor's packet processing rate.
[0037] Step S103: If the total number is greater than the target threshold, control multiple processor cores to process the corresponding data packets in parallel to obtain the processing result of each data packet.
[0038] In step S103, the multiple processor cores operate independently of each other.
[0039] Specifically, when the total number of data packets exceeds the target threshold, the processor determines that the number of data packets to be processed is too large, making it unsuitable to use a serial approach to control multiple processor cores to process the data packets. Therefore, the processor controls multiple processor cores to process the corresponding data packets in parallel, obtaining the processing result for each data packet.
[0040] Taking processor H as an example again, assuming the target threshold is 2, since there are 3 data packets to be processed, which exceeds the target threshold, processor H will control the three processor cores to process the data packets corresponding to each processor core simultaneously.
[0041] like Figure 2 As shown, at the same time, processor core A processes data packet 1, processor core B processes data packet 2, and processor core C processes data packet 3.
[0042] It is important to note that controlling multiple processor cores to process corresponding data packets in parallel is also known as a local balancing strategy based on each processor core. When implementing a local balancing strategy, each processor core uses its own local computation data to process the data packets, without using the common data between multiple processor cores (i.e., multiple processor cores are independent of each other and do not interfere with each other).
[0043] Based on the content of steps S101 to S103 above, it can be seen that in this application, by detecting whether the total number of multiple data packets to be processed is within a target threshold, and controlling multiple processor cores to process the corresponding data packets in parallel when the total number is greater than the target threshold, the process first obtains multiple data packets to be processed, then detects whether the total number of multiple data packets is greater than the target threshold, and when the total number is greater than the target threshold, controls multiple processor cores to process the corresponding data packets in parallel to obtain the processing result of each data packet. The multiple processor cores are independent of each other. Furthermore, each data packet corresponds to one processor core of the processor, and the processor includes multiple processor cores.
[0044] As can be seen from the above, the solution of this application controls each processor core to process the corresponding data packets in parallel when the total number of data packets to be processed exceeds the target threshold. This is equivalent to multiple processor cores working simultaneously and processing their respective data packets in parallel. Compared with the prior art, where multiple processor cores still process data packets serially when the total number of data packets to be processed is large, the technical solution of this application can improve the utilization of multiple processor cores. This not only improves the processing efficiency of data packets but also avoids the waste of processor core resources.
[0045] Therefore, the technical solution of this application achieves the goal of making full use of the existing processor core to process data packets when the number of data packets to be processed is large, thereby improving the data packet processing efficiency and solving the technical problem of low data packet processing efficiency in the prior art.
[0046] In one optional embodiment, after detecting whether the total number of multiple data packets is greater than a target threshold, if the total number is less than or equal to the target threshold, the processor controls each processor core to process the data packets corresponding to each processor core in the target processing order to obtain the processing result of each data packet.
[0047] The target processing order is determined by the time the data packets enter the processor core. For example, taking processor H as an example again, if data packet 1 enters processor core A at time T1, data packet 2 enters processor core B at time T2, and data packet 3 enters processor core C at time T3, and T1 is earlier than T2, and T2 is earlier than T3, then the target processing order for the three data packets is data packet 1, data packet 2, and data packet 3, respectively. Assuming the target threshold is 4, and the total number of data packets currently awaiting processing by processor H is less than the target threshold, processor H will employ a locking and load balancing strategy to control each processor core to process the corresponding data packets.
[0048] like Figure 3 As shown, processor cores A, B, and C cannot work independently; instead, they need to collaborate using shared data. Since the target processing order for the three data packets is data packet 1, data packet 2, and data packet 3, processor core A first uses the shared data to process data packet 1. During this processing, other processor cores cannot access or modify the shared data; in other words, processor core A is essentially "locking" the shared data. After processor core A completes processing data packet 1, it "unlocks" the shared data. Then, processor core B processes data packet 2. Similarly, processor core B's processing of data packet 2 involves "locking" and "unlocking" the shared data. Finally, only after processor core B completes processing data packet 2 can processor core C process data packet 3.
[0049] It's important to note that when the total number of data packets to be processed is small, employing a locking and load balancing strategy can ensure that the processing results are sent to the receiving server in a more even manner. For ease of understanding, the following will combine... Figure 4 Please provide an explanation.
[0050] like Figure 4 As shown, data packet 1 is processed by processor core A, data packet 2 by processor core B, and data packet 3 by processor core C. Since there are only three data packets, if a local load balancing strategy is used to process the three data packets in parallel, the processing times for the three data packets will be very close. Based on this, Figure 4 All three servers (Server A, Server B, and Server C) can receive the data packet processing results. Since Server A receives data packets before Server B and Server C, there is a high probability that the processing results of the three data packets will be sent to Server A.
[0051] However, considering the balance of data storage, technicians prefer that the processing result of data packet 1 be sent to server A for storage; the processing result of data packet 2 be sent to server B for storage; and the processing result of data packet 3 be sent to server C for storage. This avoids the problem of unbalanced storage resource allocation among multiple servers caused by storing all processing results on a single server. By using a locking-based data packet balancing strategy, the processing result of data packet 1 is generated before that of data packet 2, therefore, the processing result of data packet 1 is sent to server A for storage. After the processing result of data packet 2 is generated, since it is known that the processing result of data packet 1 has been sent to server A in advance, the processor will send the processing result of data packet 2 to server B; similarly, the processing result of data packet 3 will be sent to server C. Therefore, when the number of data packets to be processed is small, using a locking-based data packet balancing strategy can distribute the processing results of data packets more evenly across multiple servers for storage, achieving balanced utilization of storage resources across multiple servers.
[0052] Additionally, it should be noted that if the number of data packets to be processed is large, for example, tens of thousands of data packets, which far exceeds the number of processor cores, even if the processor uses a local load balancing strategy to control multiple processor cores to process the corresponding data packets, the generation time of the data packet processing results will still have a significant difference (i.e., the generation time of the data packet processing results corresponding to different batches of data packets is not close). Therefore, even if the processor sends the processing results of a batch of data packets with similar generation times to the same server (e.g., server A), after the processing results of the next batch of data packets are generated, the processor can send them to another server (e.g., server B). Ultimately, when all tens of thousands of data packets have been processed, the number of processing results stored on each server will not differ significantly.
[0053] In one optional embodiment, before detecting whether the total number of multiple data packets exceeds a target threshold, the processor's data packet processing rate is first obtained, and then the target threshold is determined based on the data packet processing rate. The data packet processing rate characterizes the number of data packets the processor can process per second.
[0054] Specifically, the processor can first obtain the number of data packets processed within a preset time period to obtain a first number, then determine the duration of the preset time period as the target duration, and calculate the ratio of the first number to the target duration to obtain the data packet processing rate.
[0055] Furthermore, based on the obtained data packet processing rate, the processor determines the number of data packets that the processor can process per second, obtains a second number, then receives an adjustment instruction sent by the terminal device, and adjusts the second number according to the adjustment instruction to obtain the target threshold.
[0056] Optionally, the preset time period can be customized, for example, 1 minute. Assuming the processor processes 600 data packets in 1 minute, the processor's data packet processing rate is 600 / 60 = 10 packets / second. That is, the processor can process 10 data packets per second (corresponding to the second quantity mentioned above). Based on this, the processor can directly set the target threshold to 10. Alternatively, a technician can send an adjustment command through a terminal device to determine the target threshold after adjusting the second quantity. For example, the adjustment command may include a first value, and the processor obtains the target threshold by summing the first value and the first quantity. The first value can be negative or positive.
[0057] By adjusting the instructions, technicians can easily and flexibly adjust the target threshold, thus making the technical solution in this application applicable to more application scenarios.
[0058] In one alternative embodiment, Figure 5 A flowchart illustrating how to control the processor core to process data packets according to a locking and load balancing strategy is shown, such as... Figure 5 As shown, it includes the following steps:
[0059] Step 1: Buffer multiple data packets according to the target processing order to obtain the target sequence;
[0060] Step 2: Determine the target data packets from the target sequence according to the processing order of each data packet in the target sequence, where the processing order of the target data packets has the highest priority in the target sequence;
[0061] Step 3: Determine the processor kernel corresponding to the target data packet as the target processor kernel;
[0062] Step 4: Control the target processor kernel to process the target data packet and obtain the processing result of the target data packet;
[0063] Step 5: Delete the target data packet from the target sequence to obtain the updated target sequence;
[0064] Step 6: Repeat steps 2 to 5 until the processing result of each data packet is obtained.
[0065] Taking processor H as an example, based on the target processing order of data packets 1, 2, and 3, the three data packets can be cached into a target sequence [data packet 1, data packet 2, data packet 3]. Data packet 1 has the highest processing priority in the target sequence. Therefore, in the first processing step, data packet 1 is the target data packet, and processor core A corresponding to data packet 1 is the target processor core. After processor core A completes processing data packet 1, the processor removes data packet 1 from the target sequence, resulting in the updated target sequence [data packet 2, data packet 3]. In the second processing step, data packet 2 becomes the target data packet, and processor core B becomes the target processor core. Therefore, processor H controls processor core B to process data packet 2. Similarly, data packet 3 is finally processed by processor core C.
[0066] By controlling the processor kernel to process data packets using the above-mentioned locking and balancing strategy, when the number of data packets is small, it can ensure that the processing results of the data packets are sent to multiple servers for storage in a more balanced manner, thereby achieving balanced utilization of the storage resources of multiple servers.
[0067] In one optional embodiment, when the total number of data packets to be processed is less than or equal to a target threshold, the processor employs a local load balancing strategy to control the processor cores to process the data packets. Specifically, the processor buffers at least one data packet corresponding to each processor core according to the target processing order, obtaining a data packet sequence corresponding to each processor core. Then, it controls each processor core to process the corresponding data packet sequence in parallel to obtain the processing result for each data packet.
[0068] Taking processor H as an example, assume that the data packets corresponding to processor core A are data packets A1, A2, and A3; the data packets corresponding to processor core B are data packets B1 and B2; and the data packets corresponding to processor core C are data packets C1 and C2. Furthermore, based on the time each data packet enters its corresponding processor core, the target processing order among these eight data packets is determined as: data packet A1, data packet A3, data packet B1, data packet B2, data packet A2, data packet C2, and data packet C1. Based on this, the data packet sequence corresponding to processor core A is [data packet A1, data packet A3, data packet A2], the data packet sequence corresponding to processor core B is [data packet B1, data packet B2], and the data packet sequence corresponding to processor core C is [data packet C2, data packet C1]. Further, the three processor cores process their respective data packet sequences in parallel: processor core A processes data packets A1, A3, and A2 sequentially; processor core B processes data packets B1 and B2 sequentially; and processor core C processes data packets C2 and C1 sequentially.
[0069] It should be noted that, compared with the prior art where multiple processor cores still process data packets serially when the total number of data packets to be processed is large, this application adopts a local balancing strategy to control each processor core to process the corresponding data packets when the total number of data packets exceeds the target threshold. This can improve the utilization of multiple processor cores, thereby not only improving the processing efficiency of data packets, but also avoiding the waste of processor core resources.
[0070] In one optional embodiment, after acquiring multiple data packets to be processed, the processor can also acquire the processor utilization rate at the current time, and if the utilization rate is greater than a preset threshold, control multiple processor cores to process the corresponding data packets in parallel to obtain the processing result of each data packet; if the utilization rate is less than or equal to the preset threshold, control each processor core to process the data packets corresponding to each processor core according to the target processing order to obtain the processing result of each data packet.
[0071] Specifically, processor utilization reflects the current processor load to some extent. Therefore, when processor utilization exceeds a preset threshold, it indicates a large amount of data needs to be processed at any given time. To improve data processing efficiency, the processor uses a local load balancing strategy to control multiple processor cores to process the corresponding data packets in parallel. When processor utilization is less than or equal to the preset threshold, it indicates a smaller amount of data needs to be processed at any given time. To avoid an imbalance in storage resource allocation among multiple servers caused by all processing results being stored on a single server, the processor uses a locking load balancing strategy to control each processor core to process the data packets corresponding to it according to the target processing order.
[0072] As described above, this application also achieves the goal of automatically switching between local load balancing and home-locked load balancing strategies by obtaining processor utilization. This ensures both improved data processing performance when processor utilization is high and avoids sending all processing results to a single server for storage when processor utilization is low.
[0073] Example 2
[0074] This application also provides a data processing apparatus. It should be noted that the data processing apparatus of this application can be used to execute the data processing method provided in embodiment 1 of this application. The data processing apparatus provided in this application will be described below.
[0075] Figure 6 This is a schematic diagram of a data processing apparatus according to an embodiment of this application. Figure 6 As shown, the device includes:
[0076] The acquisition module 601 is used to acquire multiple data packets to be processed, wherein each data packet corresponds to a processor core of the processor, and the processor includes multiple processor cores; the detection module 602 is used to detect whether the total number of multiple data packets is greater than a target threshold; the first processing module 603 is used to control multiple processor cores to process the corresponding data packets in parallel when the total number is greater than the target threshold, and obtain the processing result of each data packet, wherein the multiple processor cores are independent of each other.
[0077] Specifically, the aforementioned data packet can be a TCP (transmission control protocol) request, and the aforementioned processor is a common multi-core processor, that is, a processor that includes multiple processor cores.
[0078] In one optional embodiment, the data processing device includes at least the processor described above. After the processor acquires multiple data packets to be processed, it assigns each data packet to a different processor core for processing. For example, processor H includes three processor cores: processor core A, processor core B, and processor core C. If processor H receives three data packets to be processed sequentially, namely data packet 1, data packet 2, and data packet 3, then processor H will assign data packet 1 to processor core A for processing, data packet 2 to processor core B for processing, and data packet 3 to processor core C for processing.
[0079] Furthermore, the target threshold can be set by technicians or obtained through the processor's packet processing rate. Assuming the target threshold is 2, and processor H has 3 packets to process, exceeding the target threshold, processor H will control all three processor cores to process the packets corresponding to each core simultaneously.
[0080] like Figure 2 As shown, at the same time, processor core A processes data packet 1, processor core B processes data packet 2, and processor core C processes data packet 3.
[0081] It is important to note that controlling multiple processor cores to process corresponding data packets in parallel is also known as a local balancing strategy based on each processor core. When implementing a local balancing strategy, each processor core uses its own local computation data to process the data packets, without using the common data between multiple processor cores (i.e., multiple processor cores are independent of each other and do not interfere with each other).
[0082] As can be seen from the above, the solution of this application controls each processor core to process the corresponding data packets in parallel when the total number of data packets to be processed exceeds the target threshold. This is equivalent to multiple processor cores working simultaneously and processing their respective data packets in parallel. Compared with the prior art, where multiple processor cores still process data packets serially when the total number of data packets to be processed is large, the technical solution of this application can improve the utilization of multiple processor cores. This not only improves the processing efficiency of data packets but also avoids the waste of processor core resources.
[0083] Therefore, the technical solution of this application achieves the goal of making full use of the existing processor core to process data packets when the number of data packets to be processed is large, thereby improving the data packet processing efficiency and solving the technical problem of low data packet processing efficiency in the prior art.
[0084] Optionally, the data processing device further includes: a second processing module, configured to control each processor core to process the data packets corresponding to each processor core in a target processing order when the total number is less than or equal to a target threshold, and to obtain the processing result of each data packet, wherein the target processing order is determined by the time when the data packet enters the processor core.
[0085] The target processing order is determined by the time the data packets enter the processor core. For example, taking processor H as an example again, if data packet 1 enters processor core A at time T1, data packet 2 enters processor core B at time T2, and data packet 3 enters processor core C at time T3, and T1 is earlier than T2, and T2 is earlier than T3, then the target processing order for the three data packets is data packet 1, data packet 2, and data packet 3, respectively. Assuming the target threshold is 4, and the total number of data packets currently awaiting processing by processor H is less than the target threshold, processor H will employ a locking and load balancing strategy to control each processor core to process the corresponding data packets.
[0086] like Figure 3As shown, processor cores A, B, and C cannot work independently; instead, they need to collaborate using shared data. Since the target processing order for the three data packets is data packet 1, data packet 2, and data packet 3, processor core A first uses the shared data to process data packet 1. During this processing, other processor cores cannot access or modify the shared data; in other words, processor core A is essentially "locking" the shared data. After processor core A completes processing data packet 1, it "unlocks" the shared data. Then, processor core B processes data packet 2. Similarly, processor core B's processing of data packet 2 involves "locking" and "unlocking" the shared data. Finally, only after processor core B completes processing data packet 2 can processor core C process data packet 3.
[0087] It's important to note that when the total number of data packets to be processed is small, employing a locking and load balancing strategy can ensure that the processing results are sent to the receiving server in a more even manner. For ease of understanding, the following will combine... Figure 4 Please provide an explanation.
[0088] like Figure 4 As shown, data packet 1 is processed by processor core A, data packet 2 by processor core B, and data packet 3 by processor core C. Since there are only three data packets, if a local load balancing strategy is used to process the three data packets in parallel, the processing times for the three data packets will be very close. Based on this, Figure 4 All three servers (Server A, Server B, and Server C) can receive the data packet processing results. Since Server A receives data packets before Server B and Server C, there is a high probability that the processing results of the three data packets will be sent to Server A.
[0089] However, considering the balance of data storage, technicians prefer that the processing result of data packet 1 be sent to server A for storage; the processing result of data packet 2 be sent to server B for storage; and the processing result of data packet 3 be sent to server C for storage. This avoids the problem of unbalanced storage resource allocation among multiple servers caused by storing all processing results on a single server. By using a locking-based data packet balancing strategy, the processing result of data packet 1 is generated before that of data packet 2, therefore, the processing result of data packet 1 is sent to server A for storage. After the processing result of data packet 2 is generated, since it is known that the processing result of data packet 1 has been sent to server A in advance, the processor will send the processing result of data packet 2 to server B; similarly, the processing result of data packet 3 will be sent to server C. Therefore, when the number of data packets to be processed is small, using a locking-based data packet balancing strategy can distribute the processing results of data packets more evenly across multiple servers for storage, achieving balanced utilization of storage resources across multiple servers.
[0090] Additionally, it should be noted that if the number of data packets to be processed is large, for example, tens of thousands of data packets, which far exceeds the number of processor cores, even if the processor uses a local load balancing strategy to control multiple processor cores to process the corresponding data packets, the generation time of the data packet processing results will still have a significant difference (i.e., the generation time of the data packet processing results corresponding to different batches of data packets is not close). Therefore, even if the processor sends the processing results of a batch of data packets with similar generation times to the same server (e.g., server A), after the processing results of the next batch of data packets are generated, the processor can send them to another server (e.g., server B). Ultimately, when all tens of thousands of data packets have been processed, the number of processing results stored on each server will not differ significantly.
[0091] Optionally, the data processing device further includes a first acquisition module and a first determination module. The first acquisition module is used to acquire the data packet processing rate of the processor; the first determination module is used to determine a target threshold based on the data packet processing rate.
[0092] Optionally, the first acquisition module further includes: a first acquisition unit, a first determination unit, and a calculation unit. The first acquisition unit is used to acquire the number of data packets processed by the processor within a preset time period to obtain a first quantity; the first determination unit is used to determine the duration of the preset time period as a target duration; and the calculation unit is used to calculate the ratio of the first quantity to the target duration to obtain the data packet processing rate.
[0093] Optionally, the first determining module further includes: a second determining unit, a receiving unit, and an adjusting unit. The second determining unit is used to determine the number of data packets that the processor can process per second based on the data packet processing rate, thus obtaining a second quantity; the receiving unit is used to receive an adjustment instruction sent by the terminal device; and the adjusting unit is used to adjust the second quantity according to the adjustment instruction to obtain a target threshold.
[0094] Optionally, the preset time period can be customized, for example, 1 minute. Assuming the processor processes 600 data packets in 1 minute, the processor's data packet processing rate is 600 / 60 = 10 packets / second. That is, the processor can process 10 data packets per second (corresponding to the second quantity mentioned above). Based on this, the processor can directly set the target threshold to 10. Alternatively, a technician can send an adjustment command through a terminal device to determine the target threshold after adjusting the second quantity. For example, the adjustment command may include a first value, and the processor obtains the target threshold by summing the first value and the first quantity. The first value can be negative or positive.
[0095] By adjusting the instructions, technicians can easily and flexibly adjust the target threshold, thus making the technical solution in this application applicable to more application scenarios.
[0096] Optionally, the second processing module further includes: a first execution unit, a second execution unit, a third execution unit, a fourth execution unit, a fifth execution unit, and a sixth execution unit. The first execution unit is used to execute step 1, buffering multiple data packets according to the target processing order to obtain a target sequence; the second execution unit is used to execute step 2, determining the target data packet from the target sequence according to the processing order of each data packet in the target sequence; the third execution unit is used to execute step 3, determining the processor kernel corresponding to the target data packet as the target processor kernel; the fourth execution unit is used to execute step 4, controlling the target processor kernel to process the target data packet to obtain the processing result of the target data packet; the fifth execution unit is used to execute step 5, deleting the target data packet from the target sequence to obtain an updated target sequence; and the sixth execution unit is used to execute step 6, repeating steps 2 to 5 until the processing result of each data packet is obtained.
[0097] Taking processor H as an example again, based on the target processing order of data packets 1, 2, and 3, the three data packets can be cached into a target sequence [data packet 1, data packet 2, data packet 3]. Among them, the processing order of data packet 1 has the highest priority in the target sequence. Therefore, in the first processing, data packet 1 is the target data packet, and the processor core A corresponding to data packet 1 is the target processor core. After processor core A completes the processing of data packet 1, the processor removes data packet 1 from the target sequence, obtaining the updated target sequence [data packet 2, data packet 3]. In the second processing, data packet 2 becomes the target data packet, and processor core B becomes the target processor core. Therefore, processor H controls processor core B to process data packet 2. Similarly, data packet 3 is finally processed by processor core C.
[0098] By controlling the processor kernel to process data packets using the above-mentioned locking and balancing strategy, when the number of data packets is small, it can ensure that the processing results of the data packets are sent to multiple servers for storage in a more balanced manner, thereby achieving balanced utilization of the storage resources of multiple servers.
[0099] Optionally, the first processing module further includes a caching unit and a parallel processing unit. The caching unit is used to cache at least one data packet corresponding to each processor core according to the target processing order, obtaining a data packet sequence corresponding to each processor core. The parallel processing unit is used to control each processor core to process its corresponding data packet sequence in parallel, obtaining the processing result for each data packet.
[0100] Taking processor H as an example, assume that the data packets corresponding to processor core A are data packets A1, A2, and A3; the data packets corresponding to processor core B are data packets B1 and B2; and the data packets corresponding to processor core C are data packets C1 and C2. Furthermore, based on the time each data packet enters its corresponding processor core, the target processing order among these eight data packets is determined as: data packet A1, data packet A3, data packet B1, data packet B2, data packet A2, data packet C2, and data packet C1. Based on this, the data packet sequence corresponding to processor core A is [data packet A1, data packet A3, data packet A2], the data packet sequence corresponding to processor core B is [data packet B1, data packet B2], and the data packet sequence corresponding to processor core C is [data packet C2, data packet C1]. Further, the three processor cores process their respective data packet sequences in parallel: processor core A processes data packets A1, A3, and A2 sequentially; processor core B processes data packets B1 and B2 sequentially; and processor core C processes data packets C2 and C1 sequentially.
[0101] It should be noted that, compared with the prior art where multiple processor cores still process data packets serially when the total number of data packets to be processed is large, this application adopts a local balancing strategy to control each processor core to process the corresponding data packets when the total number of data packets exceeds the target threshold. This can improve the utilization of multiple processor cores, thereby not only improving the processing efficiency of data packets, but also avoiding the waste of processor core resources.
[0102] Optionally, the data processing device further includes: a second acquisition module, a first control module, and a second control module. The second acquisition module is used to acquire the processor utilization rate at the current time; the first control module is used to control multiple processor cores to process corresponding data packets in parallel when the utilization rate is greater than a preset threshold, obtaining the processing result of each data packet; the second control module is used to control each processor core to process the data packets corresponding to each processor core according to a target processing order when the utilization rate is less than or equal to the preset threshold, obtaining the processing result of each data packet.
[0103] Specifically, processor utilization reflects the current processor load to some extent. Therefore, when processor utilization exceeds a preset threshold, it indicates a large amount of data needs to be processed at any given time. To improve data processing efficiency, the processor uses a local load balancing strategy to control multiple processor cores to process the corresponding data packets in parallel. When processor utilization is less than or equal to the preset threshold, it indicates a smaller amount of data needs to be processed at any given time. To avoid an imbalance in storage resource allocation among multiple servers caused by all processing results being stored on a single server, the processor uses a locking load balancing strategy to control each processor core to process the data packets corresponding to it according to the target processing order.
[0104] As described above, this application also achieves the goal of automatically switching between local load balancing and home-locked load balancing strategies by obtaining processor utilization. This ensures both improved data processing performance when processor utilization is high and avoids sending all processing results to a single server for storage when processor utilization is low.
[0105] Example 3
[0106] According to another aspect of the embodiments of this application, an electronic device is also provided, which includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method for determining adversarial samples in Embodiment 1 above.
[0107] like Figure 7As shown, this application embodiment provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps:
[0108] The system acquires multiple data packets to be processed, where each data packet corresponds to a processor core of the processor, and the processor includes multiple processor cores; it detects whether the total number of data packets exceeds a target threshold; if the total number exceeds the target threshold, it controls the multiple processor cores to process the corresponding data packets in parallel to obtain the processing result of each data packet, wherein the multiple processor cores are independent of each other.
[0109] Optionally, the processor also performs the following steps when executing the program: after detecting whether the total number of multiple data packets is greater than the target threshold, if the total number is less than or equal to the target threshold, it controls each processor core to process the data packets corresponding to each processor core according to the target processing order, and obtains the processing result of each data packet, wherein the target processing order is determined by the time when the data packet enters the processor core.
[0110] Optionally, the processor may also perform the following steps when executing the program: before detecting whether the total number of multiple data packets is greater than the target threshold, obtain the processor's data packet processing rate; and determine the target threshold based on the data packet processing rate.
[0111] Optionally, when the processor executes the program, it also performs the following steps: obtaining the number of data packets processed by the processor within a preset time period to obtain a first number; determining the duration of the preset time period as the target duration; and calculating the ratio of the first number to the target duration to obtain the data packet processing rate.
[0112] Optionally, the processor may also perform the following steps when executing the program: determining the number of data packets that the processor can process per second based on the data packet processing rate to obtain a second number; receiving an adjustment instruction sent by the terminal device; and adjusting the second number according to the adjustment instruction to obtain a target threshold.
[0113] Optionally, the processor may also perform the following steps when executing the program: Step 1, buffering multiple data packets according to the target processing order to obtain a target sequence; Step 2, determining the target data packet from the target sequence according to the processing order of each data packet in the target sequence; Step 3, determining the processor kernel corresponding to the target data packet as the target processor kernel; Step 4, controlling the target processor kernel to process the target data packet to obtain the processing result of the target data packet; Step 5, deleting the target data packet from the target sequence to obtain an updated target sequence; Step 6, repeating steps 2 to 5 until the processing result of each data packet is obtained.
[0114] Optionally, the processor may also perform the following steps when executing the program: buffering at least one data packet corresponding to each processor core according to the target processing order to obtain a data packet sequence corresponding to each processor core; and controlling each processor core to process the corresponding data packet sequence in parallel to obtain the processing result of each data packet.
[0115] Optionally, the processor may also perform the following steps when executing the program: after acquiring multiple data packets to be processed, acquire the processor utilization rate at the current time; if the utilization rate is greater than a preset threshold, control multiple processor cores to process the corresponding data packets in parallel and obtain the processing result of each data packet; if the utilization rate is less than or equal to the preset threshold, control each processor core to process the data packets corresponding to each processor core in the target processing order and obtain the processing result of each data packet.
[0116] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0117] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0118] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between units or modules may be electrical or other forms.
[0119] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0120] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0121] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part 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 of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0122] The above are merely preferred embodiments of this application. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A data processing method, characterized in that, include: Acquire multiple data packets to be processed, wherein each data packet corresponds to a processor core of the processor, and the processor includes multiple processor cores; Detect whether the total number of the multiple data packets exceeds a target threshold; When the total number is greater than the target threshold, multiple processor cores are controlled to process the corresponding data packets in parallel to obtain the processing result of each data packet. The multiple processor cores are independent of each other, and each processor core uses its own local computing data to process the data packets without using the common data between the multiple processor cores. If the total number is less than or equal to the target threshold, each processor core is controlled to process the data packets corresponding to each processor core in a target processing order to obtain the processing result of each data packet, wherein the target processing order is determined by the time when the data packet enters the processor core; The method further includes: common data among multiple processor cores working collaboratively through locking and unlocking, wherein while a processor core is locking the common data, the other processor cores cannot access or modify the common data.
2. The method according to claim 1, characterized in that, Before detecting whether the total number of the multiple data packets exceeds a target threshold, the method further includes: Obtain the data packet processing rate of the processor; The target threshold is determined based on the data packet processing rate.
3. The method according to claim 2, characterized in that, Obtaining the data packet processing rate of the processor includes: The number of data packets processed by the processor within a preset time period is obtained to obtain a first number; The duration of the preset time period is determined as the target duration; The ratio of the first quantity to the target duration is calculated to obtain the data packet processing rate.
4. The method according to claim 2, characterized in that, Determining the target threshold based on the data packet processing rate includes: Based on the data packet processing rate, the number of data packets that the processor can process per second is determined, thus obtaining the second number; Receive adjustment instructions sent by the terminal device; The second quantity is adjusted according to the adjustment instruction to obtain the target threshold.
5. The method according to claim 1, characterized in that, Control each processor core to process the data packets corresponding to each processor core according to the target processing order, and obtain the processing result of each data packet, including: Step 1: Buffer multiple data packets according to the target processing order to obtain a target sequence; Step 2: Determine the target data packet from the target sequence according to the processing order of each data packet in the target sequence; Step 3: Determine that the processor kernel corresponding to the target data packet is the target processor kernel; Step 4: Control the target processor kernel to process the target data packet and obtain the processing result of the target data packet; Step 5: Delete the target data packet from the target sequence to obtain the updated target sequence; Step 6: Repeat steps 2 to 5 until the processing result of each data packet is obtained.
6. The method according to claim 1, characterized in that, Controlling multiple processor cores to process corresponding data packets in parallel, and obtaining the processing result for each data packet, includes: According to the target processing order, at least one data packet corresponding to each processor core is cached to obtain a data packet sequence corresponding to each processor core; Each processor core is controlled in parallel to process the corresponding data packet sequence, and the processing result of each data packet is obtained.
7. The method according to claim 1, characterized in that, After acquiring multiple data packets to be processed, the method further includes: Obtain the utilization rate of the processor at the current time; When the utilization rate is greater than a preset threshold, multiple processor cores are controlled to process the corresponding data packets in parallel to obtain the processing result of each data packet. When the utilization rate is less than or equal to the preset threshold, each processor core is controlled to process the data packets corresponding to each processor core in the target processing order to obtain the processing result of each data packet.
8. A data processing apparatus, characterized in that, include: An acquisition module is used to acquire multiple data packets to be processed, wherein each data packet corresponds to a processor core of the processor, and the processor includes multiple processor cores; The detection module is used to detect whether the total number of the multiple data packets is greater than the target threshold; The first processing module is configured to control multiple processor cores to process the corresponding data packets in parallel when the total number is greater than the target threshold, and obtain the processing result of each data packet. The multiple processor cores are independent of each other, and each processor core uses its own local computing data to process the data packets without using the common data between the multiple processor cores. The second processing module is configured to, when the total number is less than or equal to the target threshold, control each processor core to process the data packets corresponding to each processor core in a target processing order to obtain the processing result of each data packet, wherein the target processing order is determined by the time when the data packet enters the processor core; The device is also used for collaborative operation of common data among multiple processor cores through locking and unlocking, wherein while one processor core is locking the common data, the other processor cores cannot access or modify the common data.
9. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the data processing method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Using multiple central processing unit cores for packet forwarding in virtualized networks
US9483317B1
