Large-scale network session rapid multiplexing method, device, equipment, medium and program product
In high concurrency network scenarios, the network session pool and idle queue are managed using a mechanism combining dynamic arrays and idle coordinates to achieve O(1) time multiplexing network sessions, solving the problem of rapid detection and multiplexing of idle network sessions, and improving network processing performance.
Patent Information
- Application Number
- CN202411776389.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-03-07
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In high concurrent network scenarios, how to quickly detect and reuse idle network sessions to improve network processing performance.
Using a mechanism combining dynamic arrays and idle coordinates, the network session is stored and managed through session_pool and session_freequeue, and the O(1) time complexity is achieved quickly retrieval and multiplexed.
Regardless of the network connection scale, multiplexing of network sessions can be completed within O(1) time complexity, significantly improving network processing performance.
Smart Images

Figure CN119583621A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network communication technology, and in particular to a method, device, equipment, medium and program product for rapid multiplexing of large-scale network sessions. Background Art
[0002] Network function is one of the indispensable basic functions of many products today, especially for service network products, or equipment deployed in the user's network environment, which has high requirements for network communication performance to avoid large-scale network connection processing not being timely and affecting user business.
[0003] In order to improve the network service capabilities of the product, many technologies such as asynchronous I / O, thread pools, and coroutines are used to meet the high-concurrency access requirements of hundreds of thousands, millions, or even larger network connections. In this process, specific network connections are generally identified by network sessions, and a pooling mechanism is used to implement network session reuse. That is, when a new network connection is initiated as a client, or when a new network connection is accepted as a server, a new network session is applied for the corresponding connection, and the network session is not destroyed when the service is completed and the network connection is disconnected. Instead, it is put into the free pool for recycling, and the network session in the free pool is reused when a new network connection is established, thereby avoiding frequent application and destruction of network session resources in high-concurrency network scenarios, which affects system processing performance.
[0004] In a high-concurrency network scenario, hundreds of thousands or even millions of network connections are processed per second, or even larger. When a network program starts running, network sessions will reach a peak after continuous application in a short period of time. If no new network connections are connected, network sessions will not increase, but the current recycled network sessions will be reused. The corresponding network session management mechanism is as follows: Figure 1 As shown. Under this mechanism, idle sessions are generally recycled and reused through network session management; therefore, how to quickly detect whether there are idle network sessions and reuse them affects the network processing capacity. Summary of the invention
[0005] The present invention aims to provide a method, device, equipment, medium and program product for rapid reuse of large-scale network sessions, so as to achieve rapid detection of whether there are idle network sessions and reuse them within the time complexity of O(1) regardless of the scale of the corresponding network sessions, thereby significantly improving the network processing performance of the product.
[0006] In a first aspect, the present invention provides a method for rapid multiplexing of large-scale network sessions, comprising:
[0007] Define session as the network session pointer, session_pool as the network session pool, session_index as the network session index and session_freequeue as the network session free queue;
[0008] Based on the definition, a mechanism combining a dynamic array with free coordinates is adopted to sequentially store and quickly retrieve network sessions according to array coordinates.
[0009] In some embodiments, the mechanism of using a dynamic array combined with free coordinates to sequentially store and quickly retrieve network sessions according to array coordinates includes:
[0010] The session_pool uses a dynamic array to store all sessions. Each new session uses the total number of sessions in the current session_pool to identify the session_index, and puts the new session at the end of the session_pool, which corresponds to the subscript position index of the new session in the session_pool.
[0011] The session_freequeue stores the session_index of the idle session. If the session_freequeue is not empty, it means that there is an idle session. At this time, the available session_index is obtained from the session_freequeue header, and the session corresponding to the session_pool index is associated for reuse. Then the session_index at the session_freequeue header is removed, and when the session completes business processing and is recycled, it is put back to the end of the session_freequeue.
[0012] In some embodiments, session_freequeue uses a FIFO queue to store the session_index of the idle session.
[0013] In a second aspect, the present invention further provides a large-scale network session fast multiplexing device, comprising:
[0014] The first processing module is used to define session as a network session pointer, session_pool as a network session pool, session_index as a network session index and session_freequeue as a network session free queue;
[0015] The second processing module is used to store and quickly retrieve network sessions in sequence according to array coordinates by adopting a mechanism combining a dynamic array with idle coordinates based on the definition.
[0016] In some embodiments, the second processing module is specifically configured to:
[0017] The session_pool uses a dynamic array to store all sessions. Each new session uses the total number of sessions in the current session_pool to identify the session_index, and puts the new session at the end of the session_pool, which corresponds to the subscript position index of the new session in the session_pool.
[0018] The session_freequeue stores the session_index of the idle session. If the session_freequeue is not empty, it means that there is an idle session. At this time, the available session_index is obtained from the session_freequeue header, and the session corresponding to the session_pool index is associated for reuse. Then the session_index at the session_freequeue header is removed, and when the session completes business processing and is recycled, it is put back to the end of the session_freequeue.
[0019] In some embodiments, in the second processing module, session_freequeue uses a FIFO queue to store the session_index of the idle session.
[0020] In a third aspect, the present invention further provides an electronic device, comprising:
[0021] at least one processor; and a memory communicatively coupled to the at least one processor;
[0022] The memory stores instructions that can be executed by the at least one processor, and the at least one processor executes the instructions stored in the memory, so that the at least one processor performs the method.
[0023] In a fourth aspect, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store instructions, and when the instructions are executed, the above method is implemented.
[0024] In a fifth aspect, the present invention further provides a computer program product, which, when called by a computer, enables the computer to execute the above method.
[0025] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are:
[0026] 1. In the present invention, regardless of the scale of the network connection, the multiplexing operation of the network session can be completed within the time complexity of O(1), and has high performance.
[0027] 2. Different development languages in the present invention can be implemented based on this method and have universality.
[0028] 3. The method of the present invention can be quickly reused for other similar needs that require rapid storage and retrieval, thereby achieving the reuse of existing work results. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 Schematic diagram of network session management mechanism.
[0030] Figure 2 The present invention is a logical diagram of a method for rapidly reusing large-scale network sessions according to an embodiment of the present invention.
[0031] Figure 3 A structural schematic diagram of an electronic device is provided for an embodiment of the present invention. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0033] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0034] The embodiment of the present invention provides a method for rapid multiplexing of large-scale network sessions, including:
[0035] First, define session, session_pool, session_index, and session_freequeue as follows:
[0036] Session is a network session pointer, which represents a network session, corresponds one-to-one with an actual network connection, and stores data context information related to the actual network connection.
[0037] session_pool is the network session pool, which stores all the sessions in use and idle.
[0038] session_index is the network session index, which is a property of session and stores the subscript position index of the current session in session_pool for quick retrieval.
[0039] session_freequeue is the network session idle queue, which stores the session_index of all idle sessions.
[0040] Then, based on the above definition, a mechanism combining dynamic array and free coordinates is adopted to store and quickly retrieve network sessions in sequence according to array coordinates. Figure 2 As shown, session_pool uses a dynamic array to store all sessions. Each newly created session uses the total number of sessions in the current session_pool to identify the session_index, and puts the newly created session at the end of the session_pool, which corresponds to the index of the newly created session in the session_pool. The session_freequeue uses a FIFO queue (First Input First Output) to store the session_index of idle sessions. If the session_freequeue is not empty, it means that there is an idle session. At this time, the available session_index is obtained from the head of the session_freequeue, and the session corresponding to the session_pool index is associated for reuse. Then the session_index at the head of the session_freequeue is removed, and when the session is recycled after completing the business processing, it is put back to the end of the session_freequeue.
[0041] In the initial situation, the network session related data status is as follows:
[0042] 1) The session_pool is empty and does not contain any session elements.
[0043] 2)session_freequeue is empty and there is no free session_index.
[0044] 3)session_index is 0 because session_pool is empty.
[0045] When the peak number of concurrent network connections is N, the state of network session-related data is as follows:
[0046] 1)session_pool is not empty and stores N session elements.
[0047] 2) The number of session_index in session_freequeue does not exceed N, and they are reused in a cyclic manner in the first-in-first-out order.
[0048] 3) The maximum value of session_index is N-1, where 0 represents the first session element in session_pool and N-1 represents the Nth session element in session_pool.
[0049] In the above process, if the C++ development language is used for implementation, the vector container can be used to represent the dynamic array, and the queue container can be used to represent the session_freequeue. The time complexity of the vector container for random access to array elements and adding new elements is O(1), and the time complexity of the queue container for detecting empty elements, adding elements, getting the head element, and deleting the head element is also O(1). Therefore, it can be said that in the process of rapid reuse of network sessions, regardless of the scale of concurrent network connections, the overall time complexity is O(1).
[0050] Based on the same technical concept, the embodiment of the present application also provides a large-scale network session fast multiplexing device, including:
[0051] The first processing module is used to define session as a network session pointer, session_pool as a network session pool, session_index as a network session index and session_freequeue as a network session free queue;
[0052] The second processing module is used to store and quickly retrieve network sessions in sequence according to array coordinates by adopting a mechanism combining a dynamic array with idle coordinates based on the definition.
[0053] As for the specific processing methods of each processing module in the above-mentioned device, reference can be made to the specific description of the above-mentioned method, which will not be repeated here.
[0054] Based on the same technical concept, the embodiment of the present application also provides an electronic device, which can implement the large-scale network session fast multiplexing method provided in the above embodiment of the present application. In one embodiment, the electronic device can be a server, or a terminal device or other electronic device. Figure 3As shown, the electronic device may include:
[0055] At least one processor, and a memory connected to the at least one processor. The specific connection medium between the processor and the memory is not limited in the embodiment of the present application. Figure 3 The example in this article is that the processor and memory are connected through a bus. Figure 3 The connections between other components are shown in bold lines, which are only for illustration and are not intended to be limiting. The bus can be divided into address bus, data bus, control bus, etc. Figure 3 In the diagram, only one thick line is used, but this does not mean that there is only one bus or only one type of bus. Alternatively, a processor can also be called a controller, and there is no limitation on the name.
[0056] In the embodiment of the present application, the memory stores instructions that can be executed by at least one processor, and the at least one processor can execute a large-scale network session fast multiplexing method discussed above by executing the instructions stored in the memory. The processor can implement Figure 3 The functions of each module in the device shown.
[0057] Among them, the processor is the control center of the device, which can use various interfaces and lines to connect the various parts of the entire control device, and monitor the device as a whole by running or executing instructions stored in the memory and calling data stored in the memory, various functions of the device and processing data.
[0058] In an optional design, the processor may include one or more processing units, and the processor may integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the modem processor may not be integrated into the processor. In some embodiments, the processor and the memory may be implemented on the same chip, and in some embodiments, they may also be implemented separately on separate chips.
[0059] The processor may be a general-purpose processor, such as a CPU, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of a large-scale network session rapid multiplexing method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0060] As a non-volatile computer-readable storage medium, the memory can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory can include at least one type of storage medium, for example, it can include flash memory, hard disk, multimedia card, card-type memory, random access memory (Random Access Memory, RAM), static random access memory (Static Random Access Memory, SRAM), programmable read-only memory (Programmable Read Only Memory, PROM), read-only memory (Read Only Memory, ROM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), magnetic memory, disk, CD, etc. The memory is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0061] By designing and programming the processor, the code corresponding to the large-scale network session fast multiplexing method described in the above embodiment can be fixed into the chip, so that the chip can perform the steps of the large-scale network session fast multiplexing method in the above embodiment when running. How to design and program the processor is a technology well known to those skilled in the art and will not be described here.
[0062] Based on the same inventive concept, an embodiment of the present application also provides a storage medium, which stores computer instructions. When the computer instructions are executed on a computer, the computer executes a large-scale network session rapid multiplexing method discussed above.
[0063] In some optional embodiments, the present application also provides various aspects of a method for rapid multiplexing of large-scale network sessions, which can also be implemented in the form of a program product, which includes program code. When the program product is run on an apparatus, the program code is used to enable the control device to execute the steps of a method for rapid multiplexing of large-scale network sessions according to various exemplary embodiments of the present application described above in this specification.
[0064] It should be noted that, although several units or subunits of the device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units described above can be embodied in one unit. Conversely, the features and functions of a unit described above can be further divided into multiple units to be embodied. In addition, although the operation of the method of the present application is described in a specific order in the accompanying drawings, this does not require or imply that these operations must be performed in this specific order, or that all the operations shown must be performed to achieve the desired result. Additionally or alternatively, some steps can be omitted, multiple steps can be combined into one step for execution, and / or one step can be decomposed into multiple steps for execution.
[0065] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0066] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a server, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the process in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0067] Program code for performing the operations of the present application may be written using any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a stand-alone software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0068] Where a remote computing device is involved, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0069] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0070] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0071] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for rapid multiplexing of large-scale network sessions, characterized in that: include: Define session as the network session pointer, session_pool as the network session pool, session_index as the network session index and session_freequeue as the network session free queue; Based on the definition, a mechanism combining a dynamic array with free coordinates is adopted to sequentially store and quickly retrieve network sessions according to array coordinates.
2. The large-scale network session rapid multiplexing method according to claim 1, characterized in that: The mechanism of combining a dynamic array with idle coordinates to sequentially store and quickly retrieve network sessions according to array coordinates includes: The session_pool uses a dynamic array to store all sessions. Each new session uses the total number of sessions in the current session_pool to identify the session_index, and puts the new session at the end of the session_pool, which corresponds to the subscript position index of the new session in the session_pool. The session_freequeue stores the session_index of the idle session. If the session_freequeue is not empty, it means that there is an idle session. At this time, the available session_index is obtained from the session_freequeue header, and the session corresponding to the session_pool index is associated for reuse. Then the session_index at the session_freequeue header is removed, and when the session completes business processing and is recycled, it is put back to the end of the session_freequeue.
3. The large-scale network session rapid multiplexing method according to claim 1, characterized in that: session_freequeue uses FIFO queue to store session_index of idle session.
4. A large-scale network session rapid multiplexing device, characterized in that: include: The first processing module is used to define session as a network session pointer, session_pool as a network session pool, session_index as a network session index and session_freequeue as a network session free queue; The second processing module is used to store and quickly retrieve network sessions in sequence according to array coordinates by adopting a mechanism combining a dynamic array with idle coordinates based on the definition.
5. The large-scale network session rapid multiplexing device according to claim 4, characterized in that: The second processing module is specifically used for: The session_pool uses a dynamic array to store all sessions. Each new session uses the total number of sessions in the current session_pool to identify the session_index, and puts the new session at the end of the session_pool, which corresponds to the subscript position index of the new session in the session_pool. The session_freequeue stores the session_index of the idle session. If the session_freequeue is not empty, it means that there is an idle session. At this time, the available session_index is obtained from the session_freequeue header, and the session corresponding to the session_pool index is associated for reuse. Then the session_index at the session_freequeue header is removed, and when the session completes business processing and is recycled, it is put back to the end of the session_freequeue.
6. The large-scale network session rapid multiplexing device according to claim 5, characterized in that: In the second processing module, session_freequeue uses a FIFO queue to store the session_index of the idle session.
7. An electronic device, characterized in that: include: at least one processor; and a memory communicatively coupled to the at least one processor; The memory stores instructions that can be executed by the at least one processor, and the at least one processor executes the method as described in any one of claims 1 to 3 by executing the instructions stored in the memory.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store instructions, and when the instructions are executed, the method according to any one of claims 1 to 3 is implemented.
9. A computer program product, characterized in that When the computer program product is called by a computer, the computer executes the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Session retrieval method and device, equipment and computer readable storage medium
CN113596098A
Session management method and device, electronic equipment and storage medium
CN117992233A
Data structure supporting session timer and variable aging function including self adjustable 2MSL
US20050050018A1
Data structure supporting random delete and aging / timer function
US20050050188A1
Recycling items in a network device
US7716380B1
