TCP connection management method, device, electronic device, storage medium and program product
By setting timing policies based on preset events and polling the TCP connection channel, and managing the information of the client and TCP connection channel, the existing TCP connection management method has solved the problem of low management efficiency in dynamic network environments, and more efficient TCP connection status detection and resource allocation are achieved.
Patent Information
- Application Number
- CN202411555445.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-04
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2044-11-04
AI Technical Summary
The existing TCP connection management methods are difficult to quickly respond to sudden changes in network conditions or load changes in load in dynamic network environments, resulting in low management efficiency.
By setting a timing policy based on the event content of the preset event, polling and listening for whether a preset event occurs on the TCP connection channel, and managing the key-value pairs composed of client identification information and the connection information of the TCP connection channel.
It realizes accurate identification and detection of TCP connection status, improves the efficiency of TCP connection management, and can better dynamically allocate resources and adapt to changes in the network environment.
Smart Images

Figure CN119052310B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a TCP connection management method, device, electronic equipment, storage medium and program product. Background Art
[0002] The Transmission Control Protocol (TCP) is a reliable, byte-stream-based communication protocol for multi-device interconnection. Its main function is to establish a stable data transmission connection between two computers, ensuring the sequential transmission of data packets, data integrity, and error detection and recovery. When network communication uses the TCP / IP protocol, a TCP connection needs to be established between the client and the server before reading and writing operations, and the TCP connection is released after the reading and writing operations are completed.
[0003] TCP connections require a timeout heartbeat mechanism to detect whether the connection is still active. The heartbeat mechanism is to confirm that the connection is still valid and active by sending signals (usually empty messages or specific probe packets) at regular intervals. The timeout mechanism means that if no heartbeat signal or any data is received within a specified time, the system will consider the connection to be invalid. However, the existing TCP connection management method uses the same timeout heartbeat mechanism to manage different operation events, making it difficult to quickly respond to sudden changes in network conditions or changes in load in a dynamic network environment, resulting in low management efficiency. Summary of the invention
[0004] The present invention is intended to provide a TCP connection management method, device, electronic device, storage medium and program product to solve the deficiencies in the prior art. The technical problem to be solved by the present invention is achieved through the following technical solutions.
[0005] According to a first aspect of the present disclosure, a TCP connection management method is provided, the method comprising:
[0006] According to the event content of the preset event, a timing strategy matching the preset event is set, wherein the preset event includes any one of the following: no data read operation on the Transmission Control Protocol TCP connection channel between the client and the server, no data write operation on the TCP connection channel, no data read operation and no data write operation on the TCP connection channel;
[0007] According to a timing strategy matching the preset event, polling and monitoring whether the preset event occurs on the TCP connection channel;
[0008] According to the monitoring situation, the TCP connection channel is managed based on a key value composed of identification information of the client and connection information of the TCP connection channel, wherein the identification information of the client includes any one of the following: an Internet Protocol IP address of the client or a port number of the client, and the connection information of the TCP connection channel includes at least one of the following: identification information of the TCP connection channel, connection status of the TCP connection channel, most recent activity timestamp of the TCP connection channel, and data transmission volume of the TCP connection channel.
[0009] Furthermore, before setting a timing strategy matching the preset event according to the event content of the preset event, the method further includes:
[0010] Get the TCP connection request sent by the client;
[0011] Based on the TCP connection request, establishing a TCP connection channel between the client and the server;
[0012] After the TCP connection channel is established, a key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel is stored in a database.
[0013] Further, managing the TCP connection channel based on a key value consisting of identification information of the TCP connection channel and connection information of the TCP connection channel according to the monitoring situation includes:
[0014] When the preset event occurs on the TCP connection channel, disconnect the TCP connection channel;
[0015] After disconnecting the TCP connection channel, the key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel is deleted from the database.
[0016] Furthermore, after storing the key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel in the database, the method further includes:
[0017] Get the resource capacity of the server;
[0018] Calculate the maximum number of TCP connection channels that the server can connect to based on the resource capacity;
[0019] Determine a threshold value of the number of TCP connection channels to which the client can connect based on the maximum number of TCP connection channels and usage information of the client;
[0020] Querying the number of key-value pairs corresponding to the client in a database according to the identification information of the client;
[0021] When the number of key-value pairs corresponding to the client is greater than the TCP connection channel number threshold, the client is restricted from establishing a new TCP connection channel with the server.
[0022] Further, the polling and monitoring whether the preset event occurs on the TCP connection channel according to the timing strategy matching the preset event includes:
[0023] Obtaining the timestamp of the most recent data reading operation and / or data writing operation on the TCP connection channel according to the listening time interval matching the preset event;
[0024] Calculate the difference between the timestamp of the most recent data read operation and / or data write operation on the TCP connection channel and the current timestamp;
[0025] The difference is compared with the idle time threshold matching the preset event to determine whether the preset event occurs on the TCP connection channel.
[0026] According to a second aspect of the present disclosure, a TCP connection management device is provided, the device comprising:
[0027] A first setting module is used to set a timing strategy matching a preset event according to the event content of the preset event, wherein the preset event includes any one of the following: no data read operation on the transmission control protocol TCP connection channel between the client and the server, no data write operation on the TCP connection channel, no data read operation and no data write operation on the TCP connection channel;
[0028] A first monitoring module, configured to poll and monitor whether the preset event occurs on the TCP connection channel according to a timing strategy matching the preset event;
[0029] The first management module is used to manage the TCP connection channel based on a key value composed of the identification information of the client and the connection information of the TCP connection channel according to the monitoring situation, wherein the identification information of the client includes any one of the following: the Internet Protocol IP address of the client or the port number of the client, and the connection information of the TCP connection channel includes at least one of the following: the identification information of the TCP connection channel, the connection state of the TCP connection channel, the most recent activity timestamp of the TCP connection channel, and the data transmission volume of the TCP connection channel.
[0030] According to a third aspect of the present disclosure, an electronic device is provided. The electronic device includes: a memory and a processor, wherein a computer program is stored in the memory, and the method is implemented when the processor executes the computer program.
[0031] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored, and the computer program implements the method when executed by a processor.
[0032] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising computer instructions, which implement the method when executed by a processor.
[0033] The embodiments of the present invention include the following advantages:
[0034] The TCP connection management method, device, electronic device, storage medium and program product provided by the embodiments of the present invention include setting a timing strategy matching the preset event according to the event content of the preset event, wherein the preset event includes any one of the following: no data read operation on the Transmission Control Protocol TCP connection channel between the client and the server, no data write operation on the TCP connection channel, no data read operation and no data write operation on the TCP connection channel; according to the timing strategy matching the preset event, polling and monitoring whether the preset event occurs on the TCP connection channel; according to the monitoring situation, managing the TCP connection channel based on a key value composed of the identification information of the client and the connection information of the TCP connection channel, wherein the identification information of the client includes any one of the following: the Internet Protocol IP address of the client or the port number of the client, and the connection information of the TCP connection channel includes at least one of the following: the identification information of the TCP connection channel, the connection status of the TCP connection channel, the most recent activity timestamp of the TCP connection channel, and the data transmission volume of the TCP connection channel. In the method, different timing strategies are set for different preset events, so that the connection status of the TCP connection channel can be accurately identified and detected, and the TCP connection channel is managed based on the connection status of the TCP connection channel through a key value pair composed of the identification information of the client and the connection information of the TCP connection channel, which can conveniently record the detailed information of each TCP connection channel. By analyzing the stored connection information, the system can better dynamically allocate resources, thereby improving the management efficiency of the TCP connection. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a flow chart of steps of an embodiment of a TCP connection management method of the present invention;
[0036] Figure 2It is a structural schematic diagram of an embodiment of a TCP connection management device of the present invention;
[0037] Figure 3 It is a structural schematic diagram of an electronic device of the present invention. DETAILED DESCRIPTION
[0038] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0039] Figure 1 A flowchart of a TCP connection management method 100 according to an embodiment of the present disclosure is shown. The TCP connection management method can be executed by a TCP connection management system. Specifically, the method 100 includes:
[0040] S101. According to the event content of a preset event, a timing strategy matching the preset event is set, wherein the preset event includes any one of the following: no data read operation on the Transmission Control Protocol TCP connection channel between the client and the server, no data write operation on the TCP connection channel, no data read operation and no data write operation on the TCP connection channel;
[0041] In this step, an event handler in the TCP connection management system can be defined to handle three types of events: no data read operation on the TCP connection channel between the client and the server, no data write operation on the TCP connection channel between the client and the server, and neither data read operation nor data write operation on the TCP channel between the client and the server.
[0042] The above events can be used to detect the status and activity of the TCP connection channel between the client and the server.
[0043] Different operations (data reading, data writing, or simultaneous data reading and writing) have different characteristics and resource requirements. For example, data reading may be a more passive wait, while data writing is usually more active and frequent. The same timeout heartbeat strategy cannot effectively meet these different requirements, which may cause some connections to fail to detect the inactive state in time or misjudge the active state.
[0044] Therefore, in this step, different preset events are set with different timers, that is, different preset times are set with different timing strategies. According to the time interval set to match the preset event, the TCP connection management system will periodically check the TCP connection channel to detect whether a preset event has occurred on the TCP connection channel.
[0045] For example:
[0046] 1. Data read operations may sometimes be in a waiting state, that is, the client is waiting for data from the server. You can set a longer timeout because read operations may not be frequent. If a connection does not receive a data packet for a long time, you may need to send a heartbeat packet to detect the connection activity to ensure that both parties can still communicate.
[0047] 2. Data writing is usually an active operation, meaning that the client is constantly sending data to the server. A shorter timeout can be set because data writing is usually more frequent and stable. If there is a long period of inactivity during the writing process, it may indicate a problem that needs to be quickly detected and handled.
[0048] 3. Bidirectional communication with simultaneous data reading and writing means that the connection should always remain active, sending and receiving data at the same time. It is necessary to comprehensively consider the above two situations and flexibly adjust the timeout parameters to adapt to the dynamic changes of read and write synchronization.
[0049] S102, according to the timing strategy matching the preset event, polling and monitoring whether the preset event occurs on the TCP connection channel;
[0050] In some embodiments, the polling and monitoring whether the preset event occurs on the TCP connection channel according to the timing strategy matching the preset event includes:
[0051] Obtaining the timestamp of the most recent data reading operation and / or data writing operation on the TCP connection channel according to the listening time interval matching the preset event;
[0052] Calculate the difference between the timestamp of the most recent data read operation and / or data write operation on the TCP connection channel and the current timestamp;
[0053] The difference is compared with the idle time threshold matching the preset event to determine whether the preset event occurs on the TCP connection channel.
[0054] In the above embodiment, taking the data writing operation on the TCP connection channel as an example, the data reading operation on the TCP connection channel is checked according to the set listening time interval (such as listening once every 5 seconds), and then the difference between the timestamp of the most recent data reading operation on the TCP connection channel and the current timestamp is calculated. When the difference exceeds the preset space-time threshold, it means that no data writing operation has been performed on the TCP connection channel for a long time.
[0055] This embodiment can handle various possible situations in network communications more accurately and efficiently by matching different timing strategies to different preset events.
[0056] S103. According to the monitoring situation, the TCP connection channel is managed based on a key value composed of the identification information of the client and the connection information of the TCP connection channel, wherein the identification information of the client includes any one of the following: an Internet Protocol IP address of the client or a port number of the client, and the connection information of the TCP connection channel includes at least one of the following: the identification information of the TCP connection channel, the connection state of the TCP connection channel, the most recent activity timestamp of the TCP connection channel, and the data transmission volume of the TCP connection channel.
[0057] In this step, the connection manager in the TCP connection management system can manage the TCP connection channel through a key-value consisting of the identification information of the client and the connection information of the TCP connection channel. The identification information of the client can be the Internet Protocol (IP) address of the client or the port number of the client, and the connection information of the TCP connection channel can include at least one of the following: the identification information of the TCP connection channel, the connection state of the TCP connection channel, the most recent activity timestamp of the TCP connection channel, and the data transmission volume of the TCP connection channel.
[0058] Continuing with the example of monitoring data write operations on the TCP connection channel, if the TCP connection channel performs a data write operation within the preset idle time interval, the corresponding value is found according to the client's identification information (key), and the connection status of the TCP connection channel, the timestamp of the most recent data write operation, and the amount of data written are updated.
[0059] If the TCP connection channel has not performed any data writing operations for a long time, the corresponding value can be found based on the client's identification information (key) and deleted.
[0060] In some embodiments, before setting a timing strategy matching the preset event according to the event content of the preset event, the method further includes:
[0061] Get the TCP connection request sent by the client;
[0062] Based on the TCP connection request, establishing a TCP connection channel between the client and the server;
[0063] After the TCP connection channel is established, a key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel is stored in a database.
[0064] In the above embodiment, when a TCP connection channel is established between the client and the server, a key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel can be stored in the database. This makes it convenient to record the detailed information of each TCP connection. By analyzing the stored connection information, the system can better dynamically allocate resources, thereby improving the management efficiency of the TCP connection.
[0065] In some embodiments, managing the TCP connection channel based on a key value consisting of identification information of the TCP connection channel and connection information of the TCP connection channel according to the monitoring situation includes:
[0066] When the preset event occurs on the TCP connection channel, disconnect the TCP connection channel;
[0067] After disconnecting the TCP connection channel, the key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel is deleted from the database.
[0068] In the above embodiment, taking the data writing operation on the TCP connection channel as an example, if the TCP connection channel has not been used for a long time, it can be considered that the TCP connection channel may no longer be needed. In order to release the occupied network and system resources, the system will actively disconnect the TCP connection channel that has no writing activity for a long time. After the connection is disconnected, the record related to this connection (the key-value pair consisting of the client identification information and the connection information) can be deleted from the database.
[0069] This embodiment actively disconnects TCP connections that have been inactive for a long time, which helps to free up limited resources of the server, such as memory, ports, and bandwidth, and improves the system's ability to handle new and active requests. It also ensures data consistency and accuracy by regularly cleaning useless entries in the database, and prevents subsequent business logic from making erroneous decisions based on outdated or invalid data.
[0070] In some embodiments, after storing the key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel in the database, the method further includes:
[0071] Get the resource capacity of the server;
[0072] Calculate the maximum number of TCP connection channels that the server can connect to based on the resource capacity;
[0073] Determine a threshold value of the number of TCP connection channels to which the client can connect based on the maximum number of TCP connection channels and usage information of the client;
[0074] Querying the number of key-value pairs corresponding to the client in a database according to the identification information of the client;
[0075] When the number of key-value pairs corresponding to the client is greater than the TCP connection channel number threshold, the client is restricted from establishing a new TCP connection channel with the server.
[0076] In the above embodiment, the resource capacity of the server is obtained by identifying and evaluating the hardware and software resources of the server (such as the central processing unit (CPU), memory, bandwidth, etc.) to understand how many concurrent TCP connections it can support. Based on the above resource capacity, the maximum number of stable TCP connections that the server can handle is calculated. According to the calculated maximum number of connections, combined with the usage information of each client (which may include its resource requirements, priority, etc.), a specific upper limit on the number of connections is set for each client, namely the "TCP connection channel number threshold". Using the client's identification information, the corresponding connection information is searched in the database to determine the number of connections currently established by the client (through existing key-value pairs). If the number of connections established by the client exceeds the threshold set for it, the client is prevented from establishing a new connection to avoid overloading server resources.
[0077] In this embodiment, limiting the number of TCP connections can prevent the server from receiving too many requests and being overloaded, thereby maintaining system performance and service quality, and ensuring that all clients are treated fairly when competing for limited resources, especially in a multi-user environment, to prevent a single user from occupying too many resources.
[0078] According to an embodiment of the present disclosure, a TCP connection management method includes setting a timing strategy that matches a preset event according to the event content of the preset event, wherein the preset event includes any one of the following: no data read operation on the Transmission Control Protocol TCP connection channel between the client and the server, no data write operation on the TCP connection channel, and no data read operation and no data write operation on the TCP connection channel; according to the timing strategy that matches the preset event, polling and monitoring whether the preset event occurs on the TCP connection channel; according to the monitoring situation, managing the TCP connection channel based on a key value composed of the identification information of the client and the connection information of the TCP connection channel, wherein the identification information of the client includes any one of the following: the Internet Protocol IP address of the client or the port number of the client, and the connection information of the TCP connection channel includes at least one of the following: the identification information of the TCP connection channel, the connection status of the TCP connection channel, the most recent activity timestamp of the TCP connection channel, and the data transmission volume of the TCP connection channel. In the method, different timing strategies are set for different preset events, so that the connection status of the TCP connection channel can be accurately identified and detected, and the TCP connection channel is managed based on the connection status of the TCP connection channel through a key value pair composed of the identification information of the client and the connection information of the TCP connection channel, which can conveniently record the detailed information of each TCP connection channel. By analyzing the stored connection information, the system can better dynamically allocate resources, thereby improving the management efficiency of the TCP connection.
[0079] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present disclosure is not limited by the order of the actions described, because according to the present disclosure, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present disclosure.
[0080] The above is an introduction to the method embodiment. The following is a further explanation of the scheme disclosed in the present invention through an apparatus embodiment.
[0081] Figure 2 A block diagram of a TCP connection management device 200 according to an embodiment of the present disclosure is shown, and the device 200 includes:
[0082] The first setting module 201 is used to set a timing strategy matching the preset event according to the event content of the preset event, wherein the preset event includes any one of the following: no data read operation on the transmission control protocol TCP connection channel between the client and the server, no data write operation on the TCP connection channel, no data read operation and no data write operation on the TCP connection channel;
[0083] A first monitoring module 202 is used to poll and monitor whether the preset event occurs on the TCP connection channel according to a timing strategy matching the preset event;
[0084] The first management module 203 is used to manage the TCP connection channel according to the monitoring situation based on a key value composed of the identification information of the client and the connection information of the TCP connection channel, wherein the identification information of the client includes any one of the following: the Internet Protocol IP address of the client or the port number of the client, and the connection information of the TCP connection channel includes at least one of the following: the identification information of the TCP connection channel, the connection state of the TCP connection channel, the most recent activity timestamp of the TCP connection channel, and the data transmission volume of the TCP connection channel.
[0085] Furthermore, the device also includes:
[0086] The first acquisition module is used to obtain the TCP connection request sent by the client;
[0087] A first establishing module, used for establishing a TCP connection channel between the client and the server based on the TCP connection request;
[0088] The first storage module is used to store a key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel in a database after the TCP connection channel is established.
[0089] Furthermore, the first management module includes:
[0090] A first disconnection unit, configured to disconnect the TCP connection channel when the preset event occurs on the TCP connection channel;
[0091] The first deleting unit is used to delete the key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel in the database after disconnecting the TCP connection channel.
[0092] Furthermore, the device also includes:
[0093] A first acquisition module is used to acquire the resource capacity of the server;
[0094] A first calculation module, used to calculate the maximum number of TCP connection channels that the server can connect to according to the resource capacity;
[0095] A first determining module, configured to determine a threshold value of the number of TCP connection channels to which the client can connect based on the maximum number of TCP connection channels and usage information of the client;
[0096] A first query module, used to query the number of key-value pairs corresponding to the client in the database according to the identification information of the client;
[0097] The first restriction module is used to restrict the client from establishing a new TCP connection channel with the server when the number of key-value pairs corresponding to the client is greater than the TCP connection channel number threshold.
[0098] Furthermore, the first monitoring module includes:
[0099] A first acquisition unit, configured to acquire a timestamp of a most recent data read operation and / or data write operation on the TCP connection channel according to a listening time interval matching the preset event;
[0100] A first calculation unit, configured to calculate a difference between a timestamp of a most recent data read operation and / or data write operation on the TCP connection channel and a current timestamp;
[0101] The first judgment unit is used to compare the difference with the idle time threshold matching the preset event, and judge whether the preset event occurs on the TCP connection channel.
[0102] Figure 3 An example of a physical structure diagram of an electronic device is shown. The electronic device may be a smart terminal, and its internal structure diagram may be as follows: Figure 3 As shown. The electronic device includes a processor, a memory and a network interface connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the above-mentioned TCP connection management method is implemented.
[0103] On the other hand, the present invention further provides a computer storage medium storing a computer program, which implements the above-mentioned TCP connection management method when executed by a processor.
[0104] In another aspect, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and when the processor executes the computer instructions, the above-mentioned TCP connection management method is implemented.
[0105] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory.
[0106] By way of illustration and not limitation, Random Access Memory (RAM) is available in many forms, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), Rambus Direct RAM (RDRAM), Direct Rambus Dynamic RAM (DRDRAM), and Rambus Dynamic RAM (RDRAM).
[0107] It should be noted that the above detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the art to which the present application belongs.
[0108] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should also be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0109] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein.
[0110] In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or inherent to these processes, methods, products, or apparatuses.
[0111] For ease of description, spatially relative terms, such as "above", "above", "on the upper surface of", "above", etc., may be used herein to describe the spatial positional relationship between a device or feature and other devices or features as shown in the figure. It should be understood that spatially relative terms are intended to include different orientations of the device in use or operation in addition to the orientation described in the figure. For example, if the device in the accompanying drawings is inverted, the device described as "above other devices or structures" or "above other devices or structures" will be positioned as "below other devices or structures" or "below other devices or structures". Thus, the exemplary term "above" may include both "above" and "below". The device may also be positioned in other different ways, such as rotated 90 degrees or in other orientations, and the spatially relative descriptions used herein are interpreted accordingly.
[0112] In the above detailed description, reference is made to the accompanying drawings, which form a part of this document. In the accompanying drawings, similar symbols typically identify similar components unless the context indicates otherwise. The illustrated embodiments described in the detailed description, drawings, and claims are not meant to be limiting. Other embodiments may be used, and other changes may be made, without departing from the spirit or scope of the subject matter presented herein.
[0113] 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 TCP connection management method, characterized in that: The method comprises: According to the event content of the preset event, a timing strategy matching the preset event is set, wherein the preset event includes any one of the following: no data read operation on the Transmission Control Protocol TCP connection channel between the client and the server, no data write operation on the TCP connection channel, no data read operation and no data write operation on the TCP connection channel; According to a timing strategy matching the preset event, polling and monitoring whether the preset event occurs on the TCP connection channel; According to the monitoring situation, the TCP connection channel is managed based on a key value composed of identification information of the client and connection information of the TCP connection channel, wherein the identification information of the client includes any one of the following: an Internet Protocol IP address of the client or a port number of the client, and the connection information of the TCP connection channel includes at least one of the following: identification information of the TCP connection channel, connection status of the TCP connection channel, most recent activity timestamp of the TCP connection channel, and data transmission volume of the TCP connection channel; The managing the TCP connection channel based on a key value consisting of identification information of the TCP connection channel and connection information of the TCP connection channel according to the monitoring situation includes: When the preset event occurs on the TCP connection channel, disconnect the TCP connection channel; After disconnecting the TCP connection channel, deleting the key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel in the database; The polling and monitoring whether the preset event occurs on the TCP connection channel according to the timing strategy matching the preset event includes: Obtaining the timestamp of the most recent data reading operation and / or data writing operation on the TCP connection channel according to the listening time interval matching the preset event; Calculate the difference between the timestamp of the most recent data read operation and / or data write operation on the TCP connection channel and the current timestamp; The difference is compared with the idle time threshold matching the preset event to determine whether the preset event occurs on the TCP connection channel.
2. The TCP connection management method according to claim 1, characterized in that: Before setting a timing strategy matching the preset event according to the event content of the preset event, the method further includes: Get the TCP connection request sent by the client; Based on the TCP connection request, establishing a TCP connection channel between the client and the server; After the TCP connection channel is established, a key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel is stored in a database.
3. The TCP connection management method according to claim 2, characterized in that: After storing the key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel in the database, the method further includes: Obtaining the resource capacity of the server; Calculate the maximum number of TCP connection channels that the server can connect to based on the resource capacity; Determine a threshold value of the number of TCP connection channels to which the client can connect based on the maximum number of TCP connection channels and usage information of the client; Querying the number of key-value pairs corresponding to the client in a database according to the identification information of the client; When the number of key-value pairs corresponding to the client is greater than the TCP connection channel number threshold, the client is restricted from establishing a new TCP connection channel with the server.
4. A TCP connection management device, characterized in that: The device is used to execute the TCP connection management method according to any one of claims 1 to 3, and the device includes: A first setting module is used to set a timing strategy matching a preset event according to the event content of the preset event, wherein the preset event includes any one of the following: no data read operation on the transmission control protocol TCP connection channel between the client and the server, no data write operation on the TCP connection channel, no data read operation and no data write operation on the TCP connection channel; A first monitoring module, configured to poll and monitor whether the preset event occurs on the TCP connection channel according to a timing strategy matching the preset event; The first management module is used to manage the TCP connection channel based on a key value composed of the identification information of the client and the connection information of the TCP connection channel according to the monitoring situation, wherein the identification information of the client includes any one of the following: the Internet Protocol IP address of the client or the port number of the client, and the connection information of the TCP connection channel includes at least one of the following: the identification information of the TCP connection channel, the connection state of the TCP connection channel, the most recent activity timestamp of the TCP connection channel, and the data transmission volume of the TCP connection channel.
5. The connection management device according to claim 4, characterized in that: The device also includes: The first acquisition module is used to obtain the TCP connection request sent by the client; A first establishing module, used for establishing a TCP connection channel between the client and the server based on the TCP connection request; The first storage module is used to store a key-value pair consisting of the identification information of the client and the connection information of the TCP connection channel in a database after the TCP connection channel is established.
6. An electronic device, characterized in that: The method comprises a processor, a memory and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the TCP connection management method according to any one of claims 1 to 3 when executed by the processor.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the TCP connection management method according to any one of claims 1 to 3 are implemented.
8. A computer program product, characterized in that The method comprises computer instructions, which, when executed by a processor, implement the steps of the TCP connection management method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Data visualization method, device and equipment and computer storage medium
CN116795905A
Server-free computing synchronous trigger and use method thereof
CN117290007A