CN108521351B - Session flow statistical method, processor core, storage medium and electronic device - Google Patents
Session flow statistical method, processor core, storage medium and electronic device Download PDFInfo
- Publication number
- CN108521351B CN108521351B CN201810237054.8A CN201810237054A CN108521351B CN 108521351 B CN108521351 B CN 108521351B CN 201810237054 A CN201810237054 A CN 201810237054A CN 108521351 B CN108521351 B CN 108521351B
- Authority
- CN
- China
- Prior art keywords
- session
- mode core
- traffic
- user mode
- address
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L43/00—Arrangements for monitoring or testing data switching networks
- H04L43/08—Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
- H04L43/0876—Network utilisation, e.g. volume of load or congestion level
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/14—Session management
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Environmental & Geological Engineering (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The disclosure relates to a session flow statistical method, a processor core, a storage medium and an electronic device. The method is applied to any user mode core in a multi-core processor, each user mode core is correspondingly provided with a session table, each session of the user mode core is provided with a corresponding session table item in the session table, and for each session of the user mode core, index information of the session table item corresponding to the session generating flow in each statistical period is written into a message transmission address of the user mode core; the address for storing the session table and the message passing address both belong to a shared memory of a user mode core and a kernel mode core, and the index information of the session table entry is used for identifying the memory address of the session table entry in the session table of the user mode core, so that the kernel mode core reads the flow information in the corresponding session table entry for statistics based on the index information in the message passing address.
Description
Technical Field
The present disclosure relates to the field of computers, and in particular, to a session flow statistical method, a processor core, a storage medium, and an electronic device.
Background
For security manufacturers, the traffic performance of a firewall in a real scene is important, which relates to statistics on session traffic. However, the content of the session traffic statistics is very huge, and it is counted based on the session resources, and the session resources take quintuple as key (sip, sport, dip, dport, protocol), the key of the session consists of two quintuple in left and right directions, the size of the single statistical key has 80 bytes, and the number of the key is more likely to be tens of millions. Therefore, if statistical sampling is required every second, each cpu of the forwarding module every second sends flow information to the session flow statistical module, and the statistical module analyzes and processes the flow all the time, so that the overall consumed calculation amount is huge.
In the related art, most manufacturers usually add a prompt "if traffic flow statistics is turned on, the performance of the system will be greatly reduced" when the function is turned on, so as to prompt the user about the influence of the function on the performance.
Disclosure of Invention
The present disclosure provides a session traffic statistical method, a processor core, a storage medium, and an electronic device, so as to solve the problem of excessive calculation amount consumed by the existing session traffic statistical method.
In order to achieve the above object, a first aspect of the present disclosure provides a session flow statistics method, where the method is applied to any user mode core in a multi-core processor, each user mode core is correspondingly provided with a session table, and each session of the user mode core establishes a corresponding session table entry in the session table, where the method includes:
aiming at each conversation of the user mode core, writing index information of a conversation table item corresponding to the conversation generating flow in each statistical period into a message transmission address of the user mode core;
the address for storing the session table and the message passing address both belong to a shared memory of a user mode core and a kernel mode core, and the index information of the session table entry is used for identifying the memory address of the session table entry in the session table of the user mode core, so that the kernel mode core reads the flow information in the corresponding session table entry for statistics based on the index information in the message passing address.
Optionally, the writing, in the message passing address of the user mode core, the index information of the session table entry corresponding to the session in which the traffic is generated in each statistical period includes:
analyzing a message of a session generating flow, and determining whether the session is about to fail according to a session state in the message;
when the session state indicates that the session is kept effective, writing the handle number and the session table type of the session table item corresponding to the session into the message transfer address of the user state core;
the method further comprises the following steps:
when the session state indicates that the session is about to be invalid, creating a new traffic table entry in a traffic table corresponding to the user mode core according to left and right keys of the session and flow information, and writing a handle number and a traffic table type of the new traffic table entry into a message transfer address of the user mode core, wherein the address for storing the traffic table belongs to a shared memory of the user mode core and the kernel mode core.
Optionally, the creating a new traffic table entry in a traffic table corresponding to the user mode core according to the left and right keys of the session and the traffic information includes:
and sequentially creating each traffic table entry, and adopting a replacement mechanism to sequentially replace the content of each created traffic table entry according to the sequence when the memory for storing the traffic table is full.
Optionally, writing the content in the message passing address corresponding to the user mode core is performed in a consistent hash ring manner.
The second aspect of the present disclosure provides another session traffic statistical method, which is applied to a kernel-mode core in a multi-core processor, and the method includes:
polling the message transmission address of each user mode core to obtain index information newly written in the message transmission address in each statistical period, wherein the index information is used for identifying the memory address of a session table item corresponding to a session generating flow in the statistical period in a session table, and the address for storing the session table and the message transmission address both belong to a shared memory of the user mode core and a kernel mode core;
and reading the flow information in the corresponding session table entry according to the index information to carry out flow statistics.
Optionally, the reading, according to the index information, traffic information in a corresponding session table entry for performing traffic statistics includes:
when the index information comprises the type of a session table and a handle number of a session table item, counting flow information recorded in the session table item identified by the handle number in the session table;
the method further comprises the following steps:
when the index information comprises a traffic table type and a handle number of a traffic table item, traffic information recorded in the traffic table item identified by the handle number is counted in the traffic table, wherein the traffic table item is created in the traffic table of the user mode core according to left and right keys of the session and the traffic information when the user mode core determines that the session is invalid in the next counting period.
Optionally, polling the message passing address corresponding to the user mode core is performed in a consistent hash ring manner.
A third aspect of the present disclosure provides a user mode core, comprising:
a write-in module, configured to write, for each session of the user mode core, index information of a session table entry corresponding to a session that generates traffic in each statistical period into a message passing address of the user mode core;
the user mode core is correspondingly provided with a session table, addresses for storing the session table and the message transmission addresses both belong to the shared memories of the user mode core and the kernel mode core, each session of the user mode core establishes a corresponding session table item in the session table, and index information of the session table item is used for identifying the memory address of the session table item in the session table of the user mode core, so that the kernel mode core reads flow information in the corresponding session table item for statistics based on the index information in the message transmission addresses.
Optionally, the user mode core further includes a message parsing module, configured to parse a message of a session generating a flow, and determine whether the session is about to fail according to a session state in the message, where the writing module is configured to write, when the session state indicates that the session is valid, a handle number and a session table type of a session table entry corresponding to the session into a message delivery address of the user mode core;
the user mode core further comprises a creating module, configured to create a new traffic table entry in a traffic table corresponding to the user mode core according to left and right keys of the session and flow information when the session state indicates that the session is about to fail, where the writing module is configured to write a handle number and a traffic table type of the new traffic table entry into a message passing address of the user mode core, where an address storing the traffic table is a shared memory of the user mode core and the kernel mode core.
Optionally, the creating module is configured to:
and sequentially creating each traffic table entry, and adopting a replacement mechanism to sequentially replace the content of each created traffic table entry according to the sequence when the memory for storing the traffic table is full.
A fourth aspect of the present disclosure provides a kernel-mode core, comprising:
a polling module, configured to poll a message passing address of each user mode core to obtain index information newly written in the message passing address in each statistical period, where the index information is used to identify a memory address, in a session table, of a session entry corresponding to a session that generates traffic in the statistical period, where the address for storing the session table and the message passing address both belong to a shared memory of the user mode core and the kernel mode core;
and the flow counting module is used for reading the flow information in the corresponding session table entry according to the index information to carry out flow counting.
Optionally, the traffic statistic module is configured to:
when the index information comprises the type of a session table and a handle number of a session table item, counting flow information recorded in the session table item identified by the handle number in the session table;
the flow statistics module is further configured to:
when the index information comprises a traffic table type and a handle number of a traffic table item, traffic information recorded in the traffic table item identified by the handle number is counted in the traffic table, wherein the traffic table item is created in the traffic table of the user mode core according to left and right keys of the session and the traffic information when the user mode core determines that the session is invalid in the next counting period.
A fifth aspect of the present disclosure provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the method of the first or second aspect.
A sixth aspect of the present disclosure provides an electronic device comprising a first computer-readable storage medium, a user-mode core, a second computer-readable storage medium, a kernel-mode core;
wherein the user-mode kernel implements the steps of the method of the first aspect when executing a computer program stored on the first computer-readable storage medium;
the kernel mode core implements the steps of the method of the second aspect when executing the computer program stored on the second computer readable storage medium.
Through the technical scheme, the session table is designed to be a shared memory of the user mode core and the kernel mode core, so that the kernel mode core can directly read the session flow information from the table entry of the session table. And the information transmission between the user mode core and the kernel mode core does not adopt a notification mechanism, the user mode core only needs to write the index information of the session generating the flow into the message transmission address, the kernel mode core can read the index information from the message transmission address and read the flow information from the corresponding session table entry according to the index information, compared with the notification mechanism that the user mode core needs to notify the kernel mode to receive the whole session resource in a system calling mode, the technical scheme provided by the disclosure saves a large amount of message transmission contents, avoids the user mode core from initiating the system calling in a large amount, and thus reduces the consumption of calculation amount. And because the session table and the message transmission address are set corresponding to each user mode core, competition among multiple cores is avoided, the multiple cores are ensured not to be interfered with each other, and the performance of the multiple core processor can be increased linearly along with the increase of the cores.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows.
Drawings
The accompanying drawings, which are included to provide a further understanding of the disclosure and are incorporated in and constitute a part of this specification, illustrate embodiments of the disclosure and together with the description serve to explain the disclosure without limiting the disclosure. In the drawings:
fig. 1 is a schematic structural diagram of an asynchronous multicore processor provided in an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of a session traffic statistical method according to an embodiment of the present disclosure;
fig. 3 is a schematic flowchart of a session traffic statistic method according to an embodiment of the present disclosure;
fig. 4 is a schematic flowchart of another session traffic statistical method according to an embodiment of the present disclosure;
fig. 5 is a schematic structural diagram of a user mode core provided in an embodiment of the present disclosure;
fig. 6 is a schematic structural diagram of a kernel-mode core according to an embodiment of the present disclosure.
Detailed Description
The following detailed description of specific embodiments of the present disclosure is provided in connection with the accompanying drawings. It should be understood that the detailed description and specific examples, while indicating the present disclosure, are given by way of illustration and explanation only, not limitation.
The following embodiments of the present disclosure may be used in a multi-core processor, and fig. 1 provides a schematic structural diagram of an asynchronous multi-core processor 10, and referring to fig. 1, the asynchronous multi-core processor 10 includes a CPU0, a CPU1, a CPU2, and a CPU3 operating in a user state, and a CPU4, a CPU5, a CPU6, and a CPU7 operating in a kernel state.
It is worth noting that the allocation of CPUs of an asynchronous multi-core processor is a dedicated role allocation, i.e. one CPU only does one thing, not one CPU does all things. For this reason, the intelligence of the asynchronous multi-core processor is divided into two parts, namely fast forwarding logic (the disclosure is simply referred to as a fast module) and strategy slow logic (the disclosure is simply referred to as a slow module) with complex functions. As shown in fig. 1, the fast module includes the CPU0, the CPU1, the CPU2, and the CPU3 shown in fig. 1; the slow modules include the CPU4, CPU5, CPU6, and CPU7 shown in fig. 1, wherein the fast modules are responsible for fast forwarding logic and the slow modules are responsible for functionally complex strategic slow logic. In the operation state, the asynchronous multi-core processor is divided into a kernel state and a user state, the kernel state is used for realizing logic with complex functions, the slow module operates in the time state, the user state is used for receiving network card messages and realizing fast forwarding logic, and the fast module operates in the user state. That is, from the runtime state, the CPU0, the CPU1, the CPU2, and the CPU3 shown in fig. 1 are user-state cores, and the CPU4, the CPU5, the CPU6, and the CPU7 are kernel-state cores.
The module for carrying out session traffic statistics is in the slow module, after all, the function is very complex and time-consuming to implement, and the general traffic fast forwarding processing is carried out by the fast module. In the related art, because the statistics of the session traffic requires that multiple cores simultaneously count and summarize to the session traffic statistics module, contention of shared resources exists among the multiple cores, and because lock contention exists, the performance of a multi-core processor is not better due to the multiple cores, and even the multi-core performance is not better than that of a single core due to poor design, and forwarding of normal traffic is also affected.
The embodiment of the present disclosure provides a session flow statistical method, which is applied to any user mode core in a multi-core processor, for example, any user mode core in an asynchronous multi-core processor 10 shown in fig. 1, where each user mode core is correspondingly provided with a session table, and each session of the user mode core establishes a corresponding session table entry in the session table, as shown in fig. 2, the method includes:
s101, aiming at each conversation of a user mode core, writing index information of a conversation table item corresponding to the conversation generating flow in each statistical period into a message transmission address of the user mode core so that the core mode core reads the flow information in the corresponding conversation table item for statistics based on the index information in the message transmission address.
The method comprises the steps that each user mode core is correspondingly provided with a message transmission address, the address for storing the session table and the message transmission address belong to a shared memory of the user mode core and a kernel mode core, and index information of session table entries is used for identifying memory addresses of the session table entries in the user mode core.
Specifically, for the design of the session table, the embodiment of the present disclosure designs the session table as a per-core mechanism, that is, one session table is correspondingly set for one user mode core. Illustratively, a memory pool is used to allocate memory for storing the session table for each user mode core during the module initialization phase, and the memory address of each session table can be designed as a continuous space. Thus, each session table corresponds to an array (the array represents the memory space allocated from the memory pool), and an entry created in the session table by each session of the user-mode core corresponds to a subscript of the array, where the subscript is a fixed index of a session entry in the memory and is also referred to as a handle number. The index information may include a handle number, and according to the handle number, the corresponding session entry may be found, and the content recorded in the session entry may be read.
The meaning of the session table entry is that the fast module forwards the message based on the message received. Specifically, when the session table entry is not found, the message is sent to the slow module for policy matching, then the session is quickly created, and if the session table entry is found, the message is forwarded based on the existing session table. In the related art, the session table is actually established on the fast module, the user is also the fast module, and the slow module cannot perform query, so that when performing session traffic statistics in the related art, the fast module needs to transmit traffic information to the slow module core, where the traffic information is part of a session table entry, and the amount of the traffic information is basically the number of effective traffic within one second of the session, which results in a huge data amount transmitted between cores. The session table is designed to be a shared memory through the optimization design of the method, and the content required by the session flow counting module is just part of the content of the session table item, so that the session flow counting module can be directly accessed after the session flow counting module is designed to be the shared memory, and a large amount of inter-core message transmission is saved.
In addition, regarding the message transmission mode, a notification mechanism is adopted in the related art, and the user mode notifies the kernel mode to accept the message by using a system call mode, that is, the inter-core interrupt IPI is sent to the kernel mode core. After all, the fast module is user-mode packet receiving processing based on a polling mechanism, and if the fast module is occupied by a large amount of system calls, the packet loss of the forwarding module can be caused due to untimely packet receiving processing. In order to solve the problem, in the technical solution provided in the embodiment of the present disclosure, the information transmission between the user mode core and the kernel mode core does not use a notification mechanism, and the user mode core only needs to write the index information of the session table corresponding to the session generating the traffic into the message transmission address, where the message transmission address belongs to the shared memory of the user mode core and the kernel mode core. Therefore, the kernel mode core can read the index information from the message transmission address and read the flow information from the corresponding session table item according to the index information. Compared with a notification mechanism that the user mode core needs to notify the kernel mode to receive the whole session resource in a system call mode, the technical scheme provided by the disclosure saves a large amount of message transmission contents, and avoids the user mode core from initiating a large amount of system calls, thereby reducing the consumption of calculation amount. And because the session table and the message passing address are set corresponding to each user mode core, competition among multiple cores is avoided, multiple cores are guaranteed to be not interfered with each other concurrently, and the performance of the multiple core processor can be increased linearly along with the increase of the cores.
Specifically, the content written in the message passing address of the user mode core may be in a manner of a consistent hash ring (ring), that is, a ring is established for each user mode core. Specifically, a ring mechanism is used, read and write pointers are set, the user mode core performs continuous write operation, the kernel mode core performs continuous read operation, when the read and write operations are the same, no new message comes, and the kernel mode core does not need to process any new message. Therefore, by adopting the ring mechanism, the kernel-mode core can use an independent thread to poll and process the ring of each user-mode core, only a plurality of ring rings from the user mode to the kernel mode need to be maintained in the whole process, and any memory life cycle does not need to be maintained, so that any message flow is transmitted to the kernel mode without maintaining the memory release, the whole design is simplified, and the performance consumption caused by the memory release is reduced.
In specific implementation, in order to ensure that the concurrency among multiple cores is not affected, only one traffic thread can be started in a kernel mode to perform session traffic statistics, lock contention caused by multiple cores is avoided, and the overall forwarding performance is improved.
In addition, the above statistical period may be set according to actual requirements, for example, the flow generated by a session within two seconds is counted, and the disclosure is not limited. However, for a set statistical period, there is a possibility that it is not yet time to count the traffic of a session in the statistical period, and the session is deleted. For example, a session is destroyed within the second, but the traffic of the session still needs to be transferred to the kernel mode core, so that the kernel mode core may find a failed session entry in the shared memory according to the index information, resulting in a loss of the traffic statistics.
In order to solve this problem, an embodiment of the present disclosure provides another session traffic statistical method, as shown in fig. 3, which is applied to any user-mode core in a multi-core processor, and includes:
s201, a user mode core analyzes a message of a session generating flow, and determines whether the session is about to fail according to a session state in the message.
Specifically, the session that generates traffic refers to a session that transmits a message, and thus, the session state in the message is obtained by analyzing the message, and it can be determined whether the session is to be continuously maintained or needs to be disconnected according to the session state. It should be noted that, when receiving an instruction indicating session disconnection, the client sends a message for notifying the session disconnection to the server, so that when the user mode core forwards the message, it can know that the session is about to be disconnected by analyzing the message.
Further, if the analyzed session status indicates that the session is valid, step S202 is executed; if the analyzed session status indicates that the session is about to fail, step S203 to step S204 are executed.
S202, writing the handle number and the session table type of the session table entry corresponding to the session into the message passing address of the user mode core.
In the embodiment of the present disclosure, the session table and the message passing address may be designed according to the above description of step S101 shown in fig. 1, and details are not described here.
S203, creating a new traffic table item in the traffic table corresponding to the user mode core according to the left and right keys of the session and the traffic information.
Wherein, the left and right keys are five-tuple (sip, short, dip, dport, protocol) in left and right directions recorded in the session table entry respectively. The traffic information refers to the traffic in _ pkts, out _ pkts, in _ bytes, out _ bytes of this session. The user mode core can directly extract left and right keys and flow information from the session table entry.
In order to ensure that the session resource which is about to fail can be correctly transferred, a traffic table is correspondingly arranged on each user mode core, wherein the traffic table is consistent with the design of the session table, and each internal table entry has a corresponding array subscript, which is also called handle number. And the address for storing the traffic table also belongs to a shared memory which is a user mode core and a kernel mode core, so that the kernel mode core can access the shared memory.
And S204, writing the handle number and the traffic table type of the new traffic table item into the message passing address of the user mode core.
Therefore, for the session about to fail in the next statistical period, the kernel-state core can count the traffic information in the traffic table, thereby avoiding the traffic counting loss caused by the session failure and improving the accuracy of the traffic counting.
It should be noted that, in order to distinguish the session table and the traffic table, the content written by the user mode core at the message passing address includes a memory pool type in addition to the handle number, taking a ring as an example, the content of each element in the ring is (handle number, sequence number of the mempool), where the type of the mempool is divided into two major classes, one of which is the session pool and the other is the traffic pool. Since the session pool and traffic pool are respectively one for each user mode core, the mempool number is actually the global number of the session pool and traffic pool of each corresponding user mode core, which is determined by initialization. If the session table type in step S202 and the traffic table type in step S204 are used, so that when the read content includes the session pool type and the handle number of the session entry, the kernel mode core counts the traffic information of the session entry record identified by the handle number in the session table; when the read content comprises the traffic pool type and the handle number of the traffic entry, the traffic information of the traffic entry record identified by the handle number is counted in the traffic table.
In addition, in a possible implementation manner of the embodiment of the present disclosure, the traffic table has no release memory mechanism, when a traffic table entry is initially created, the user mode core creates each traffic table entry in sequence, and adopts a replacement mechanism, and when a memory storing the traffic table is full, contents of each created traffic table entry are sequentially replaced according to the sequence. The order may be, for example, the order in which handles are sequentially increased. Moreover, in order to avoid that the newly-established traffic table entry is not read by the kernel mode core due to too small memory allocated to the traffic table, and the user mode core has already replaced the newly-established traffic table entry for the next time, the memory allocated to the traffic table should be larger than the maximum value of the number of sessions that may fail in one statistical period, and in specific implementation, the traffic table entries stored in the allocated memory can reach the million level. Therefore, the traffic pool only applies for alloc operation by the memory and has no release mechanism, so that the kernel mode is not required to inform the user mode to release the memory after reading a certain traffic table entry, the complexity of the system is simplified, and the performance consumption caused by memory release is avoided.
The embodiment of the present disclosure further provides another session flow statistical method, which is applied to a kernel-mode core in a multi-core processor, as shown in fig. 4, and the method includes:
s301, polling the message transmission address of each user mode core to obtain the index information newly written in the message transmission address in each statistical period.
The index information is used to identify the memory address of the session table entry in the session table corresponding to the session generating the traffic in the statistical period, wherein the address storing the session table and the message passing address both belong to the shared memory of the user mode core and the kernel mode core.
S302, reading the flow information in the corresponding session table entry according to the index information to perform flow statistics.
Optionally, the reading, according to the index information, traffic information in a corresponding session table entry for performing traffic statistics includes:
when the index information comprises the type of a session table and a handle number of a session table item, counting flow information recorded in the session table item identified by the handle number in the session table;
the method further comprises the following steps:
when the index information comprises a traffic table type and a handle number of a traffic table item, traffic information recorded in the traffic table item identified by the handle number is counted in the traffic table, wherein the traffic table item is created in the traffic table of the user mode core according to left and right keys of the session and the traffic information when the user mode core determines that the session is invalid in the next counting period.
Optionally, polling the message passing address corresponding to the user mode core is performed in a consistent hash ring manner.
In addition, in order to ensure that the concurrency among the multiple cores is not affected, only one traffic thread may be started in the kernel mode to perform session traffic statistics, that is, the method shown in fig. 3 is applied to the core running the traffic thread in the kernel mode, so that lock contention caused by the multiple cores is avoided, and the overall forwarding performance is improved.
The session table and the message passing address are specifically designed with reference to the above description of the session traffic statistical method on the user mode core side, and details are not repeated here.
In order to make those skilled in the art understand the technical solution provided by the embodiment of the present disclosure, the following takes the asynchronous multicore processor 10 shown in fig. 1 as an example to describe the session traffic statistical method provided by the embodiment of the present disclosure.
After the traffic statistic function is started, the CPU0, the CPU1, the CPU2, and the CPU3 in the asynchronous multi-core processor 10 all transmit the index information of the session in which the message needs to be transmitted into the ring of each core according to a set statistic period, and the message format is (handle number, memory pool type). The statistical period may be preset, for example, one second. It should be noted that the operation is reflected in the code as a flow of forwarding based on the session table, and in the case that the statistical period is one second, if the processing distance of a certain packet exceeds one second from the last time, the handle number and the session table type are written into the ring corresponding to the user mode core. In another case, if the message is about to be deleted in the next second, the left and right key values and the flow information of the session are extracted, a traffic entry is established from a traffic pool corresponding to the user mode core, the extracted content is filled into the newly established traffic entry, and then the handle number and the traffic type of the traffic entry are filled into the ring. Since each user mode core has a ring, the writing process of the ring is completely lock-free. That is to say, each core between multiple cores is operated completely independently without competing any resource, thereby ensuring that the whole performance under the multi-core system can be increased completely linearly along with the increase of the cores, and completely not influencing the forwarding of normal flow.
Further, only one core in the kernel mode may be used to run traffic threads, for example, the CPU4 in the asynchronous multi-core processor 10, in which case, the CPU4 polls and processes (handle number, memory pool type) passed by each user mode core, and performs statistics on the traffic in the current statistical period based on the read information. Therefore, only one traffic thread exists, so that the problem of resource competition among multiple cores does not exist, and the kernel mode access operation can be free from competition on the whole. Moreover, the traffic table can avoid the problem of system crash caused by access failure of the kernel core memory due to session deletion, and the robustness of the function is ensured.
Compared with the prior art that the whole session resource needs to be transmitted between the kernel mode and the user mode when flow statistics is carried out, the embodiment of the disclosure only needs to transmit the handle number of the session table entry or the handle number of the traffic table entry between the user mode and the kernel mode, thereby greatly reducing the number of bytes transmitted by the message, removing most of the burden in the flow statistics process, and improving the overall processing efficiency. And the design of the session table and the message transmission address (such as ring) avoids resource competition among multiple cores, and ensures that multiple cores are not interfered with each other, so that the performance of the multi-core processor can be increased linearly along with the increase of the cores, and the overall performance of the multi-core processor is further improved.
The embodiment of the present disclosure further provides a user mode core 40, as shown in fig. 5, the user mode core 40 includes:
a writing module 401, configured to write, for each session of the user mode core, index information of a session table entry corresponding to a session that generates traffic in each statistical period into a message passing address of the user mode core;
the user mode core is correspondingly provided with a message transmission address and a session table, the address of the session table and the message transmission address are stored in the shared memories of the user mode core and the kernel mode core, each session of the user mode core establishes a corresponding session table item in the session table, and the index information of the session table item is used for identifying the memory address of the session table item in the session table of the user mode core, so that the kernel mode core reads the flow information in the corresponding session table item for statistics based on the index information newly written in the message transmission address in the statistics period.
Optionally, the user mode core further includes a message parsing module 402, configured to parse a message of a session generating a flow, and determine whether the session is about to fail according to a session state in the message, where the writing module 401 is configured to, when the session state indicates that the session is valid, write a handle number and a session table type of a session table entry corresponding to the session into a message passing address of the user mode core;
the user mode core further includes a creating module 403, configured to create a new traffic table entry in a traffic table corresponding to the user mode core according to left and right keys of the session and flow information when the session state indicates that the session is about to fail, where the writing module 401 is configured to write a handle number and a traffic table type of the new traffic table entry into a message passing address of the user mode core, where an address storing the traffic table is a shared memory of the user mode core and the kernel mode core.
Optionally, the creating module 403 is configured to:
and sequentially creating each traffic table entry, and adopting a replacement mechanism to sequentially replace the content of each created traffic table entry according to the sequence when the memory for storing the traffic table is full.
By adopting the user mode core, the session table in the multi-core processor is designed into a shared memory of the user mode core and the kernel mode core, so that the kernel mode core can directly read the session flow information from the session table entry. And the information transmission between the user mode core and the kernel mode core does not adopt a notification mechanism, the user mode core only needs to write the index information of the session generating the flow into the message transmission address, the kernel mode core running the traffic thread can read the index information from the message transmission address and read the flow information from the corresponding session table entry according to the index information, compared with the notification mechanism that the user mode core needs to notify the kernel mode to receive the whole session resource in a system call mode, the technical scheme provided by the disclosure saves a large amount of message transmission contents and avoids the user mode core from initiating a large amount of system calls, thereby reducing the calculation amount consumption and improving the overall performance of the processor.
The embodiment of the present disclosure further provides a kernel mode core 50, as shown in fig. 6, the kernel mode core 50 includes:
a polling module 501, configured to poll a message passing address of each user mode core to obtain index information newly written in the message passing address in each statistical period, where the index information is used to identify a memory address, in a session table, of a session entry corresponding to a session that generates traffic in the statistical period, where the address for storing the session table and the message passing address both belong to a shared memory of the user mode core and the kernel mode core;
and a traffic statistics module 502, configured to read traffic information in a corresponding session entry according to the index information to perform traffic statistics.
Optionally, the traffic statistic module 502 is configured to:
when the index information comprises the type of a session table and a handle number of a session table item, counting flow information recorded in the session table item identified by the handle number in the session table;
the traffic statistic module 502 is further configured to:
when the index information comprises a traffic table type and a handle number of a traffic table item, traffic information recorded in the traffic table item identified by the handle number is counted in the traffic table, wherein the traffic table item is created in the traffic table of the user mode core according to left and right keys of the session and the traffic information when the user mode core determines that the session is invalid in the next counting period.
It is obvious to those skilled in the art that, for convenience and simplicity of description, the foregoing division of the functional modules is merely used as an example, and in practical applications, the above function distribution may be performed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to perform all or part of the above described functions. For the specific working process of the functional module, reference may be made to the corresponding process in the foregoing method embodiment, which is not described herein again.
The embodiments of the present disclosure also provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the steps of a session traffic statistical method provided by the foregoing method embodiments.
The embodiment of the disclosure also provides an electronic device, which includes a first computer-readable storage medium, a user mode core, a second computer-readable storage medium, and a kernel mode core.
The user mode core implements the session traffic statistical method of the user mode core side when executing the computer program stored in the first computer readable storage medium, and the kernel mode core implements the session traffic statistical method of the kernel mode core side when executing the computer program stored in the second computer readable storage medium.
The preferred embodiments of the present disclosure are described in detail with reference to the accompanying drawings, however, the present disclosure is not limited to the specific details of the above embodiments, and various simple modifications may be made to the technical solution of the present disclosure within the technical idea of the present disclosure, and these simple modifications all belong to the protection scope of the present disclosure.
It should be noted that, in the foregoing embodiments, various features described in the above embodiments may be combined in any suitable manner, and in order to avoid unnecessary repetition, various combinations that are possible in the present disclosure are not described again.
In addition, any combination of various embodiments of the present disclosure may be made, and the same should be considered as the disclosure of the present disclosure, as long as it does not depart from the spirit of the present disclosure.
Claims (14)
1. A session flow statistical method is characterized in that the method is applied to any user mode core in a multi-core processor, each user mode core is correspondingly provided with a session table, each session of the user mode core is provided with a corresponding session table item in the session table, and the method comprises the following steps:
aiming at each conversation of the user mode core, writing index information of a conversation table item corresponding to the conversation generating flow in each statistical period into a message transmission address of the user mode core;
the address for storing the session table and the message passing address both belong to a shared memory of a user mode core and a kernel mode core, and the index information of the session table entry is used for identifying the memory address of the session table entry in the session table of the user mode core, so that the kernel mode core reads the flow information in the corresponding session table entry for statistics based on the index information in the message passing address.
2. The method of claim 1, wherein writing the index information of the session table entry corresponding to the session generating traffic in each statistical period into the messaging address of the user mode core comprises:
analyzing a message of a session generating flow, and determining whether the session is about to fail according to a session state in the message;
when the session state indicates that the session is kept effective, writing the handle number and the session table type of the session table item corresponding to the session into the message transfer address of the user state core;
the method further comprises the following steps:
when the session state indicates that the session is about to fail, creating a new traffic table entry in a traffic table corresponding to the user mode core according to left and right keys of the session and flow information, and writing a handle number and a traffic table type of the new traffic table entry into a message transfer address of the user mode core, wherein the address for storing the traffic table belongs to a shared memory of the user mode core and the kernel mode core.
3. The method according to claim 2, wherein the creating a new traffic entry in the traffic table corresponding to the user mode core according to the left and right keys of the session and the traffic information includes:
and sequentially creating each traffic table entry, and adopting a replacement mechanism to sequentially replace the content of each created traffic table entry according to the sequence when the memory for storing the traffic table is full.
4. The method according to any one of claims 1 to 3, wherein writing content in the messaging address corresponding to the user mode core is in a form of a consistent hash ring.
5. A session traffic statistical method is applied to a kernel-mode core in a multi-core processor, and comprises the following steps:
polling the message transmission address of each user mode core to obtain index information newly written in the message transmission address in each statistical period, wherein the index information is used for identifying the memory address of a session table item corresponding to a session generating flow in the statistical period in a session table, and the address for storing the session table and the message transmission address both belong to the shared memory of the user mode core and the kernel mode core;
and reading the flow information in the corresponding session table entry according to the index information to carry out flow statistics.
6. The method according to claim 5, wherein the reading the traffic information in the corresponding session table entry according to the index information for performing traffic statistics includes:
when the index information comprises the type of a session table and a handle number of a session table item, counting flow information recorded in the session table item identified by the handle number in the session table;
the method further comprises the following steps:
when the index information comprises a traffic table type and a handle number of a traffic table item, traffic information recorded in the traffic table item identified by the handle number is counted in the traffic table, wherein the traffic table item is created in the traffic table of the user mode core according to left and right keys of the session and the traffic information when the user mode core determines that the session is invalid in the next counting period.
7. The method according to claim 5 or 6, wherein polling the messaging address corresponding to the user mode core is performed by using a consistent hash ring.
8. A user mode core, comprising:
a write-in module, configured to write, for each session of the user mode core, index information of a session table entry corresponding to a session that generates traffic in each statistical period into a message passing address of the user mode core;
the user mode core is correspondingly provided with a session table, addresses for storing the session table and the message transmission addresses both belong to the shared memories of the user mode core and the kernel mode core, each session of the user mode core establishes a corresponding session table item in the session table, and index information of the session table item is used for identifying the memory address of the session table item in the session table of the user mode core, so that the kernel mode core reads flow information in the corresponding session table item for statistics based on the index information in the message transmission addresses.
9. The user mode core according to claim 8, wherein the user mode core further includes a message parsing module configured to parse a message of a session that generates a flow, and determine whether the session is about to fail according to a session state in the message, and the writing module is configured to, when the session state indicates that the session is valid, write a handle number and a session table type of a session table entry corresponding to the session into a message passing address of the user mode core;
the user mode core further comprises a creating module, configured to create a new traffic table entry in a traffic table corresponding to the user mode core according to left and right keys of the session and flow information when the session state indicates that the session is about to fail, where the writing module is configured to write a handle number and a traffic table type of the new traffic table entry into a message passing address of the user mode core, where an address storing the traffic table is a shared memory of the user mode core and the kernel mode core.
10. The user mode core of claim 9, wherein the creation module is configured to:
and sequentially creating each traffic table entry, and adopting a replacement mechanism to sequentially replace the content of each created traffic table entry according to the sequence when the memory for storing the traffic table is full.
11. A kernel-mode core, comprising:
a polling module, configured to poll a message passing address of each user mode core to obtain index information newly written in the message passing address in each statistical period, where the index information is used to identify a memory address, in a session table, of a session entry corresponding to a session that generates traffic in the statistical period, where an address for storing the session table and the message passing address both belong to a shared memory of the user mode core and the kernel mode core;
and the flow counting module is used for reading the flow information in the corresponding session table entry according to the index information to carry out flow counting.
12. The kernel mode core of claim 11, wherein the traffic statistics module is to:
when the index information comprises the type of a session table and a handle number of a session table item, counting flow information recorded in the session table item identified by the handle number in the session table;
the flow statistics module is further configured to:
when the index information comprises a traffic table type and a handle number of a traffic table item, traffic information recorded in the traffic table item identified by the handle number is counted in the traffic table, wherein the traffic table item is created in the traffic table of the user mode core according to left and right keys of the session and the traffic information when the user mode core determines that the session is invalid in the next counting period.
13. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 7.
14. An electronic device comprising a first computer-readable storage medium, a user-mode core, a second computer-readable storage medium, a kernel-mode core;
wherein the user-mode kernel, when executing a computer program stored on the first computer-readable storage medium, implements the steps of the method of claim 1;
the kernel-mode core, when executing the computer program stored on the second computer-readable storage medium, implements the steps of the method of claim 5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810237054.8A CN108521351B (en) | 2018-03-21 | 2018-03-21 | Session flow statistical method, processor core, storage medium and electronic device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810237054.8A CN108521351B (en) | 2018-03-21 | 2018-03-21 | Session flow statistical method, processor core, storage medium and electronic device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108521351A CN108521351A (en) | 2018-09-11 |
CN108521351B true CN108521351B (en) | 2021-02-05 |
Family
ID=63433886
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810237054.8A Active CN108521351B (en) | 2018-03-21 | 2018-03-21 | Session flow statistical method, processor core, storage medium and electronic device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108521351B (en) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112714021B (en) * | 2020-12-29 | 2023-04-18 | 北京格林威尔科技发展有限公司 | Method and device for obtaining flow statistical result in optical transport network based on packet network |
CN116471194A (en) * | 2022-01-12 | 2023-07-21 | 华为技术有限公司 | Stream statistics method, device and system |
Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7363353B2 (en) * | 2001-07-06 | 2008-04-22 | Juniper Networks, Inc. | Content service aggregation device for a data center |
CN101178694A (en) * | 2006-11-07 | 2008-05-14 | 莱克斯信息技术(北京)有限公司 | Intel e1000 zero copy method |
US8127290B2 (en) * | 2007-06-22 | 2012-02-28 | Red Hat, Inc. | Method and system for direct insertion of a virtual machine driver |
CN102541461A (en) * | 2010-12-31 | 2012-07-04 | 阿里巴巴集团控股有限公司 | Data reading-writing method and device for remote data storage and system thereof |
US8539570B2 (en) * | 2007-06-22 | 2013-09-17 | Red Hat, Inc. | Method for managing a virtual machine |
CN103729329A (en) * | 2012-10-12 | 2014-04-16 | 深圳市中兴微电子技术有限公司 | ICN device and method |
CN104753711A (en) * | 2013-12-31 | 2015-07-01 | 华为技术有限公司 | Method and device for adjusting resource allocation of network equipment |
CN105763437A (en) * | 2014-12-17 | 2016-07-13 | 中兴通讯股份有限公司 | Message forwarding method and network equipment |
CN106713185A (en) * | 2016-12-06 | 2017-05-24 | 瑞斯康达科技发展股份有限公司 | Load balancing method and apparatus of multi-core CPU |
CN106789617A (en) * | 2016-12-22 | 2017-05-31 | 东软集团股份有限公司 | A kind of message forwarding method and device |
CN107046508A (en) * | 2016-02-05 | 2017-08-15 | 华为技术有限公司 | Message method of reseptance and the network equipment |
-
2018
- 2018-03-21 CN CN201810237054.8A patent/CN108521351B/en active Active
Patent Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7363353B2 (en) * | 2001-07-06 | 2008-04-22 | Juniper Networks, Inc. | Content service aggregation device for a data center |
CN101178694A (en) * | 2006-11-07 | 2008-05-14 | 莱克斯信息技术(北京)有限公司 | Intel e1000 zero copy method |
US8127290B2 (en) * | 2007-06-22 | 2012-02-28 | Red Hat, Inc. | Method and system for direct insertion of a virtual machine driver |
US8539570B2 (en) * | 2007-06-22 | 2013-09-17 | Red Hat, Inc. | Method for managing a virtual machine |
CN102541461A (en) * | 2010-12-31 | 2012-07-04 | 阿里巴巴集团控股有限公司 | Data reading-writing method and device for remote data storage and system thereof |
CN103729329A (en) * | 2012-10-12 | 2014-04-16 | 深圳市中兴微电子技术有限公司 | ICN device and method |
CN104753711A (en) * | 2013-12-31 | 2015-07-01 | 华为技术有限公司 | Method and device for adjusting resource allocation of network equipment |
CN105763437A (en) * | 2014-12-17 | 2016-07-13 | 中兴通讯股份有限公司 | Message forwarding method and network equipment |
CN107046508A (en) * | 2016-02-05 | 2017-08-15 | 华为技术有限公司 | Message method of reseptance and the network equipment |
CN106713185A (en) * | 2016-12-06 | 2017-05-24 | 瑞斯康达科技发展股份有限公司 | Load balancing method and apparatus of multi-core CPU |
CN106789617A (en) * | 2016-12-22 | 2017-05-31 | 东软集团股份有限公司 | A kind of message forwarding method and device |
Also Published As
Publication number | Publication date |
---|---|
CN108521351A (en) | 2018-09-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9736034B2 (en) | System and method for small batching processing of usage requests | |
US9996403B2 (en) | System and method for providing message queues for multinode applications in a middleware machine environment | |
US20130160028A1 (en) | Method and apparatus for low latency communication and synchronization for multi-thread applications | |
CN108319496B (en) | Resource access method, service server, distributed system and storage medium | |
US10331499B2 (en) | Method, apparatus, and chip for implementing mutually-exclusive operation of multiple threads | |
CN113110916B (en) | Virtual machine data reading and writing method, device, equipment and medium | |
CN111190854B (en) | Communication data processing method, device, equipment, system and storage medium | |
CN108521351B (en) | Session flow statistical method, processor core, storage medium and electronic device | |
CN111897666A (en) | Method, device and system for communication among multiple processes | |
US11868799B2 (en) | Command information transmission method, system, and apparatus, and readable storage medium | |
CN110740145A (en) | Message consumption method, device, storage medium and electronic equipment | |
CN111416825A (en) | Inter-thread lock-free log management method and system, terminal and storage medium | |
CN114640716A (en) | Cloud network cache acceleration system and method based on fast network path | |
CN113220535A (en) | Method, device and equipment for processing program exception and storage medium | |
CN109831394B (en) | Data processing method, terminal and computer storage medium | |
CN116820527B (en) | Program upgrading method, device, computer equipment and storage medium | |
CN117370046A (en) | Inter-process communication method, system, device and storage medium | |
CN111221642B (en) | Data processing method, device, storage medium and terminal | |
US9841992B2 (en) | Information processing device, information processing system, and interrupt device control method | |
US8719499B2 (en) | Cache-line based notification | |
US20130046910A1 (en) | Method for managing a processor, lock contention management apparatus, and computer system | |
CN114138371B (en) | Configuration dynamic loading method and device, computer equipment and storage medium | |
CN109634721B (en) | Method and related device for starting communication between virtual machine and host | |
KR102125791B1 (en) | Method and apparatus for managing network session in multi-core environment | |
EP4339776A1 (en) | Task scheduling method, system, and hardware task scheduler |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |