A method and device for adjusting the number of NGINX connections, an electronic device, and a storage medium

By adjusting the number of NGINX connections in real time using memory-mapped arrays and connection tables, the problem of communication latency and resource waste caused by static connection limits in existing technologies is solved, achieving dynamic adjustment and efficient communication.

CN115883580BActive Publication Date: 2026-04-17BEIJING TOPSEC NETWORK SECURITY TECH +2
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING TOPSEC NETWORK SECURITY TECH
Filing Date
2022-12-26
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

In existing technologies, the limit on the number of NGINX connections cannot be dynamically adjusted, resulting in communication delays and resource waste, and the service needs to be restarted to modify the number of connections.

Method used

By creating a memory-mapped array and a connection table, the number of NGINX connections can be adjusted in real time based on the connection status of data packets and socket status, thus avoiding service restarts.

Benefits of technology

It enables flexible adjustment of the number of NGINX connections, avoids communication delays and resource waste, improves communication efficiency, and reduces system pressure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115883580B_ABST
    Figure CN115883580B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a method and device for adjusting the number of NGINX connections, electronic equipment and storage medium, wherein the method comprises: creating a memory mapping array; obtaining the connection state of a data packet to be connected according to the structure state of the data packet; obtaining the current number of connections of a server corresponding to the NGINX according to the memory mapping array and the connection state; connecting the data packet to be connected to the NGINX according to the current number of connections and the connection state; creating a connection table; and adjusting the current number of connections of the NGINX after the data packet to be connected is connected according to the connection table and the socket in the NGINX. By implementing the embodiments of the present application, the number of NGINX connections can be flexibly adjusted, the communication connection is smoother, the delay and lag of the communication connection are avoided, the NGINX does not need to be restarted, and resource and performance waste is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and more specifically, to a method, apparatus, electronic device, and computer storage medium for adjusting the number of NGINX connections. Background Technology

[0002] NGINX is a high-performance concurrent server capable of functioning as a web server and reverse proxy. In addition, NGINX can be combined with TPROXY to achieve transparent proxying, a feature commonly used in firewalls and other devices.

[0003] When the traffic through NGINX is too large, it will consume too much system performance, which will not only affect other processes in the system, but also cause communication delays due to the decrease in NGINX processing efficiency. Therefore, the number of NGINX connections is usually limited or adjusted.

[0004] Existing solutions typically rely on limiting the number of NGINX connections by writing the connection limit into the configuration. When NGINX receives a new communication connection, it first checks the current NGINX connection count. If the count exceeds the configured limit, it returns an exception without further processing. Because the connection count is directly written to the configuration file, dynamic adjustment is not possible; it can only be modified by restarting NGINX, impacting performance. Summary of the Invention

[0005] The purpose of this application is to provide a method, apparatus, electronic device, and storage medium for adjusting the number of NGINX connections, which can flexibly adjust the number of NGINX connections, making communication connections smoother, without causing delays or stuttering, without requiring NGINX to be restarted, and avoiding waste of resources and performance.

[0006] In a first aspect, embodiments of this application provide a method for adjusting the number of NGINX connections, the method comprising:

[0007] Create a memory-mapped array;

[0008] The connection status of the data packet to be connected is obtained based on the structure status of the data packet to be connected.

[0009] The current number of connections to the server corresponding to NGINX is obtained based on the memory mapping array and the connection status;

[0010] Connect the data packet to be connected to the NGINX based on the current number of connections and the connection status;

[0011] Create a join table;

[0012] The current number of connections in NGINX is adjusted based on the connection table and the sockets in NGINX after connecting the data packet to be connected.

[0013] In the above implementation process, data packets are connected to NGINX based on the current number of connections and the connection status. The current number of connections is adjusted according to the connection table and sockets. This allows for flexible adjustment of the number of NGINX connections, making communication connections smoother and preventing delays or stuttering. It also eliminates the need to restart NGINX, thus avoiding waste of resources and performance.

[0014] Further, the step of obtaining the connection state of the data packet to be connected based on the structure state of the data packet to be connected includes:

[0015] Determine whether the structure state is a preset state;

[0016] If so, determine that the connection status of the data packet to be connected is a waiting connection state;

[0017] If not, the connection status of the data packet to be connected is determined to be an unconnectable state.

[0018] In the above implementation process, the connection status of data packets is determined based on the status of the mechanism, which can quickly distinguish the data packets to be connected, improve the efficiency of communication connection, and avoid lag and delay.

[0019] Furthermore, when the connection status of the data packet to be connected is determined to be a waiting connection state, the step of obtaining the current connection count of the server corresponding to NGINX based on the memory mapping array and the connection status includes:

[0020] Obtain the NGINX server corresponding to the data packet to be connected;

[0021] Read the location information of the NGINX server corresponding to the data packet to be connected in the memory-mapped array to obtain the number of connections of the NGINX server;

[0022] The queue length of the data packet to be connected is read according to the structure of the data packet to be connected;

[0023] The number of unconnected servers of the NGINX server is obtained based on the queue length;

[0024] The current connection count is obtained based on the number of connections and the number of unconnected connections, and the current connection count is stored in the memory-mapped array.

[0025] In the above implementation process, the current number of connections is obtained based on the number of connections and the number of disconnections. This allows for a clear understanding of the connection status between the data packets to be connected and the NGINX server, facilitating adjustments to the current number of connections and effectively shortening the connection time.

[0026] Further, the step of connecting the data packet to be connected to the NGINX based on the current number of connections and the connection status includes:

[0027] Obtain the set connection limit for the NGINX server;

[0028] Determine whether the current number of connections is less than the set number of connections;

[0029] If so, connect the data packet to be connected to the NGINX.

[0030] In the above implementation process, the system determines whether a data packet to be connected to NGINX can be connected based on the set number of connections and the current number of connections. This effectively utilizes the NGINX server and avoids resource consumption and connection congestion.

[0031] Furthermore, following the step of creating the join table, the following steps are also included:

[0032] The changes in the join table are synchronized to the memory-mapped array.

[0033] In the above implementation process, the change information of the connection table is synchronized to the memory-mapped array to ensure that the connection table and the memory-mapped array can simultaneously obtain the adjustment information of NGINX's connection count.

[0034] Further, the step of adjusting the current number of connections in NGINX after connecting the data packet to be connected according to the connection table and the socket in NGINX includes:

[0035] Record the server corresponding to the socket;

[0036] The first preset value corresponding to the recorded server is added to the connection table after the synchronization change information to obtain the connection table after the first adjustment.

[0037] The connection table after the first adjustment is then adjusted.

[0038] In the above implementation process, adding the first preset value corresponding to the recorded server to the connection table after synchronization change information can make the connection status of the server corresponding to the socket be recorded and updated in real time, which makes it easy to directly obtain the change of the number of connections corresponding to the server in the connection table, and can effectively improve the adjustment efficiency.

[0039] Furthermore, the step of adjusting the join table after the first adjustment includes:

[0040] The first signal transmission parameter in the socket is assigned a value, and the second preset value is added to the connection table after the first adjustment to obtain the connection table after the second adjustment.

[0041] Release the NGINX connection;

[0042] Determine whether a corresponding parameter value exists in the second signal transmission parameter during the process of releasing the NGINX connection;

[0043] If so, adjust the connection table after the second adjustment.

[0044] In the above implementation process, the changes in the number of connections generated during socket assignment and connection release can be displayed in the connection table, making it easier to know the changes in NGINX connections and making the adjustment of the number of connections more flexible.

[0045] Secondly, embodiments of this application also provide an apparatus for adjusting the number of NGINX connections, the apparatus comprising:

[0046] The module is used to create memory-mapped arrays and also to create join tables.

[0047] A connection status acquisition module is used to obtain the connection status of the data packet to be connected based on the structure status of the data packet to be connected.

[0048] The data acquisition module is used to obtain the current number of connections to the server corresponding to the NGINX based on the memory mapping array and the connection status;

[0049] A connection module is used to connect the data packet to be connected to the NGINX based on the current number of connections and the connection status;

[0050] An adjustment module is used to adjust the current number of connections in NGINX after connecting the data packet to be connected, based on the connection table and the sockets in NGINX.

[0051] In the above implementation process, data packets are connected to NGINX based on the current number of connections and the connection status. The current number of connections is adjusted according to the connection table and sockets. This allows for flexible adjustment of the number of NGINX connections, making communication connections smoother and preventing delays or stuttering. It also eliminates the need to restart NGINX, thus avoiding waste of resources and performance.

[0052] Thirdly, an electronic device provided in this application includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method described in any of the first aspects.

[0053] Fourthly, embodiments of this application provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method described in any of the first aspects.

[0054] Fifthly, embodiments of this application provide a computer program product that, when run on a computer, causes the computer to perform the method described in any of the first aspects.

[0055] Other features and advantages of this disclosure will be set forth in the following description, or some features and advantages may be inferred from the description or determined without doubt, or may be learned by practicing the techniques described above.

[0056] It can be implemented in accordance with the contents of the specification. The preferred embodiments of this application are described in detail below with reference to the accompanying drawings. Attached Figure Description

[0057] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation on the range. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0058] Figure 1 A flowchart illustrating the method for adjusting the number of NGINX connections provided in an embodiment of this application;

[0059] Figure 2 A schematic diagram illustrating the structural composition of the apparatus for adjusting the number of NGINX connections provided in an embodiment of this application;

[0060] Figure 3 This is a schematic diagram of the structural composition of the electronic device provided in the embodiments of this application. Detailed Implementation

[0061] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.

[0062] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0063] The specific embodiments of this application will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to adjust the scope of this application.

[0064] Example 1

[0065] Figure 1 This is a flowchart illustrating the method for adjusting the number of NGINX connections provided in an embodiment of this application. Figure 1 As shown, the method includes:

[0066] S1, Create a memory-mapped array;

[0067] S2, obtain the connection status of the data packet to be connected based on the structure status of the data packet to be connected;

[0068] S3, obtain the current number of connections to the server corresponding to NGINX based on the memory mapping array and the connection status;

[0069] S4, connect the data packets to be connected to NGINX based on the current number of connections and connection status;

[0070] S5, Create a join table;

[0071] S6, adjust the current number of NGINX connections after connecting the data packets to be connected based on the connection table and the sockets in NGINX.

[0072] In the above implementation process, data packets are connected to NGINX based on the current number of connections and the connection status. The current number of connections is adjusted according to the connection table and sockets. This allows for flexible adjustment of the number of NGINX connections, making communication connections smoother and preventing delays or stuttering. It also eliminates the need to restart NGINX, thus avoiding waste of resources and performance.

[0073] This application implements a method for limiting the number of NGINX connections in transparent proxy mode. It adds connection limit functionality on top of the transparent proxy mode.

[0074] In S1, memory is allocated, and mmap (a method of memory-mapped files) is overwritten to map the allocated memory for use. This memory map is used as an array, where each member represents an NGINX server. Subsequently, the connection count of each NGINX server is obtained by reading this memory map array.

[0075] Furthermore, S2 includes:

[0076] Determine if the structure state is a preset state;

[0077] If so, determine the connection status of the data packet to be connected as a waiting connection state;

[0078] If not, the connection status of the data packet to be connected is determined to be an unconnectable state.

[0079] In the above implementation process, the connection status of data packets is determined based on the status of the mechanism, which can quickly distinguish the data packets to be connected, improve the efficiency of communication connection, and avoid lag and delay.

[0080] In this embodiment, the state of the struct sock structure in the tproxy_tg4() function of the data packet to be connected is used to determine whether the data packet to be connected will create a connection in NGINX.

