TCP performance optimization method and device based on local port number

By actively selecting the local port number and managing the port number resource pool, ensuring that TCP reception and transmission are processed on the same CPU core, the lock competition and Cache migration problems are solved, and TCP transmission performance is improved and CPU core switching overhead is saved.

CN119172394APending Publication Date: 2024-12-20CHINA TELECOM DIGITAL INTELLIGENCE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411324958.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-23
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

In the prior art, the TCP reception and transmission process is often processed on different CPU cores, resulting in lock competition and frequent migration of Cache data, resulting in performance overhead and affecting network transmission efficiency.

Method used

By actively selecting the local port number, the network card sends TCP messages to the CPU core where the application thread is located, thereby avoiding processing of different cores. The port number resource pool is used to manage the idle port number to ensure that the TCP link receives and sends operations on the same CPU core .

Benefits of technology

It effectively improves TCP transmission performance, saves the overhead of CPU core switching, improves network transmission efficiency, and significantly improves performance in high concurrency and low latency network environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119172394A_ABST
    Figure CN119172394A_ABST
Patent Text Reader

Abstract

The invention relates to a TCP performance optimization method and device based on a local port number, and belongs to the technical field of TCP performance optimization, and the method comprises the steps: determining an idle port number in an operating system; forming a port number resource pool, and counting the number in the port resource number pool and corresponding port number details; before a TCP client calls connect () to initiate a TCP link, a first local port number is selected from a port number resource pool for the TCP link, and a server address structure is set; the TCP link uses a first local port number; the server receives a connection request of the TCP client and performs data transmission with the TCP client; and closing the TCP link, and releasing resources of the first local port number. According to the invention, the problem of performance reduction caused by CPU core number switching in the TCP packet receiving and sending process is solved, the TCP transmission performance can be effectively improved, and the overhead between CPU core switching is saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of TCP performance optimization, and in particular relates to a TCP performance optimization method and device based on a local port number. Background Art

[0002] As network speed increases, the speed at which network cards receive messages exceeds the processing capacity of a single CPU core. To solve this problem, many network card chips now support the RSS (Receive Side Scaling) feature, that is, sending received TCP messages to multiple CPU cores for processing. The packet receiving and sending processes of a TCP link often run on different CPU cores. Since both the receiving and sending processes need to access the data structure of the TCP link, they run on different CPU cores, so locks are required to ensure mutual exclusive access, which will cause lock contention. These TCP data structures frequently migrate between the L1 / L2 caches of different CPU cores. Lock contention and frequent migration of data in the cache will result in a large performance overhead. Trying to make the receiving and sending processes of the same TCP run on the same CPU core is an important practical method for optimizing TCP performance in this solution. For multiple systems, if this problem is solved, the performance can be at least 10% higher.

[0003] In order to ensure that the packets of the same TCP link are sent to the same CPU core, the network card will use the five-tuple (local_addr, remote_addr, local_port, remote_port, proto) to calculate a hash value, and then send the packets to different receive queues based on this hash value. Different queues are processed by different CPU cores. The specific implementation method is that different receive queues correspond to different interrupt numbers, and these interrupt numbers will be routed to different CPU cores. After the network packet arrives, the CPU core is notified through an interrupt, and then the Linux kernel will wake up the soft interrupt processing flow on this core and run the code path of TCP receiving packets in the soft interrupt. Then wake up the upper application thread and call recvmsg() to copy the packet out of the kernel. In other words, the kernel TCP receiving processing path is determined by the network card, the hash algorithm of the network card's RSS, and the binding relationship between the network card's receive queue interrupt and the CPU core.

[0004] The kernel's TCP send processing path is on the same CPU core as the application thread. If no special processing is done, the receive process and send process of the same TCP link are likely to be processed on different CPU cores.

[0005] Since both the receiving process and the sending process need to access the data structure of the TCP link, they run on different CPU cores, so locks are needed to ensure mutual exclusive access, which will cause lock contention. These TCP data structures frequently migrate between the L1 / L2 caches of different CPU cores. Lock contention and frequent migration of data in the cache will cause a lot of performance overhead. Trying to make the receiving and sending processes of the same TCP run on the same CPU core has become an important direction for optimizing TCP performance. Summary of the invention

[0006] In view of the above deficiencies in the prior art, the purpose of the invention is to provide a TCP performance optimization method and device based on local port numbers. By actively selecting the local port number, the network card sends the received TCP message to the CPU core where the application thread is located, thereby avoiding TCP reception and transmission being processed on different cores, solving the problem of performance degradation caused by CPU core switching during TCP connection packet reception and transmission, and can effectively improve TCP transmission performance and save the overhead between CPU core switching.

[0007] The first aspect of the present invention provides a TCP performance optimization method based on a local port number, comprising:

[0008] Determine the free port number in the operating system;

[0009] The idle port numbers in the operating system are grouped into a port number resource pool, and the number of ports in the port resource number pool and the corresponding port number details are counted;

[0010] Before the TCP client calls connect() to initiate a TCP connection, it selects the first local port number from the port number resource pool for the TCP connection and sets the server address structure;

[0011] The TCP connection uses the first local port number;

[0012] The server accepts the connection request from the TCP client and transmits data with the TCP client;

[0013] Close the TCP connection and release the resources of the first local port number.

[0014] Furthermore, in the above-mentioned TCP performance optimization method based on local port numbers, determining an idle port number in the operating system includes:

[0015] Filter out the ports being listened to in the operating system and find the unused port range;

[0016] Determine an idle port number in the range of 1024 to 65535;

[0017] Count and calibrate the port numbers occupied by components in the system and the port numbers that subsequent components need to occupy;

[0018] The free port numbers in the operating system are obtained by filtering out the port numbers occupied by the components in the operating system and the port numbers required to be occupied by subsequent components from the free port numbers in the range of 1024 to 65535.

[0019] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, setting the server address structure is to use the struct sockaddr_in structure to set the IP address and local port number of the server.

[0020] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, the TCP link uses the first local port number, including: calling bind to let the TCP link use the first local port number.

[0021] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, the server accepts the connection request of the TCP client, including:

[0022] Use the accept() function to accept the client's connection request.

[0023] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, data transmission with the TCP client includes:

[0024] Use send() and recv() functions to transmit data with TCP client;

[0025] Or, use the write() and read() functions to transfer data with a TCP client.

[0026] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, after releasing the resources of the first local port number, it also includes:

[0027] Put the first local port number back into the port number resource pool.

[0028] The second aspect of the present invention further proposes a TCP performance optimization device based on a local port number, comprising:

[0029] Determination module: used to determine the idle port number in the operating system;

[0030] Composition module: used to organize the idle port numbers in the operating system into a port number resource pool, count the number of port resource number pools and the corresponding port number details;

[0031] Selection module: used for selecting the first local port number from the port number resource pool for the TCP connection and setting the server address structure before the TCP client calls connect() to initiate the TCP connection;

[0032] Use module: Use the first local port number for TCP connection;

[0033] Transmission module: used for the server to accept the connection request of the TCP client and to transmit data with the TCP client;

[0034] Release module: used to close the TCP link and release the resources of the first local port number.

[0035] According to a third aspect of the present invention, an electronic device is provided, comprising: a processor and a memory;

[0036] The processor is used to execute any one of the above TCP performance optimization methods based on the local port number by calling the program or instruction stored in the memory.

[0037] In a fourth aspect of the present invention, a computer-readable storage medium is further proposed, wherein the computer-readable storage medium stores a program or instruction, and the program or instruction enables a computer to execute any one of the above methods for optimizing TCP performance based on a local port number.

[0038] The beneficial effects of the present invention are as follows: the present invention determines the idle port number in the operating system; the idle port numbers in the operating system are formed into a port number resource pool, and the number of the port resource number pool and the corresponding port number details are counted; before the TCP client calls connect() to initiate a TCP link, the first local port number is selected from the port number resource pool for the TCP link, and the server address structure is set; the TCP link uses the first local port number; the server accepts the connection request of the TCP client and performs data transmission with the TCP client; the TCP link is closed to release the resources of the first local port number. The present invention actively selects the local port number, allowing the network card to send the received TCP message to the CPU core where the application thread is located, thereby avoiding TCP receiving and sending processing on different cores, solving the performance degradation problem caused by the switching of the number of CPU cores during TCP connection packet receiving and packet sending, and can effectively improve TCP transmission performance and save the overhead between CPU core switching. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The accompanying drawings are only used to illustrate specific embodiments and are not considered to limit the present invention. In the entire drawings, the same reference symbols represent the same components. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.

[0040] Figure 1 A method diagram for optimizing TCP performance based on local port numbers provided by an embodiment of the present invention;

[0041] Figure 2 A method diagram for determining an idle port number in an operating system provided by an embodiment of the present invention;

[0042] Figure 3 A diagram of a TCP performance optimization device based on a local port number provided in an embodiment of the present invention;

[0043] Figure 4 A schematic block diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0044] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work should fall within the scope of protection of the present invention.

[0045] Furthermore, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts disclosed in the present invention.

[0046] In the description of the present invention, the terms "first", "second", and "third" are used for descriptive purposes only and should not be understood as indicating or implying relative importance. The terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be internal communication between two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0047] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of methods and systems consistent with some aspects of the present invention as detailed in the appended claims.

[0048] The present invention proposes a TCP performance optimization method, device, electronic device and storage medium based on local port numbers. By actively selecting the local port number, the performance degradation problem caused by CPU core switching during TCP connection packet receiving and sending is solved, which can effectively improve TCP transmission performance and save the overhead between CPU core switching.

[0049] Before introducing the embodiments of the present invention, professional terms and application scenarios involved in the embodiments of the present invention are introduced.

[0050] Cache: Cache is a data storage mechanism designed to improve system performance by temporarily storing frequently used data on a fast-access storage medium.

[0051] TCP (Transmission Control Protocol): Transmission Control Protocol is a connection-oriented, reliable, byte stream-based transport layer communication protocol.

[0052] UDP (User Datagram Protocol): User Datagram Protocol is a connectionless transport layer protocol that provides a simple, unreliable data transmission service.

[0053] RTT (Round-Trip Time): Round-trip time, the time required for data to travel from the sender to the receiver and then back to the sender.

[0054] RSS (Receive Side Scaling): Receive side scaling is a technology implemented on the network interface card (NIC) to improve the processing efficiency of network data packets.

[0055] This embodiment has a significant effect on performance improvement in various application scenarios, especially in network communication environments that require high reliability, high throughput, and low latency. Typical application scenarios are as follows:

[0056] Large-scale distributed systems: In large-scale distributed systems such as distributed storage and distributed file systems, optimizing TCP through local port numbers helps speed up data synchronization and access.

[0057] Cloud computing platform: Optimizing TCP performance through local port numbers can improve the efficiency of network communication between virtual machines or containers, thereby improving the overall performance of the cloud computing platform.

[0058] Video streaming services: Video streaming services rely on stable high-bandwidth and low-latency network connections. TCP performance optimization can reduce buffering time and provide a smoother video playback experience.

[0059] Internet of Things (IoT): IoT devices often need to operate in resource-constrained environments. Optimizing TCP performance can reduce data transmission time, reduce energy consumption, and improve device efficiency.

[0060] Method Embodiment

[0061] Figure 1 A diagram of a TCP performance optimization method based on a local port number provided in an embodiment of the present invention.

[0062] The first aspect of the present invention provides a TCP performance optimization method based on local port number, combined with Figure 1 , including six steps from S1 to S6:

[0063] S1: Determine the free port number in the operating system.

[0064] Specifically, in the embodiment of the present invention, the method for determining an idle port number in the operating system includes: Steps S21 to S24, which are described below in conjunction with Figure 2 Detailed introduction.

[0065] S2: The idle port numbers in the operating system are organized into a port number resource pool, and the number of ports in the port resource number pool and the corresponding port number details are counted.

[0066] Specifically, in the embodiment of the present invention, the idle port numbers in the operating system are combined into a port number resource pool, and the number of ports in the port resource number pool and the corresponding port number details are counted.

[0067] S3: Before the TCP client calls connect() to initiate a TCP connection, it selects the first local port number from the port number resource pool for the TCP connection and sets the server address structure.

[0068] Specifically, in the embodiment of the present invention, the first local port number may be any one in the port number resource pool. The method for setting the server address structure is described in detail below.

[0069] S4: TCP connection uses the first local port number.

[0070] Specifically, in the embodiment of the present invention, bind is called to let the TCP link use the selected first local port number, so as to avoid the kernel operating the same function automatically selecting a random port number during connect.

[0071] S5: The server accepts the connection request from the TCP client and transmits data with the TCP client.

[0072] Specifically, in the embodiment of the present invention, the server uses the accept() function to accept the connection request of the client, and uses the send() and recv() functions to transmit data with the TCP client; or uses the write() and read() functions to transmit data with the TCP client.

[0073] S6: Close the TCP link and release the resources of the first local port number.

[0074] Specifically, in the embodiment of the present invention, after the TCP link is closed, the resources of the first local port number are released to facilitate the subsequent use of the first local port number.

[0075] Figure 2 A diagram of a method for determining an idle port number in an operating system provided by an embodiment of the present invention.

[0076] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, the idle port number in the operating system is determined, combined with Figure 2 , including four steps from S21 to S24:

[0077] S21: Filter out the ports being listened to in the operating system and find the unused port range.

[0078] Specifically, in the embodiment of the present invention, the code for filtering out the ports being listened to in the operating system and finding the unused port range is as follows: netstat -an | grep LISTEN | awk '{print $4}' | sed 's / .*: / / ' | sort -n | awk 'BEGIN {last = 0} {if ($1-last>1) print last + 1; last = $1}'.

[0079] S22: Determine an idle port number in the range of 1024 to 65535.

[0080] Specifically, in the embodiment of the present invention, determining an idle port number in the range of 1024 to 65535 is to find an idle port number in the range of 1024 to 65535. The specific code is as follows: find 102465535-type f|xargs-n 1bash-c'exec 7<> / dev / tcp / localhost / $0&&echo"Port$0is open"||echo"Port$0is not open"'.

[0081] S23: Count and calibrate the port numbers occupied by components in the system and the port numbers that need to be occupied by subsequent components.

[0082] Specifically, in an embodiment of the present invention, statistics are collected to determine the specific port numbers occupied by various components in the system. For example, there are many components in a distributed storage system, OSD / MDS occupies 6800-7300, MON occupies 6789, etc., and the port numbers are clearly classified. The port numbers that need to be occupied by subsequent components are also counted.

[0083] S24: Filter out the port numbers occupied by components in the operating system and the port numbers to be occupied by subsequent components from the free port numbers in the range of 1024 to 65535 to obtain the free port numbers in the operating system.

[0084] Specifically, in the embodiment of the present invention, free port numbers in the range of 1024 to 65535 are further screened, thereby improving the accuracy of free port numbers in the operating system.

[0085] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, setting the server address structure is to use the struct sockaddr_in structure to set the IP address and local port number of the server.

[0086] Specifically, in the embodiment of the present invention, the code for setting the IP address and local port number of the server using the struct sockaddr_in structure is as follows:

[0087] / **Bind port** /

[0088] server_addr.sin_family=AF_INET;

[0089] server_addr.sin_port = htons(local_port); / / bind local port number

[0090] server_addr.sin_addr.s_addr=INADDR_ANY;

[0091] bind(sockfd,(struct sockaddr*)&server_addr,sizeof(server_addr));

[0092] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, the TCP link uses the first local port number, including: calling bind to let the TCP link use the first local port number.

[0093] Specifically, in the embodiment of the present invention, bind is called to let the TCP link use the selected first local port number, thereby avoiding the operating system kernel from automatically selecting a random port number during connect.

[0094] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, the server accepts the connection request of the TCP client, including:

[0095] Use the accept() function to accept the client's connection request.

[0096] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, data transmission with the TCP client includes:

[0097] Use send() and recv() functions to transmit data with TCP client;

[0098] Or, use the write() and read() functions to transfer data with a TCP client.

[0099] Furthermore, in the above-mentioned TCP performance optimization method based on local port number, after releasing the resources of the first local port number, it also includes:

[0100] Put the first local port number back into the port number resource pool.

[0101] Specifically, in the embodiment of the present invention, after the resources of the first local port number are released, the first local port number is put back into the port number resource pool to facilitate subsequent use.

[0102] Device Embodiment

[0103] Figure 3 A diagram of a TCP performance optimization device based on a local port number provided in an embodiment of the present invention.

[0104] The second aspect of the present invention also proposes a TCP performance optimization device based on a local port number, combined with Figure 3 ,include:

[0105] Determining module 31: used to determine an idle port number in the operating system.

[0106] Specifically, in the embodiment of the present invention, the determination module 31 determines an idle port number in the operating system.

[0107] The composition module 32 is used to form a port number resource pool with idle port numbers in the operating system, and count the number of ports in the port resource number pool and the corresponding port number details.

[0108] Specifically, in the embodiment of the present invention, the composition module 32 combines the idle port numbers in the operating system into a port number resource pool, and counts the number of ports in the port resource pool and the corresponding port number details.

[0109] Selection module 33: before the TCP client calls connect() to initiate a TCP connection, it selects the first local port number from the port number resource pool for the TCP connection and sets the server address structure.

[0110] Specifically, in the embodiment of the present invention, the first local port number selected by the selection module 33 may be any one in the port number resource pool.

[0111] Using module 34: Using the first local port number for the TCP connection.

[0112] Specifically, in the embodiment of the present invention, the module 34 is used to call bind to let the TCP link use the selected first local port number, so as to avoid the kernel operating the same automatically selecting a random port number during connect.

[0113] Transmission module 35: used for the server to accept the connection request of the TCP client and perform data transmission with the TCP client.

[0114] Specifically, in the embodiment of the present invention, the server uses the accept() function to accept the client's connection request, and the transmission module 35 uses the send() and recv() functions to transmit data with the TCP client; or, uses the write() and read() functions to transmit data with the TCP client.

[0115] Release module 36: used to close the TCP link and release the resources of the first local port number.

[0116] Specifically, in the embodiment of the present invention, after closing the TCP link, the release module 36 releases the resource of the first local port number to facilitate the subsequent use of the first local port number.

[0117] According to a third aspect of the present invention, an electronic device is provided, comprising: a processor and a memory;

[0118] The processor is used to execute any one of the above TCP performance optimization methods based on the local port number by calling the program or instruction stored in the memory.

[0119] In a fourth aspect of the present invention, a computer-readable storage medium is further proposed, wherein the computer-readable storage medium stores a program or instruction, and the program or instruction enables a computer to execute any one of the above methods for optimizing TCP performance based on a local port number.

[0120] Figure 4 It is a schematic block diagram of an electronic device provided by an embodiment of the present invention.

[0121] like Figure 4As shown, the electronic device includes: at least one processor 401, at least one memory 402 and at least one communication interface 403. The various components in the electronic device are coupled together through a bus system 404. The communication interface 403 is used to transmit information between external devices. It can be understood that the bus system 404 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 404 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, Figure 4 Various buses are labeled as bus system 404 .

[0122] It can be understood that the memory 402 in this embodiment can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories.

[0123] In some implementations, the memory 402 stores the following elements, executable units or data structures, or a subset thereof, or an extended set thereof: an operating system and application programs.

[0124] The operating system includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application includes various application programs, such as a media player (Media Player), a browser (Browser), etc., which are used to implement various application services. A program that implements any method in a TCP performance optimization method based on a local port number provided in an embodiment of the present invention can be included in the application.

[0125] In an embodiment of the present invention, the processor 401 calls a program or instruction stored in the memory 402, specifically, a program or instruction stored in an application, and the processor 401 is used to execute the steps of each embodiment of a TCP performance optimization method based on a local port number provided in an embodiment of the present invention.

[0126] Determine the free port number in the operating system;

[0127] The idle port numbers in the operating system are grouped into a port number resource pool, and the number of ports in the port resource number pool and the corresponding port number details are counted;

[0128] Before the TCP client calls connect() to initiate a TCP connection, it selects the first local port number from the port number resource pool for the TCP connection and sets the server address structure;

[0129] The TCP connection uses the first local port number;

[0130] The server accepts the connection request from the TCP client and transmits data with the TCP client;

[0131] Close the TCP connection and release the resources of the first local port number.

[0132] Any method in a TCP performance optimization method based on a local port number provided in an embodiment of the present invention can be applied to a processor 401, or implemented by a processor 401. The processor 401 can be an integrated circuit chip having a signal processing capability. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 401 or an instruction in the form of software. The above processor 401 can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.

[0133] The steps of any method in a method for optimizing TCP performance based on a local port number provided by an embodiment of the present invention can be directly embodied as being executed by a hardware decoding processor, or being executed by a combination of hardware and software units in a decoding processor. The software unit can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 402, and the processor 401 reads the information in the memory 402, and completes the steps of the method in combination with its hardware.

[0134] Those skilled in the art will appreciate that although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features from different embodiments is meant to be within the scope of the present invention and to form different embodiments.

[0135] Those skilled in the art will appreciate that the description of each embodiment has its own emphasis, and for parts not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0136] Although the embodiments of the present invention are described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations all fall within the scope defined by the appended claims. The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of various equivalent modifications or substitutions within the technical scope disclosed by the present invention, and these modifications or substitutions should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

[0137] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A TCP performance optimization method based on local port number, It is characterized in that include: Determine the free port number in the operating system; The idle port numbers in the operating system are grouped into a port number resource pool, and the number of ports in the port resource number pool and the corresponding port number details are counted; Before the TCP client calls connect() to initiate a TCP connection, a first local port number is selected from a port number resource pool for the TCP connection, and a server address structure is set; The TCP connection uses the first local port number; The server accepts the connection request from the TCP client and transmits data with the TCP client; Close the TCP link and release the resources of the first local port number.

2. A TCP performance optimization method based on local port number according to claim 1, It is characterized in that Determining an idle port number in the operating system includes: Filter out the ports being listened to in the operating system and find the unused port range; Determine an idle port number in the range of 1024 to 65535; Count and calibrate the port numbers occupied by components in the system and the port numbers that subsequent components need to occupy; The free port numbers in the operating system are obtained by filtering out the port numbers occupied by the components in the operating system and the port numbers required to be occupied by subsequent components from the free port numbers in the range of 1024 to 65535.

3. A TCP performance optimization method based on local port number according to claim 1, It is characterized in that The server address structure is set by using the struct sockaddr_in structure to set the IP address and local port number of the server.

4. A TCP performance optimization method based on local port number according to claim 1, It is characterized in that The TCP link uses the first local port number, including: calling bind to let the TCP link use the first local port number.

5. A TCP performance optimization method based on local port number according to claim 1, It is characterized in that The server accepts a connection request from a TCP client, including: Use the accept() function to accept the client's connection request.

6. A TCP performance optimization method based on local port number according to claim 1, It is characterized in that The data transmission with the TCP client includes: Use send() and recv() functions to transmit data with TCP client; Or, use the write() and read() functions to transfer data with a TCP client.

7. A TCP performance optimization method based on local port number according to claim 1, It is characterized in that After releasing the resources of the first local port number, the method further includes: Put the first local port number back into the port number resource pool.

8. A TCP performance optimization device based on local port number, It is characterized in that include: Determination module: used to determine the idle port number in the operating system; Composition module: used to organize the idle port numbers in the operating system into a port number resource pool, count the number of port resource number pools and the corresponding port number details; Selection module: used for selecting the first local port number from the port number resource pool and setting the server address structure for the TCP link before the TCP client calls connect() to initiate the TCP link; Use module: Use the first local port number for TCP connection; Transmission module: used for the server to accept the connection request of the TCP client and to transmit data with the TCP client; Release module: used to close the TCP link and release the resources of the first local port number.

9. An electronic device, It is characterized in that include: Processor and memory; The processor is used to execute a TCP performance optimization method based on a local port number as described in any one of claims 1 to 7 by calling a program or instruction stored in the memory.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a program or instruction, and the program or instruction enables a computer to execute a TCP performance optimization method based on a local port number as described in any one of claims 1 to 7.