Log output method, load balancing device and computer readable storage medium
By using the working core and log core division of multi-core CPUs in load balancing equipment, the service traffic and log output are not interfered with each other, and dynamically adjusting the log output frequency, the problem of log output affecting forwarding speed in the existing technology is solved. , improves the real-time and integrity of log files and enhances security.
Patent Information
- Application Number
- CN202011187866.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-30
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2040-10-30
AI Technical Summary
When existing load balancing devices perform log output during business traffic forwarding, the forwarding speed is affected, and the polling method of the DPDK framework causes log output to be untimely, affecting monitoring of other log types.
The load balancing device adopts multi-core CPU. Through the division of labor between the working core and the log core, the working core is responsible for forwarding the business traffic and recording the log information to the ring queue. The log core obtains session information from the ring queue according to the preset frequency to output the log file to realize business The traffic and log output do not interfere with each other, and the output frequency of the log type is dynamically adjusted.
While ensuring the speed of forwarding of services traffic, real-time output and balanced output of various log types are realized, which improves the integrity and real-time nature of log files, promptly detects attack behaviors, and improves protection and security.
Smart Images

Figure CN112380001B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer network technology, and in particular to a log output method, a load balancing device, and a computer-readable storage medium. Background Art
[0002] Logs are data generated during program operation. Complete logs will play a positive role in program maintenance, fault tracing, user behavior analysis, etc., especially in the development and operation of large real-time systems, such as various load balancing programs and solutions suitable for content delivery network (CDN) application scenarios.
[0003] At present, in order to facilitate troubleshooting, in programs and solutions based on load balancing technology, it is generally necessary to output logs of business traffic forwarded by load balancing devices to facilitate subsequent positioning and analysis.
[0004] However, the existing log output is mostly done directly during the forwarding process of business traffic. Although this method can achieve log output, since the I / O read and write speed is much slower than the speed of the central processing unit (CPU) processing business traffic, even if the cache method is used to batch process I / O read and write operations, in the process of forwarding business traffic, letting the CPU that executes business traffic forwarding to output logs will still seriously affect the forwarding speed of business traffic.
[0005] In order to solve this problem, a log processing system based on the Data Plane Development Kit (DPDK) framework was developed. This log processing system realizes the independent forwarding of business traffic and log output by introducing a multi-core CPU and dividing the multi-core CPU into a log core and a working core. However, since the working principle of the DPDK framework is that the log core processes logs based on polling, only a certain type of log is output within a period of time. When all logs of this type are output, other types of logs will be processed, which seriously affects the monitoring of other logs. Summary of the invention
[0006] The purpose of the embodiments of the present invention is to provide a log output method, a load balancing device and a computer-readable storage medium, aiming to solve the above technical problems.
[0007] In order to solve the above technical problems, an embodiment of the present invention provides a log output method, which is applied to a load balancing device of a multi-core processor CPU. The log output method includes:
[0008] Receive business traffic, use the working cores in the multi-core CPU to perform data plane forwarding processing on the business traffic, dispatch the processed business traffic to the backend server, and record the session information corresponding to various log types generated during the processing into the ring queue corresponding to the working core;
[0009] For each type of log, during the process of the working core performing data plane forwarding processing on the business traffic, the log core in the multi-core CPU is used to obtain the corresponding session information from the ring queue at the preset frequency corresponding to the log type, and output the session information as a log file corresponding to the log type.
[0010] An embodiment of the present invention further provides a load balancing device, comprising:
[0011] at least one processor; and,
[0012] a memory communicatively connected to the at least one processor; wherein,
[0013] The at least one processor is a multi-core processor, which includes a working core and a log core. The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the log output method described above.
[0014] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program, wherein the computer program implements the log output method described above when executed by a processor.
[0015] The log output method, load balancing device and computer-readable storage medium provided by the embodiments of the present invention adopt a load balancing device with a multi-core CPU. When receiving business traffic, the designated working core in the multi-core CPU performs data plane forwarding processing on the business traffic, and dispatches the processed business traffic to the back-end server. At the same time, during the processing, the session information corresponding to each type of log generated is recorded in the circular queue corresponding to the working core, and the designated log core in the multi-core CPU is set to obtain session information from the circular queue corresponding to the working core regularly according to the preset frequency corresponding to each type of log during the working core performing the above processing, and output the obtained session information as a log file, thereby realizing non-interference between the forwarding of business traffic and the log output. While ensuring the forwarding speed of business traffic, the real-time output of logs corresponding to each type of log can also be performed, thereby ensuring the user experience and facilitating subsequent analysis and positioning according to the log file.
[0016] In addition, the log output method, load balancing device and computer-readable storage medium provided by the embodiments of the present invention output log files at preset frequencies corresponding to different log types when setting the designated log core in the multi-core CPU to output logs, thereby avoiding a single type of log file occupying the log core for a long time, so that log files of various log types can be output in a balanced manner. Therefore, when the number of CPU cores is limited, the frequency of each log output can be dynamically planned according to the log type corresponding to different business traffic, thereby ensuring the integrity and real-time performance of the log files of various log types output, so that various attack behaviors can be discovered in time according to the real-time and complete logs of various log types output, and corresponding warnings can be made to improve protection security.
[0017] In addition, before the log core in the multi-core CPU is used to obtain the corresponding session information from the circular queue at the preset frequency corresponding to the log type and output the session information as a log file corresponding to the log type, the method further includes: determining the quantity and length of the session information corresponding to the log type to obtain a first quantity and a first length; and planning the preset frequency corresponding to the log type according to the first quantity and the first length. In an embodiment of the present invention, the preset frequency corresponding to the log type of the type is planned according to the quantity and length of the session information corresponding to the log type, thereby realizing dynamic adjustment of the preset frequencies corresponding to various types of log types, so that the log core can more reasonably and evenly output various types of log files.
[0018] In addition, before recording the session information corresponding to each type of log generated during the processing into the circular queue corresponding to the working core, the method further includes: for each type of the log type, allocating a circular queue corresponding to the log type to the working core; wherein, recording the session information corresponding to each type of log generated during the processing into the circular queue corresponding to the working core includes: for each type of the log type generated during the processing, recording the session information corresponding to the log type in the circular queue allocated to the log type in the working core. In an embodiment of the present invention, by allocating a circular queue for recording session information of different log types to the working core, the classification of log types can be realized from the source, so that the log core can output different types of log files by obtaining session information from the circular queues corresponding to different log types.
[0019] In addition, the session information corresponding to each type of the log generated during the processing is recorded in the circular queue allocated to the log type in the working core, including: counting the number of the session information corresponding to each type of the log generated during the processing to obtain a second number; judging whether the second number meets the first preset condition; if so, taking the second number as a write batch, recording the session information in the circular queue allocated to the log type in the working core. In the embodiment of the present invention, by setting the session information to be recorded in the corresponding circular queue in a batch input manner, the working core processing efficiency is improved while the consumption of working core resources is effectively reduced.
[0020] In addition, the method of obtaining the corresponding session information from the circular queue at the preset frequency corresponding to the log type, and outputting the session information as a log file corresponding to the log type, includes: counting the number of session information recorded in the circular queue to obtain a third number; judging whether the third number satisfies a second preset condition; if so, obtaining the corresponding session information from the circular queue at the preset frequency corresponding to the log type with the third number as a batch, and outputting the session information as a log file corresponding to the log type. In an embodiment of the present invention, the log core is set to obtain session information from the circular queue in a batch reading manner, and outputs the session information as a log file, thereby greatly improving the throughput of the log file and effectively reducing the consumption of log core resources.
[0021] In addition, there are multiple working cores; for each type of log type, in the process of the working core performing data plane forwarding processing on the business traffic, the log core in the multi-core CPU is used to obtain the corresponding session information from the circular queue at a preset frequency corresponding to the log type, and the session information is output as a log file corresponding to the log type, including: for each type of log type, in the process of the working core performing data plane forwarding processing on the business traffic, the log core in the multi-core CPU is used to obtain the corresponding session information from the circular queue corresponding to each of the working cores at a preset frequency corresponding to the log type; the session information obtained from the circular queue corresponding to each of the working cores is aggregated and output as a log file corresponding to the log type.
[0022] In addition, before receiving the business traffic, the method also includes: determining the number of cores of the multi-core CPU; determining the number of working cores based on a preset working core ratio and the number of cores, and selecting cores of the number of working cores from the multi-core CPU as the working cores; determining the number of log cores based on a preset log core ratio and the number of cores, and selecting cores of the number of log cores from the remaining cores in the multi-core CPU as the log cores.
[0023] In addition, the selecting the number of cores of the log cores from the remaining cores in the multi-core CPU as the log cores includes: obtaining the load status of each remaining core in the multi-core CPU; and selecting the number of cores of the log cores from the remaining cores in the multi-core CPU as the log cores according to the load status of each remaining core. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0025] Figure 1 is a schematic diagram of the interaction between the working core and the log core in the log output method provided by the first embodiment of the present invention;
[0026] Figure 2 It is a schematic diagram of the interaction between a load balancing device, a client, and a backend server to which the log output method provided by the first embodiment of the present invention is applied;
[0027] Figure 3 is a schematic diagram of the interaction between the working core and the log core in the log output method provided by the first embodiment of the present invention;
[0028] Figure 4 is a schematic diagram of the interaction between the working core and the log core in the log output method provided by the second embodiment of the present invention;
[0029] Figure 5 It is a structural diagram of a load balancing device provided in the third embodiment of the present invention. DETAILED DESCRIPTION
[0030] To make the purpose, technical scheme and advantages of the embodiments of the present invention clearer, the embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in the embodiments of the present invention, many technical details are proposed in order to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can be implemented. The division of the following embodiments is for the convenience of description, and should not constitute any limitation on the specific implementation of the present invention. The various embodiments can be combined and referenced with each other without contradiction.
[0031] A first embodiment of the present invention relates to a log output method, which is applied to a load balancing device, and the processor in the load balancing device is a multi-core CPU.
[0032] In practical applications, the load balancing device of the multi-core CPU is, for example, a backend server. For ease of description, this embodiment is described by taking the load balancing device as a backend server as an example.
[0033] To facilitate understanding of the technical solution provided in this embodiment, it should first be explained that the multi-core CPU in the load balancing device mentioned in this embodiment will at least be divided into a working core for forwarding business traffic and a log core for log output.
[0034] The division of working cores and log cores may be determined specifically according to the number of cores of the multi-core CPU and preset proportions, such as the working core proportion and the log core proportion.
[0035] Specifically, in actual applications, before implementing the log output method provided in this embodiment, the load balancing device can first determine the number of cores of the multi-core CPU it uses; then, based on the preset working core ratio and the number of cores, determine the number of working cores, and based on the preset log core ratio and the number of cores, determine the number of log cores; then, select the cores with the number of working cores from the multi-core CPU as the working cores, and select the cores with the number of log cores from the remaining cores in the multi-core CPU as the log cores.
[0036] For example, for any multi-core CPU, in order to facilitate the following explanation, N is used to represent the number of CPU cores, and the agreed proportion of working cores is The proportion of log cores is
[0037] For an 8-core CPU, 4 cores can be set as working cores and 1 core as a log core. For a 16-core CPU, 8 cores need to be set as working cores and 1 core needs to be set as a log core. For a 32-core CPU, 16 cores need to be set as working cores and 1 core needs to be set as a log core.
[0038] For example, for any multi-core CPU, the proportion of working cores can be predetermined as The proportion of log cores to working cores Holistic
[0039] For an 8-core CPU, 4 cores need to be set as working cores and 1 core as a log core; for a 16-core CPU, 8 cores need to be set as working cores and 2 cores need to be set as log cores; for a 32-core CPU, 16 cores need to be set as working cores and 4 cores need to be set as log cores.
[0040] It should be understood that the above examples are merely examples listed for a better understanding of the technical solution of this embodiment and are not intended to be the sole limitation to this embodiment.
[0041] In addition, it is worth mentioning that in actual applications, when selecting the number of cores of the log cores from the remaining cores in the multi-core CPU as the log cores, it can be decided which remaining cores to select as log cores based on the load status of the remaining cores in the multi-core CPU.
[0042] Specifically, during implementation, the load status of each remaining core in the multi-core CPU may be obtained first; then, according to the load status of each remaining core, cores of the number of log cores are selected from the remaining cores in the multi-core CPU as the log cores.
[0043] For example, the load states of the remaining cores are sorted in ascending order, and then cores corresponding to the sorted load states are sequentially selected as log cores until the number of selected log cores is equal to the determined number of log cores.
[0044] Taking a 32-core CPU as an example, if the determined number of working cores is 16 and the number of log cores is 4, after 16 cores are selected as working cores from the 32 cores of the 32-core CPU, the remaining 16 cores need to be sorted in ascending order according to their load status, that is, the core with the smallest current load status is placed in front, and the first 4 cores are selected from the sorted cores in order as log cores.
[0045] From the above description, it can be seen that the selection of the log core is based on the dynamically changing load state, that is, the log core determined at the current moment satisfies the current performance of the load balancing device.
[0046] In addition, in actual applications, for application scenarios where the load status of each core changes little, in addition to determining the working core and the log core based on the above method, several cores can be directly fixed as log cores as needed.
[0047] It should be understood that the above examples are merely examples listed for a better understanding of the technical solution of this embodiment and are not intended to be the sole limitation to this embodiment.
[0048] In order to facilitate understanding of the log output method of this embodiment, the following Figures 1 to 3 , the implementation details of the log output method of this embodiment are explained.
[0049] It should be understood that the following content is only implementation details provided for ease of understanding and is not necessary for implementing this solution.
[0050] like Figure 1 As shown, for the working core of the multi-core CPU, when receiving business traffic, it will perform data plane forwarding processing on the business traffic, and record the session information corresponding to various log types generated during the processing into the circular queue corresponding to the working core.
[0051] At the same time, after completing the data plane forwarding processing of the business traffic, the processed business traffic will be directly dispatched to the backend server.
[0052] It should be understood that in actual applications, different business flows are often processed by different back-end servers. Therefore, after the working core completes the data plane forwarding processing of the business flow, it actually schedules the processed business flow to the specific back-end server to which the business flow points.
[0053] In addition, in this embodiment, the above-mentioned service traffic is generated according to the service operation triggered by the client in actual application, that is, the service traffic comes from the client.
[0054] For ease of understanding, the following combination Figure 2 To explain:
[0055] like Figure 2 As shown, assuming that within a certain time period, there are i clients that initiate business processing requests to a load balancing device including a j-core CPU. The load balancing device obtains the business traffic corresponding to the business processing requests based on the business processing requests initiated by each client. In order to distinguish the business traffic generated between different clients and determine which of the k backend servers needs to process the business traffic corresponding to different clients, the obtained business traffic corresponding to each client needs to carry at least the source IP address and source port of the client, as well as the destination IP address and destination port of the backend server to be accessed.
[0056] Assuming that the destination IP address and destination port carried in the business traffic corresponding to client 1 indicate that the back-end server that ultimately provides services to it is back-end server 1, the business traffic corresponding to the client will be directly dispatched to back-end server 1 by the working core in the load balancing device after data plane forwarding processing (specifically which one of CPU1, CPU2...CPUj is predetermined according to preset configuration requirements).
[0057] In addition, it should be understood that the values of i and k mentioned above need to be integers greater than 1, and the value of j needs to be at least an integer greater than 2, usually an integer multiple of 8.
[0058] In addition, according to Figure 1 It can be seen that in the process of the working core performing data plane forwarding processing on the business traffic and recording the session information corresponding to various log types generated during the processing into the ring queue corresponding to the working core, the log core will perform the following operations without affecting the processing of the business traffic by the working core:
[0059] For each log type, the log core obtains the session information corresponding to the current log type from the corresponding ring queue, and outputs the obtained session information as a log file corresponding to the current log type, that is, the generated log file only records the session information corresponding to the current log type.
[0060] From the above description, it can be seen that the forwarding of business traffic by the load balancing device is performed by a separate working core, and the output of logs is performed by a separate log core, so the forwarding of business traffic and the output of logs can not interfere with each other.
[0061] Furthermore, in actual applications, for the convenience of log core output, the log files are clustered according to the log type and then output, that is, the session information corresponding to different log types will be output as different log files. For example, for the CC attack (Challenge Collapsar Attack) type of session information mainly used to attack pages, it is output as a CC attack log file, and the session information of the session speed limit type is output as a session speed limit log file.
[0062] For each type of log, a circular queue corresponding to each type of log may be allocated to the working core in advance.
[0063] Correspondingly, when the working core records the session information corresponding to each type of log generated during the processing into the circular queue corresponding to the working core, it specifically records the session information corresponding to each type of log generated during the processing into the circular queue allocated by the working core for the log type, such as the session information of the CC attack type is recorded separately in the CC attack circular queue, and the session information of the session speed limit type is recorded separately in the session speed limit circular queue.
[0064] Therefore, by allocating a circular queue for recording session information of different log types to the working core, the log type classification can be achieved from the source, so that the log core can output different types of log files by obtaining session information from the circular queues corresponding to different log types.
[0065] In addition, it should be noted that the session mentioned above is usually called "session control" in computers, especially in network applications, and is used to store attributes and configuration information required for a specific user session.
[0066] Furthermore, in actual applications, in order to maximize the performance of the working core and the log core and reduce the consumption of working core and log core resources, for the working core, the session information generated during the processing can be recorded in batches to the corresponding ring queue, and for the corresponding log core, the session information can be obtained in batches from the corresponding ring queue.
[0067] Specifically, in order to realize batch recording of session information, the following implementation logic can be set for the working core:
[0068] First, the number of the session information corresponding to each type of the log generated during the processing is counted to obtain a second number.
[0069] Then, it is determined whether the second number meets a first preset condition, such as reaching a certain threshold.
[0070] For example, in actual applications, the threshold may be set according to the maximum number of data items or the amount of data that the working core can process at one time, such as setting the first preset condition to 32 data items or 100KB of data.
[0071] Therefore, the second number mentioned above may be the number of pieces of session information or the amount of data.
[0072] Correspondingly, if it is determined through judgment that the number of session information corresponding to a certain type of log generated at the current moment meets the above-mentioned first preset condition, the second number is used as a write batch, and the session information is recorded in the circular queue allocated to the log type in the working core.
[0073] Accordingly, in order to obtain session information in batches, a similar implementation process can be set for the log core:
[0074] First, the number of the session information recorded in the ring queue is counted to obtain a third number.
[0075] Then, it is determined whether the third quantity meets a second preset condition.
[0076] Correspondingly, if satisfied, the third quantity is used as a batch to obtain the corresponding session information from the circular queue at a preset frequency corresponding to the log type, and the session information is output as a log file corresponding to the log type.
[0077] It should be noted that in actual applications, in addition to dividing several cores into working cores and several cores into log cores, the multi-core CPU in the load balancing device may also reserve several cores for processing other services. For example, the main CPU core is used to uniformly receive the service traffic sent by different clients, especially to obtain the load status of each working core, and then allocate the currently received service traffic to the corresponding working core according to the load status for plane data forwarding processing and scheduling of the service traffic.
[0078] Accordingly, the quantity counting and judgment operations required for batch recording of session information may be implemented by the corresponding working cores, or by the main CPU core mentioned above.
[0079] Similarly, the quantity counting and judgment operations required for batch acquisition of session information can also be implemented by the log core or the main CPU core mentioned above.
[0080] In addition, it is worth mentioning that in actual applications, usually there are multiple working cores in the load balancing device. In this case, when the log core obtains session information from the ring queues corresponding to these working cores and outputs it to the log file, it is specifically as follows:
[0081] For each type of log, in the process of the working core performing data plane forwarding processing on the service traffic, the log core in the multi-core CPU is used to obtain the corresponding session information from the ring queue corresponding to each working core at a preset frequency corresponding to the log type;
[0082] The session information obtained from the circular queue corresponding to each of the working cores is aggregated and output as a log file corresponding to the log type.
[0083] For ease of understanding, the following combination Figure 3 To explain:
[0084] Assume that there are 3 working cores in the multi-core CPU of the current load balancing device, which are Figure 3 Working core 1, working core 2 and working core 3 in.
[0085] Furthermore, according to the session information generated during the data plane forwarding processing of the business traffic by these three working cores, it can be seen that the session information generated by working core 1 is divided into A log type and A' log type, the session information generated by working core 2 is divided into A log type, and the session information generated by working core 3 is divided into A log type and A' log type.
[0086] Based on this, a circular queue for recording log type A and a circular queue for recording log type A' are allocated to working core 1, a circular queue for recording log type A is allocated to working core 2, and a circular queue for recording log type A and a circular queue for recording log type A' are allocated to working core 3.
[0087] Correspondingly, when the session information a (session information a1, session information a2...) of the A log type generated during the business traffic processing by the working core 1 meets a preset condition, it is recorded in batches in the circular queue of the A log type corresponding to the working core 1; when the session information a' (session information a'1, session information a'2...) of the A' log type generated during the business traffic processing by the working core 1 meets a preset condition, it is recorded in batches in the circular queue of the A' log type corresponding to the working core 1.
[0088] The recording process types of working core 2 and working core 3 are not described in detail here.
[0089] Accordingly, it is assumed that the preset frequency set for the A log type is to obtain a preset batch of session information every minute, and the preset frequency set for the A' log type is to obtain a preset batch of session information every 30 seconds.
[0090] Then, for the log core, within a certain working cycle, the session information in the circular queue of the A log type and the session information in the circular queue of the A' log type corresponding to the three working cores will be obtained alternately at the above two time granularities, and then the session information obtained from the circular queue of the A log type corresponding to each of the above three working cores will be output as a log file of the A log type, and the session information obtained from the circular queue of the A' log type corresponding to each of the above three working cores will be output as a log file of the A' log type. By outputting log files at preset frequencies of different log types, it is effectively avoided that a single type of log file occupies the log core for a long time, thereby ensuring the integrity and real-time performance of log files of various log types.
[0091] It should be understood that the above examples are merely examples listed for a better understanding of the technical solution of this embodiment and are not intended to be the sole limitation to this embodiment.
[0092] It is not difficult to find from the above description that the log output method provided in this embodiment, by adopting a multi-core CPU load balancing device, when receiving business traffic, the designated working core in the multi-core CPU performs data plane forwarding processing on the business traffic, and dispatches the processed business traffic to the back-end server, and at the same time, during the processing, the session information corresponding to the various log types generated is recorded in the circular queue corresponding to the working core, and the designated log core in the multi-core CPU is set to obtain session information from the circular queue corresponding to the working core regularly according to the preset frequency corresponding to each log type during the process of the working core executing the above processing, and output the obtained session information as a log file, thereby realizing non-interference between the forwarding of business traffic and the log output, and ensuring the forwarding speed of business traffic while also achieving real-time output of logs, which not only ensures the user experience, but also facilitates subsequent analysis and positioning based on log files.
[0093] In addition, the log output method provided in this embodiment, by setting the designated log core in the multi-core CPU to output log files at preset frequencies of different log types when performing log output, avoids a single type of log file occupying the log core for a long time, so that log files of various log types can be output in a balanced manner, thereby ensuring the integrity and real-time performance of log files of various log types.
[0094] The second embodiment of the present invention relates to a log output method. The second embodiment is further improved on the basis of the first embodiment, and the main improvement is that the preset frequency of the log core obtaining session information from the ring queue corresponding to different log types is dynamically determined according to the number of session information generated in real time when the working core processes the business traffic and the length of each session information.
[0095] like Figure 2 As shown, before the log core obtains the session information from the circular queue corresponding to each log type corresponding to the working core, it needs to first obtain the first quantity and first length of the session information recorded in the corresponding circular queue from the working core, and then plan the preset frequency of the corresponding log type according to the obtained first quantity and first length, that is, according to the number of session information and the length or size of each session information, determine the interval for obtaining the session information of the current log type.
[0096] Specifically, the first quantity and the first length acquired by the log core may be determined by the working core, or may be determined by the main CPU core mentioned in the first embodiment.
[0097] Correspondingly, for the method determined by the working core, the log core obtains the first quantity and the first length directly from the working core; for the method determined by the main CPU core, the log core needs to obtain the first quantity and the first length from the main CPU core, or initiate a request to the working core to obtain the first quantity and the first length, and the working core obtains them from the main CPU core and feeds them back to the log core.
[0098] It should be understood that the above examples are merely examples listed for a better understanding of the technical solution of this embodiment and are not intended to be the sole limitation to this embodiment.
[0099] Therefore, the log output method provided in this embodiment plans the preset frequency corresponding to the log type of this type according to the number and length of session information corresponding to the log type, thereby realizing dynamic adjustment of the preset frequency corresponding to each type of log type, so that the log core can output various types of log files more reasonably and balancedly.
[0100] It should be understood that the step division of the above methods is only for clear description. When implemented, they can be combined into one step or some steps can be split and decomposed into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this patent; adding insignificant modifications to the algorithm or process or introducing insignificant designs without changing the core design of the algorithm and process are all within the scope of protection of this patent.
[0101] A third embodiment of the present invention relates to a load balancing device, such as Figure 5 As shown, it includes at least one processor 501; and a memory 502 that is communicatively connected to the at least one processor 501; wherein the at least one processor 501 is a multi-core processor, and the multi-core processor includes a working core and a log core, and the memory 502 stores instructions that can be executed by the at least one processor 501, and the instructions are executed by the at least one processor 501 so that the at least one processor 501 can execute the log output method described in the first or second embodiment above.
[0102] The memory 502 and the processor 501 are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors 501 and the memory 502 together. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor 501 is transmitted on a wireless medium via an antenna, and further, the antenna also receives data and transmits the data to the processor 501.
[0103] The processor 501 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 502 can be used to store data used by the processor 501 when performing operations.
[0104] A fourth embodiment of the present invention relates to a computer-readable storage medium storing a computer program, which implements the above-mentioned log output method embodiment when executed by a processor.
[0105] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0106] Those skilled in the art will appreciate that the above embodiments are specific embodiments for implementing the present invention, and that in actual applications, various changes may be made in form and detail without departing from the spirit and scope of the present invention.
Claims
1. A log output method, characterized in that: A load balancing device applied to a multi-core processor CPU, wherein the log output method includes: Receive business traffic, use the working cores in the multi-core CPU to perform data plane forwarding processing on the business traffic, dispatch the processed business traffic to the backend server, and record the session information corresponding to various log types generated during the processing into the ring queue corresponding to the working core; For each type of log, in the process of the working core performing data plane forwarding processing on the service traffic, the log core in the multi-core CPU is used to obtain the corresponding session information from the ring queue at a preset frequency corresponding to the log type, and the session information is output as a log file corresponding to the log type; Wherein, there are multiple working cores; For each type of log, in the process of the working core performing data plane forwarding processing on the service traffic, using the log core in the multi-core CPU, at a preset frequency corresponding to the log type, obtaining the corresponding session information from the ring queue, and outputting the session information as a log file corresponding to the log type, including: For each type of log, in the process of the working core performing data plane forwarding processing on the service traffic, the log core in the multi-core CPU is used to obtain the corresponding session information from the ring queue corresponding to each working core at a preset frequency corresponding to the log type; The session information obtained from the circular queue corresponding to each of the working cores is aggregated and output as a log file corresponding to the log type.
2. The log output method according to claim 1, characterized in that: Before using the log core in the multi-core CPU to obtain the corresponding session information from the ring queue at a preset frequency corresponding to the log type and outputting the session information as a log file corresponding to the log type, the method further includes: Determine the quantity and length of the session information corresponding to the log type to obtain a first quantity and a first length; The preset frequency corresponding to the log type is planned according to the first quantity and the first length.
3. The log output method according to claim 1, characterized in that: Before recording the session information corresponding to each type of log generated during the processing into the circular queue corresponding to the working core, the method further includes: For each type of the log, a circular queue corresponding to the log type is allocated to the working core; The step of recording the session information corresponding to each type of log generated during the processing into the circular queue corresponding to the working core includes: The session information corresponding to each log type generated during the processing is recorded in the circular queue allocated to the log type in the working core.
4. The log output method according to claim 3, characterized in that: The recording of the session information corresponding to each type of the log generated during the processing into the ring queue allocated for the log type in the working core includes: Counting the number of session information corresponding to each type of log generated during the processing to obtain a second number; Determining whether the second quantity satisfies a first preset condition; If satisfied, the second number is used as a write batch to record the session information into a circular queue allocated to the log type in the working core.
5. The log output method according to claim 4, characterized in that: The acquiring the corresponding session information from the ring queue at a preset frequency corresponding to the log type, and outputting the session information as a log file corresponding to the log type, includes: Counting the number of the session information recorded in the ring queue to obtain a third number; Determining whether the third quantity satisfies a second preset condition; If satisfied, the third quantity is used as a batch to obtain the corresponding session information from the circular queue at a preset frequency corresponding to the log type, and the session information is output as a log file corresponding to the log type.
6. The log output method according to any one of claims 1 to 5, characterized in that: Before receiving the service traffic, the method further includes: Determine the number of cores of the multi-core CPU; Determine the number of working cores according to a preset working core ratio and the number of cores, and select cores with the number of working cores from the multi-core CPU as the working cores; According to the preset log core ratio and the number of cores, the number of log cores is determined, and cores of the number of log cores are selected from the remaining cores in the multi-core CPU as the log cores.
7. The log output method according to claim 6, characterized in that: The step of selecting the number of cores of the log cores from the remaining cores in the multi-core CPU as the log cores includes: Obtaining the load status of each remaining core in the multi-core CPU; According to the load status of the remaining cores, cores of the number of log cores are selected from the remaining cores in the multi-core CPU as the log cores.
8. A load balancing device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The at least one processor is a multi-core processor, which includes a working core and a log core. The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the log output method as described in any one of claims 1 to 7.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the log output method according to any one of claims 1 to 7 is implemented.