[0081] In this embodiment of the application, the data packet to be connected is the Transmission Control Protocol (TCP). If the state of the matched struct sock structure is not the preset state (the preset state in this embodiment of the application is TCP_LISTEN), a connection will not be created on NGINX, the connection state is determined to be an unconnection state, and this data packet will not be processed.

[0082] If the state of the matched struct sock is TCP_LISTEN, the connection state is determined to be a waiting connection state, indicating that this communication connection will be created by NGINX.

[0083] Optionally, the data packet to be connected in this embodiment of the application can also be a User Datagram Protocol (UDP). UDP can be determined by the position of the struct sock structure in the tproxy_tg4() function. Specifically, if the five-tuple in the data packet to be connected is matched, a connection will not be created on NGINX, the connection status is determined to be unconnectable, and this data packet will not be processed.

[0084] If the destination IP and destination port number passed to TPROXY match, it means that the communication connection will be created on NGINX, and the connection status is determined to be a waiting connection state.

[0085] Furthermore, S3 includes:

[0086] When the connection status of the data packet to be connected is determined to be in the waiting connection state, obtain the NGINX server corresponding to the data packet to be connected;

[0087] Read the location information of the NGINX server corresponding to the data packet to be connected in the memory-mapped array to obtain the number of connections to the NGINX server;

[0088] Read the queue length of the data packets to be connected based on the structure of the data packets to be connected;

[0089] Get the number of unconnected servers for NGINX based on the queue length;

[0090] The current number of connections is obtained based on the number of connected connections and the number of unconnected connections. The current number of connections is stored in a memory-mapped array.

[0091] In the above implementation process, the current number of connections is obtained based on the number of connections and the number of disconnections. This allows for a clear understanding of the connection status between the data packets to be connected and the NGINX server, facilitating adjustments to the current number of connections and effectively shortening the connection time.

[0092] When the connection status of a data packet to be connected is determined to be in a waiting connection state, it indicates that a communication connection needs to be established between the data packet and NGINX. First, it's determined which NGINX server this communication connection belongs to. The NGINX connection count (also known as the accepted connection count) is obtained by reading the corresponding position in the memory-mapped array.

[0093] Obtain the struct sock structure of the data packet to be connected, and calculate the number of TCP connections that have not completed the three-way handshake and the number of TCP connections that NGINX has not connected on the current struct sock structure by reading the length of the half-connection queue and the full-connection queue. This is the number of unconnected connections in this embodiment (or it can be called the half_connection value).

[0094] Furthermore, S4 includes:

[0095] Get the configured connection limit for the NGINX server;

[0096] Determine if the current number of connections is less than the set number of connections;

[0097] If so, connect the data packet to be connected to NGINX.

[0098] In the above implementation process, the system determines whether a data packet to be connected to NGINX can be connected based on the set number of connections and the current number of connections. This effectively utilizes the NGINX server and avoids resource consumption and connection congestion.

[0099] The current number of connections (accepted connections + half_connection value * 2) is compared with the set number of connections on the corresponding server (i.e., the limit of NGINX connections). Specifically, if it is less than the set number of connections, a communication connection is created between the data packet to be connected and NGINX; if it is equal to the set number of connections, it is forwarded directly or other operations are performed.

[0100] During the TPROXY connection count matching process, only the first packet to be connected will match the socket (the socket created by the NGINX server). After the socket is matched, due to the three-way handshake in the TCP connection process, NGINX cannot immediately connect to TCP, so the NGINX connection cannot be created immediately. Therefore, the connection count obtained directly from the memory-mapped array is inaccurate and needs to be further adjusted.

[0101] In S5, a memory mapping is created. This memory mapping and the memory mapping array use the same physical memory, so when the number of connections changes, NGINX simply writes the change information to the corresponding location in this memory mapping area, thus synchronizing the change information of the NGINX connection number to the memory mapping array. In this embodiment, this memory mapping area is referred to as the connection table.

[0102] Furthermore, after the step of creating the join table, the following steps are also included:

[0103] Synchronize the changes in the join table to the memory-mapped array.

[0104] In the above implementation process, the change information of the connection table is synchronized to the memory-mapped array to ensure that the connection table and the memory-mapped array can simultaneously obtain the adjustment information of NGINX's connection count.

[0105] If there are multiple worker threads in NGINX, mutual exclusion operations can be performed using thread locks.

[0106] Specifically, a connection_typs entry is added to the struct ngx_connection_s structure to record the server to which the connection belongs, thereby synchronizing the change information of the connection table to the memory-mapped array.

[0107] Furthermore, S6 includes:

[0108] Record the server corresponding to the socket;

[0109] The first preset value corresponding to the recorded server is added to the connection table after the synchronization change information to obtain the connection table after the first adjustment.

[0110] Adjust the connection table after the first adjustment.

[0111] In the above implementation process, adding the first preset value corresponding to the recorded server to the connection table after synchronization change information can make the connection status of the server corresponding to the socket be recorded and updated in real time, which makes it easy to directly obtain the change of the number of connections corresponding to the server in the connection table, and can effectively improve the adjustment efficiency.

[0112] When a socket is acquired, the server to which the socket belongs is recorded in connection_typs. At the same time, the connection count of the corresponding server in the connection table (i.e. shared memory) is incremented by 2. Optionally, the first preset value in this embodiment is 2. Each communication connection occupies two NGINX servers. Here, the socket is also treated as a communication connection, which can simplify the operation when releasing the connection later.

[0113] There are many ways to determine the server to which a socket belongs. You can determine it by port in NGINX, or you can add a field to mark it in the NGINX configuration.

[0114] Further steps for adjusting the join table after the first adjustment include:

[0115] The first signal transmission parameter in the socket is assigned a value, and the second preset value is added to the connection table after the first adjustment to obtain the connection table after the second adjustment.

[0116] Release the NGINX connection;

[0117] Determine whether the corresponding parameter value exists in the second signal transmission parameter during the process of releasing the NGINX connection;

[0118] If so, adjust the connection table after the second adjustment.

[0119] In the above implementation process, the changes in the number of connections generated during socket assignment and connection release can be displayed in the connection table, making it easier to know the changes in NGINX connections and making the adjustment of the number of connections more flexible.

[0120] In the function ngx_event_accept(), the first signaling parameter connection_type in the socket connection is assigned to the new NGINX connection, and the connection count of the corresponding server is incremented by 2 in the connection table. Optionally, the second preset value in this embodiment is 2.

[0121] In the function ngx_free_connection() that releases a connection, the second signaling parameter connection_type of the connection is checked. If there is a corresponding parameter value, the connection count of the corresponding server in the connection table is reduced by 2, completing the second adjustment.

[0122] Compared to traditional methods, this embodiment of the application can directly handle packet loss when the NGINX connection limit is exceeded, without needing to reply with a SynchronizeSequenceNumbers (SYN) packet. This omits the packet exchange in the last two steps of the TCP three-way handshake and reduces the number of times NGINX uses the accept system call, effectively alleviating system pressure. Unlike traditional NGINX connection limit methods, this approach effectively limits the number of connections while allowing TCP connections exceeding the NGINX connection limit to continue normal communication and forwarding.

[0123] The limitation on the number of connections in this application embodiment is not directly reflected in NGINX, but implemented in the kernel. Modifying the number of NGINX connections without restarting NGINX can also easily achieve dynamic allocation of connections between different servers on NGINX, thus enabling load balancing of the number of NGINX connections.

[0124] Example 2

[0125] In order to execute the method corresponding to Embodiment 1 above and achieve the corresponding functions and technical effects, an apparatus for adjusting the number of NGINX connections is provided below, such as... Figure 3 As shown, the device includes:

[0126] Create module 1, which is used to create memory-mapped arrays; it is also used to create join tables.

[0127] Connection status acquisition module 2 is used to obtain the connection status of the data packet to be connected based on the structure status of the data packet to be connected.

[0128] Data acquisition module 3 is used to obtain the current number of connections to the server corresponding to NGINX based on the memory mapping array and the connection status;

[0129] Connection module 4 is used to connect the data packets to be connected to the NGINX according to the current number of connections and the connection status;

[0130] Adjustment module 5 is used to adjust the current number of NGINX connections after connecting to the data packets to be connected, based on the connection table and the sockets in NGINX.

[0131] In the above implementation process, data packets are connected to NGINX based on the current number of connections and the connection status. The current number of connections is adjusted according to the connection table and sockets. This allows for flexible adjustment of the number of NGINX connections, making communication connections smoother and preventing delays or stuttering. It also eliminates the need to restart NGINX, thus avoiding waste of resources and performance.

[0132] Furthermore, the connection status acquisition module 2 is also used for:

[0133] Determine if the structure state is a preset state;

[0134] If so, determine the connection status of the data packet to be connected as a waiting connection state;

[0135] If not, the connection status of the data packet to be connected is determined to be an unconnectable state.

[0136] In the above implementation process, the connection status of data packets is determined based on the status of the mechanism, which can quickly distinguish the data packets to be connected, improve the efficiency of communication connection, and avoid lag and delay.

[0137] Furthermore, the data acquisition module 3 is also used for:

[0138] When the connection status of the data packet to be connected is determined to be in the waiting connection state, obtain the NGINX server corresponding to the data packet to be connected;

[0139] Read the location information of the NGINX server corresponding to the data packet to be connected in the memory-mapped array to obtain the number of connections to the NGINX server;

[0140] Read the queue length of the data packets to be connected based on the structure of the data packets to be connected;

[0141] Get the number of unconnected servers for NGINX based on the queue length;

[0142] The current number of connections is obtained based on the number of connected connections and the number of unconnected connections. The current number of connections is stored in a memory-mapped array.

[0143] In the above implementation process, the current number of connections is obtained based on the number of connections and the number of disconnections. This allows for a clear understanding of the connection status between the data packets to be connected and the NGINX server, facilitating adjustments to the current number of connections and effectively shortening the connection time.

[0144] Furthermore, the connection module 4 is also used for:

[0145] Get the configured connection limit for the NGINX server;

[0146] Determine if the current number of connections is less than the set number of connections;

[0147] If so, connect the data packet to be connected to NGINX.

[0148] In the above implementation process, the system determines whether a data packet to be connected to NGINX can be connected based on the set number of connections and the current number of connections. This effectively utilizes the NGINX server and avoids resource consumption and connection congestion.

[0149] Furthermore, the device also includes a synchronization module for:

[0150] Synchronize the changes in the join table to the memory-mapped array.

[0151] In the above implementation process, the change information of the connection table is synchronized to the memory-mapped array to ensure that the connection table and the memory-mapped array can simultaneously obtain the adjustment information of NGINX's connection count.

[0152] Furthermore, adjustment module 5 is also used for:

[0153] Record the server corresponding to the socket;

[0154] The first preset value corresponding to the recorded server is added to the connection table after the synchronization change information to obtain the connection table after the first adjustment.

[0155] Adjust the connection table after the first adjustment.

[0156] In the above implementation process, adding the first preset value corresponding to the recorded server to the connection table after synchronization change information can make the connection status of the server corresponding to the socket be recorded and updated in real time, which makes it easy to directly obtain the change of the number of connections corresponding to the server in the connection table, and can effectively improve the adjustment efficiency.

[0157] Furthermore, adjustment module 5 is also used for:

[0158] The first signal transmission parameter in the socket is assigned a value, and the second preset value is added to the connection table after the first adjustment to obtain the connection table after the second adjustment.

[0159] Release the NGINX connection;

[0160] Determine whether the corresponding parameter value exists in the second signal transmission parameter during the process of releasing the NGINX connection;

[0161] If so, adjust the connection table after the second adjustment.

[0162] In the above implementation process, the changes in the number of connections generated during socket assignment and connection release can be displayed in the connection table, making it easier to know the changes in NGINX connections and making the adjustment of the number of connections more flexible.

[0163] The apparatus for adjusting the number of NGINX connections described above can implement the method of Embodiment 1. The options in Embodiment 1 also apply to this embodiment, and will not be described in detail here.

[0164] The remaining contents of this embodiment can be referred to the contents of Embodiment 1 above, and will not be repeated in this embodiment.

[0165] Example 3

[0166] This application provides an electronic device, including a memory and a processor. The memory stores a computer program, and the processor runs the computer program to cause the electronic device to perform the method for adjusting the number of NGINX connections as described in Embodiment 1.

[0167] Alternatively, the aforementioned electronic device may be a server.

[0168] Please see Figure 3 , Figure 3 This is a schematic diagram illustrating the structural composition of an electronic device provided in an embodiment of this application. The electronic device may include a processor 31, a communication interface 32, a memory 33, and at least one communication bus 34. The communication bus 34 is used to enable direct communication between these components. In this embodiment, the communication interface 32 is used for signaling or data communication with other node devices. The processor 31 may be an integrated circuit chip with signal processing capabilities.

[0169] The processor 31 described above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor, or the processor 31 can be any conventional processor.

[0170] The memory 33 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc. The memory 33 stores computer-readable instructions. When these computer-readable instructions are executed by the processor 31, the device can perform the aforementioned operations. Figure 1 The various steps involved in the method implementation examples.

[0171] Optionally, the electronic device may also include a storage controller and an input / output unit. The memory 33, storage controller, processor 31, peripheral interface, and input / output unit are electrically connected directly or indirectly to each other to achieve data transmission or interaction. For example, these components can be electrically connected to each other via one or more communication buses 34. The processor 31 is used to execute executable modules stored in the memory 33, such as software function modules or computer programs included in the device.

[0172] Input / output units are used to enable users to create tasks and set optional start periods or preset execution times for those tasks, facilitating user-server interaction. Input / output units can be, but are not limited to, a mouse and keyboard.

[0173] Understandable. Figure 3 The structure shown is for illustrative purposes only; the electronic device may also include components that are more advanced than those shown. Figure 3 The more or fewer components shown, or having the same Figure 3 The different configurations shown. Figure 3 The components shown can be implemented using hardware, software, or a combination thereof.

[0174] In addition, this application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method for adjusting the number of NGINX connections in Embodiment 1.

[0175] This application also provides a computer program product that, when run on a computer, causes the computer to perform the method described in the method embodiment.

[0176] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using dedicated hardware-based apparatus that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0177] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0178] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, external hard drives, ROM, RAM, magnetic disks, or optical disks.

[0179] The above description is merely an embodiment of this application and is not intended to adjust the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0180] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of protection of the claims.

[0181] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further modification, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A method for adjusting NGINX connection number, characterized in that, The method includes: Create a memory-mapped array; The connection status of the data packet to be connected is obtained based on the structure status of the data packet to be connected. The current number of connections to the server corresponding to NGINX is obtained based on the memory mapping array and the connection status; Connect the data packet to be connected to the NGINX based on the current number of connections and the connection status; Create a join table; Synchronize the changes in the join table to the memory-mapped array; The current number of connections in NGINX is adjusted based on the connection table and the sockets in NGINX after connecting the data packet to be connected; The step of adjusting the current number of connections in NGINX after connecting the data packet to be connected according to the connection table and the socket in NGINX includes: Record the server corresponding to the socket; The first preset value corresponding to the recorded server is added to the connection table after the synchronization change information to obtain the connection table after the first adjustment. The connection table after the first adjustment is then adjusted; The step of adjusting the join table after the first adjustment includes: The first signal transmission parameter in the socket is assigned a value, and the second preset value is added to the connection table after the first adjustment to obtain the connection table after the second adjustment. In this process, the first signal transmission parameter in the socket connection is assigned to the new NGINX connection, and the connection count of the corresponding server is added to the second preset value in the connection table. Release the NGINX connection; Determine whether a corresponding parameter value exists in the second signal transmission parameter during the process of releasing the NGINX connection; If so, the connection table after the second adjustment is adjusted, wherein the second signal transmission parameter of the connection is judged in the function of releasing the connection, and if there is a corresponding parameter value, the connection count of the corresponding server in the connection table is reduced by a second preset value. Both the first signal transmission parameter and the second signal transmission parameter are connection types.

2. The method for adjusting the number of NGINX connections according to claim 1, characterized in that, The step of obtaining the connection status of the data packet to be connected based on the structure status of the data packet to be connected includes: Determine whether the structure state is a preset state; If so, determine that the connection status of the data packet to be connected is a waiting connection state; If not, the connection status of the data packet to be connected is determined to be an unconnectable state.

3. The method for adjusting the number of NGINX connections according to claim 2, characterized in that, When the connection status of the data packet to be connected is determined to be in a waiting connection state, the step of obtaining the current connection count of the server corresponding to NGINX based on the memory mapping array and the connection status includes: Obtain the NGINX server corresponding to the data packet to be connected; Read the location information of the NGINX server corresponding to the data packet to be connected in the memory-mapped array to obtain the number of connections of the NGINX server; The queue length of the data packet to be connected is read according to the structure of the data packet to be connected; The number of unconnected servers of the NGINX server is obtained based on the queue length; The current connection count is obtained based on the number of connections and the number of unconnected connections, and the current connection count is stored in the memory-mapped array.

4. The method for adjusting the number of NGINX connections according to claim 1, characterized in that, The step of connecting the data packet to be connected to the NGINX based on the current number of connections and the connection status includes: Obtain the set connection limit for the NGINX server; Determine whether the current number of connections is less than the set number of connections; If so, connect the data packet to be connected to the NGINX.

5. A device for adjusting the number of NGINX connections, characterized in that, The device includes: The module is used to create memory-mapped arrays and also to create join tables. A connection status acquisition module is used to obtain the connection status of the data packet to be connected based on the structure status of the data packet to be connected. The data acquisition module is used to obtain the current number of connections to the server corresponding to the NGINX based on the memory mapping array and the connection status; A connection module is used to connect the data packet to be connected to the NGINX based on the current number of connections and the connection status; The synchronization module is used to synchronize the change information of the connection table to the memory-mapped array; An adjustment module is used to adjust the current number of connections in NGINX after connecting the data packet to be connected, based on the connection table and the sockets in NGINX; Record the server corresponding to the socket; The first preset value corresponding to the recorded server is added to the connection table after the synchronization change information to obtain the connection table after the first adjustment. The connection table after the first adjustment is then adjusted; The device further includes: The step of adjusting the join table after the first adjustment includes: The process involves assigning a value to the first signal transmission parameter in the socket and adding a second preset value to the connection table after the first adjustment to obtain the connection table after the second adjustment. It also includes assigning the first signal transmission parameter in the socket connection to the new NGINX connection and adding the second preset value to the connection table to count the number of connections to the corresponding server. Release the NGINX connection; Determine whether a corresponding parameter value exists in the second signal transmission parameter during the process of releasing the NGINX connection; If so, adjusting the connection table after the second adjustment also includes: judging the second signal transmission parameter of the connection in the function of releasing the connection; if there is a corresponding parameter value, then subtracting the second preset value from the connection count of the corresponding server in the connection table. Both the first signal transmission parameter and the second signal transmission parameter are connection types.

6. An electronic device, characterized in that, The device includes a memory and a processor, the memory being used to store a computer program, and the processor running the computer program to cause the electronic device to perform the method of adjusting the number of NGINX connections according to any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by a processor, implements the method for adjusting the number of NGINX connections as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Data processing method and system and virtual switch

    CN114268594A