Transmission behavior optimization method, device and equipment for forwarding QUIC protocol data based on Nginx
By replacing the event processor when the buffer is full and using the epoll event loop, the problems of high memory usage and increased load balancer overhead caused by buffer fullness in the prior art are solved, and more efficient and stable data processing is achieved.
Patent Information
- Application Number
- CN202411977415.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-15
AI Technical Summary
When the buffer is full, the existing technology adopts the method of constantly creating temporary buffers, which leads to a surge in memory usage and increases the overhead and burden of load balancers.
When the buffer is full, replace the initial event processor as the target event processor and switch to the event processing loop. Epoll's efficient multiplexed IO multiplexing mechanism is used to process other events in a timely manner to avoid blocking the data reception function, and write the data in the buffer to the upstream service when the upstream service can be written.
By reducing the use of temporary buffers, memory usage and load balancer overhead are reduced, and data processing efficiency and stability are improved.
Smart Images

Figure CN119835238A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a transmission behavior optimization method, device and equipment based on Nginx forwarding QUIC protocol data. Background Art
[0002] The QUIC (Quick UDP Internet Connections) protocol is suitable for scenarios with poor network signals and frequent network switching. Through the QUIC protocol, available services can still be provided under severe network delays. In scenarios where ALB (Application Load Balancer) supports the QUIC protocol, a QUIC listener can be created to forward QUIC protocol requests to actual services.
[0003] Currently, streaming processing is used by default for QUIC uploads, that is, the "buffering while uploading" method, which is also the preferred forwarding method of ALB. However, during streaming processing, the data sending rate requested by the client cannot match the receiving rate of the upstream service well, resulting in the buffer being easily filled. In the prior art, when the buffer is full, a temporary buffer is continuously created to buffer the data that cannot be forwarded in time.
[0004] However, this method of creating temporary buffers can easily lead to high memory usage, increasing the overhead and burden of the load balancer. Summary of the invention
[0005] The present application provides a method, device and equipment for optimizing transmission behavior of QUIC protocol data forwarding based on Nginx, so as to solve the problem in the prior art that when the buffer is full, a temporary buffer is continuously created to buffer the data that cannot be forwarded in time, which easily leads to a surge in memory usage and increases the overhead and burden of the load balancer.
[0006] In a first aspect, the present application provides a method for optimizing transmission behavior based on Nginx forwarding QUIC protocol data, including:
[0007] In the process of the QUIC listener receiving data sent by the client, calling the data receiving function to write the data received by the QUIC listener into the buffer;
[0008] In the process of calling the data receiving function to write the data into the buffer, determining whether the buffer is full;
[0009] When the buffer is full, determining whether the upstream service corresponding to the buffer is in a writable state;
[0010] When the upstream service is in a non-writable state, the initial event handler used to write data to the upstream service is replaced with the target event handler, and the activation flag of the QUIC listener read event is turned off, and the data receiving function is returned to switch to the event processing loop;
[0011] Using the event processing loop to trigger calling the target event processor to write the data in the buffer into the upstream service when the upstream service is in a writable state;
[0012] After the event processing loop triggers the call to the target event handler to write the data in the buffer to the upstream service, the data receiving function is called back and the activation flag of the QUIC listener read event is turned on to continue writing the data received by the QUIC listener to the buffer using the data receiving function.
[0013] In a possible implementation, after the callback data receiving function is completed, the event handler of the upstream service is restored to the initial event handler.
[0014] In a possible implementation, the method further includes:
[0015] During the process of calling back the data receiving function, determining whether the buffer is full again;
[0016] When the buffer is full again, the target event handler is directly called to write the data in the buffer into the upstream service.
[0017] In a possible implementation, the method further includes:
[0018] When the upstream service is in a writable state, calling the initial event handler to read part of the data from the buffer, and writing part or all of the data to the upstream service;
[0019] After the initial event handler reads part or all of the data from the buffer and writes the part of the data to the upstream service, the data receiving function continues to read the received data and write it to the buffer, and determines whether the buffer is full again;
[0020] When the buffer is full again, the initial event handler is replaced by the target event handler, the activation flag of the QUIC listener read event is turned off, and the event processing loop is switched to the event processing loop. The event processing loop is used to trigger the call of the target event handler to write the data in the buffer to the upstream service when the upstream service is in a writable state.
[0021] In a possible implementation, determining whether the upstream service corresponding to the buffer is in a writable state includes:
[0022] Query the write event flag of the upstream service;
[0023] When the value of the write event flag is the first value, determining that the upstream service is in a writable state;
[0024] When the value of the write event flag is a second value, it is determined that the upstream service is in a non-writable state, wherein the first value and the second value are different.
[0025] In a possible implementation, the method further includes:
[0026] When the buffer is full, the QUIC listener is controlled to close the streaming upload function so as to forward the complete request data to the upstream service after the complete request data is cached.
[0027] In a possible implementation, the method further includes:
[0028] When the buffer is full, sending a first command frame to the client to stop the client from sending data;
[0029] After the data in the buffer is completely consumed by the upstream service, a second command frame is sent to the client to enable the client to continue sending data.
[0030] In a second aspect, the present application provides a transmission behavior optimization device based on Nginx forwarding QUIC protocol data, including:
[0031] A first calling module is used to call a data receiving function to write the data received by the QUIC listener into a buffer during the process of the QUIC listener receiving data sent by the client;
[0032] A first determining module, used for determining whether the buffer is full during the process of calling a data receiving function to write the data into the buffer;
[0033] A second determination module, configured to determine whether an upstream service corresponding to the buffer is in a writable state when the buffer is full;
[0034] The second calling module is used to replace the initial event handler used to write data to the upstream service with the target event handler when the upstream service is in a non-writable state, and at the same time turn off the activation flag of the QUIC listener read event, return from the data receiving function, and switch to the event processing loop;
[0035] A loop processing module, used for triggering the call of the target event processor to write the data in the buffer into the upstream service by using the event processing loop when the upstream service is in a writable state;
[0036] A callback module is used to call back the data receiving function and turn on the activation flag of the QUIC listener read event after the event processing loop triggers the call of the target event handler to write the data in the buffer into the upstream service, so as to continue to use the data receiving function to write the data received by the QUIC listener into the buffer.
[0037] In a possible implementation, the device further includes a restoration module, configured to:
[0038] After the callback data receiving function is completed, the event handler of the upstream service is restored to the initial event handler.
[0039] In a possible implementation manner, the device further includes a third calling module, configured to:
[0040] During the process of calling back the data receiving function, determining whether the buffer is full again;
[0041] When the buffer is full again, the target event handler is directly called to write the data in the buffer into the upstream service.
[0042] In a possible implementation manner, the device further includes a fourth calling module, configured to:
[0043] When the upstream service is in a writable state, calling the initial event handler to read part or all of the data from the buffer, and writing the part or all of the data to the upstream service;
[0044] After the initial event handler reads part or all of the data from the buffer and writes the part of the data to the upstream service, the data receiving function continues to read the received data and write it to the buffer, and determines whether the buffer is full again;
[0045] When the buffer is full again, the initial event handler is replaced by the target event handler, the activation flag of the QUIC listener read event is turned off, and the event processing loop is switched to the event processing loop. The event processing loop is used to trigger the call of the target event handler to write the data in the buffer to the upstream service when the upstream service is in a writable state.
[0046] In a possible implementation manner, the second determining module is specifically configured to:
[0047] Query the write event flag of the upstream service;
[0048] When the value of the write event flag is the first value, determining that the upstream service is in a writable state;
[0049] When the value of the write event flag is a second value, it is determined that the upstream service is in a non-writable state, wherein the first value and the second value are different.
[0050] In a possible implementation manner, the device further includes a closing module, which is used to:
[0051] When the buffer is full, the QUIC listener is controlled to close the streaming upload function so as to forward the complete request data to the upstream service after the complete request data is cached.
[0052] In a possible implementation manner, the device further includes a sending module, configured to:
[0053] When the buffer is full, sending a first command frame to the client to stop the client from sending data;
[0054] After the data in the buffer is completely consumed by the upstream service, a second command frame is sent to the client to enable the client to continue sending data.
[0055] In a third aspect, the present application provides a device comprising: a processor and a memory, wherein the processor is used to execute a transmission behavior optimization program based on Nginx forwarding QUIC protocol data stored in the memory, so as to implement the transmission behavior optimization method based on Nginx forwarding QUIC protocol data described in any one of the first aspects.
[0056] In a fourth aspect, the present application provides a storage medium storing one or more programs, which can be executed by one or more processors to implement the transmission behavior optimization method based on Nginx forwarding QUIC protocol data as described in any one of the first aspects.
[0057] The above-mentioned technical scheme provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application, in the process that the QUIC listener receives data sent by the client, calls the data receiving function to write the data received by the QUIC listener into the buffer; in the process that the data receiving function is called to write the data into the buffer, determines whether the buffer is full; when the buffer is full, determines whether the upstream service corresponding to the buffer is in a writable state; when the upstream service is in a non-writable state, replaces the initial event handler used to write data to the upstream service with the target event handler, and at the same time turns off the activation flag of the QUIC listener read event, returns from the data receiving function, and switches to the event processing loop; uses the event processing loop to trigger the call of the target event handler to write the data in the buffer into the upstream service when the upstream service is in a writable state; after the event processing loop triggers the call of the target event handler to write the data in the buffer into the upstream service, calls back the data receiving function, turns on the activation flag of the QUIC listener read event, and uses the data receiving function to continue to write the data received by the listener into the buffer. Through this application, the efficient multi-channel IO multiplexing mechanism of epoll (event poll, I / O multiplexing technology) can be utilized. After the buffer is full, the original write event handler of the upstream service can be replaced in time and switched to the event processing loop. In this way, other events can be processed in time to avoid being blocked by the current data receiving function, and the data in the buffer can be written to the upstream service in time when the upstream service is writable. There is no need to expand the temporary buffer in the process, thereby reducing the overhead and burden of the load balancer. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0059] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0060] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0061] Figure 1A flow chart of an embodiment of a method for optimizing transmission behavior based on Nginx forwarding QUIC protocol data provided in an embodiment of the present application;
[0062] Figure 2 A flowchart of another embodiment of a method for optimizing transmission behavior based on Nginx forwarding QUIC protocol data provided in an embodiment of the present application;
[0063] Figure 3 A flowchart of another embodiment of a method for optimizing transmission behavior based on Nginx forwarding QUIC protocol data provided in an embodiment of the present application;
[0064] Figure 4 An overall implementation flow chart of a transmission behavior optimization method based on Nginx forwarding QUIC protocol data provided in an embodiment of the present application;
[0065] Figure 5 Another processing flow diagram provided in an embodiment of the present application in which Handler A is replaced with Handler B but not restored to Handler A, and the buffer is filled up again;
[0066] Figure 6 A block diagram of an embodiment of a transmission behavior optimization device based on Nginx forwarding QUIC protocol data provided in an embodiment of the present application;
[0067] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0068] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0069] The disclosure below provides many different embodiments or examples to realize the different structures of the present application. In order to simplify the disclosure of the present application, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present application. In addition, the present application can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0070] In order to solve the technical problem in the prior art that when the buffer is full, a temporary buffer is continuously created to buffer the data that cannot be forwarded in time, which easily leads to a surge in memory usage and increases the overhead and burden of the load balancer, the present application provides a transmission behavior optimization method based on Nginx forwarding QUIC protocol data. The method can utilize the efficient multi-channel IO multiplexing mechanism of epoll. After the buffer is full, the original upstream service write event processor is replaced in time and switched to the event processing loop. In this way, other events can be processed in time to avoid being blocked by the current data receiving function, and the data in the buffer can be written to the upstream service in time when the upstream service is writable. In the process, there is no need to expand the temporary buffer additionally, thereby reducing the overhead and burden of the load balancer.
[0071] Figure 1 The embodiment of the present application provides a flow chart of an embodiment of a method for optimizing the transmission behavior of QUIC protocol data forwarded by Nginx. The load balancing device used in the cloud computing network can adapt to various underlying QUIC libraries, such as Figure 1 As shown, the method comprises the following steps:
[0072] Step 101: During the process of the QUIC listener receiving data sent by the client, a data receiving function is called to write the data received by the QUIC listener into a buffer.
[0073] The embodiment of the present application provides a transmission behavior optimization method based on Nginx forwarding QUIC protocol data, which can be applied to the scenario where ALB (Application Load Balancer) supports the QUIC protocol. Among them, ALB is a load balancing service specifically for application layer load scenarios of HTTP and HTTPS, which can achieve exclusive performance, resource isolation, super elasticity and large-scale application layer traffic processing capabilities. The QUIC (Quick UDP Internet Connections) protocol is a network transmission protocol developed by Google and standardized in the Internet Engineering Task Force (IETF). It is based on UDP, rather than traditional TCP, and is mainly used to speed up web page loading and improve connection performance. QUIC integrates the characteristics of multiplexing, low-latency encryption and fast reconnection, which can reduce the delay of the first connection and data transmission. Compared with traditional TCP+TLS, QUIC is more suitable for modern Internet applications, especially in unstable or high-latency network environments, and performs better.
[0074] The above-mentioned client refers to a program that initiates a request using the QUIC protocol. In actual applications, it can be an App (Application) or a browser.
[0075] The above-mentioned QUIC listener is the basic working unit of ALB. Business traffic is load balanced through the QUIC listener, which refers to the UDP listener configured with the QUIC protocol.
[0076] The above data receiving function is used to write the data received by the QUIC listener into the buffer. In the application, it can be the http3 upload function, where http3 is the latest version of the HTTP protocol, based on the QUIC transmission protocol. http3 uses UDP, which can reduce the delay in connection establishment and improve data transmission efficiency. It integrates encryption functions (TLS1.3) and supports multiplexing, 0-RTT connection recovery and other features, improving performance in environments with high network packet loss and latency.
[0077] In an embodiment of the present application, the QUIC listener implements streaming processing of data based on the QUIC protocol, that is, in the process of the QUIC listener receiving data sent by the client, the data receiving function is called to write the data received by the QUIC listener into a pre-configured ring buffer. The size of the buffer is fixed and is set by the configuration parameters at startup, generally about 64KiB for each connection.
[0078] Step 102: In the process of calling the data receiving function to write the data into the buffer, determine whether the buffer is full.
[0079] Step 103: When the buffer is full, determine whether the upstream service corresponding to the buffer is in a writable state.
[0080] Step 104: When the upstream service is in a non-writable state, the initial event handler used to write data to the upstream service is replaced with the target event handler, and the activation flag of the QUIC listener read event is turned off, and the data receiving function is returned to switch to the event processing loop.
[0081] Step 105: Utilize the event processing loop to trigger calling the target event handler to write the data in the buffer into the upstream service when the upstream service is in a writable state.
[0082] Step 106: After the event processing loop triggers the call to the target event handler to write the data in the buffer into the upstream service, the data receiving function is called back and the activation flag of the QUIC listener read event is turned on to continue writing the data received by the QUIC listener into the buffer using the data receiving function.
[0083] For ease of understanding, steps 102 to 106 are described in a unified manner as follows:
[0084] The upstream service mentioned above refers to the backend business server to which the QUIC listener needs to forward the client's business traffic.
[0085] A Handler (event processor) is a function or method that is triggered when an event occurs and performs the corresponding operation. In programming, an event usually refers to an external input or a change in system status, such as a user clicking a button, network data arriving, or a timer timing out. These events will be registered with the corresponding Handler. When the relevant event is triggered, the corresponding Handler will be directly called and run by the event response model.
[0086] The above initial event handler refers to a Handler used to read data in the buffer and write the data to the upstream service in a normal state (ie, when the buffer is not full).
[0087] The above target event handler is a custom Handler, which is used to process data in conjunction with the event processing loop when the buffer is full.
[0088] The above event processing loop refers to the epoll event loop, which is an efficient I / O multiplexing mechanism provided by Linux, mainly used to handle a large number of concurrent connections. Compared with traditional select and poll, epoll can better handle a large number of file descriptors, supports edge trigger (ET) and level trigger (LT) modes, and its performance will not decrease significantly with the increase of the number of connections. It reduces unnecessary system calls through the event notification mechanism and is widely used in high-performance network servers and applications. In the application, the event loop processor of Nginx can be implemented through epoll. Nginx is a high-performance open source web server and reverse proxy server, which is often used to handle a large number of concurrent connections and high-traffic sites. It excels in the rapid distribution of static content, and can also be used as a load balancer and API gateway to optimize the performance of backend services. Nginx has excellent stability, efficiency and low resource consumption, and is widely used in various websites and cloud services.
[0089] In actual applications, when the client sends data too fast and the upstream service cannot consume it in time or is busy and cannot write, the buffer is easily filled.
[0090] In order to deal with this situation, in an embodiment of the present application, in the process of calling the data receiving function to write data into the buffer, the situation of the buffer will be monitored to determine whether the buffer is full. When the buffer is full, first, determine whether the upstream service corresponding to the buffer is in a writable state. If the upstream service is not writable, replace the initial event handler used to write data to the upstream service with the target event handler, and turn off the QUIC listener read event activation flag, and return from the data receiving function, switch to the epoll event loop, and continue to process other events. At this time, it means that the subsequent epoll no longer waits for the QUIC listener to read the event, that is, it no longer reads the data sent by the QUIC client, and the data receiving function cannot be directly triggered by the epoll event loop. When the upstream service is in a writable state, the target event handler is triggered and called by the epoll event loop, and the original write operation and its related incidental business logic continue to be processed in the target event handler, and the data in the buffer is written to the upstream service. After writing the data in the buffer to the upstream service, there must be free space in the buffer, that is, it is in a writable state. At this time, the data receiving function is immediately called back, and the QUIC listener read event activation flag is turned on to continue reading the unread data into the buffer.
[0091] If the buffer is not full, continue to read the received data into the buffer until all the current data is read, at which time the data receiving function will exit normally.
[0092] In one embodiment, determining whether the upstream service corresponding to the buffer is in a writable state may include the following steps:
[0093] Query the write event flag of the upstream service; when the value of the write event flag is a first value, determine that the upstream service is in a writable state; when the value of the write event flag is a second value, determine that the upstream service is in a non-writable state, wherein the first value and the second value are different.
[0094] In this solution, when the flag bit ready is equal to 1 (i.e., the first value), the upstream service is in a writable state, and when the flag bit ready is equal to 0 (i.e., the second value), the upstream service is in a non-writable state. In this way, it is possible to quickly determine whether the upstream service is in a writable state based on the value assigned to the flag bit.
[0095] In another embodiment of the present application, the method may further include the following steps: after the callback data receiving function is completed, the event handler of the upstream service is restored to the initial event handler. In this way, in the next cycle, the initial event handler can continue to be used to perform the operation of writing data to the upstream service.
[0096] In another embodiment of the present application, the method may further include the following steps: when the buffer is full, controlling the QUIC listener to close the streaming upload function, so as to forward the complete request data to the upstream service after caching the complete request data to an external temporary file.
[0097] From the above description, it can be seen that in this solution, after the buffer is full, the streaming upload function is turned off and the complete request data is saved to a temporary file to skip the complex and cumbersome event handler Handler switching process.
[0098] In addition, in another embodiment of the present application, the method may further include the following steps: when the buffer is full, sending a first command frame to the client to make the client stop sending data, and after the data in the buffer is consumed by the upstream service, sending a second command frame to the client to make the client continue sending data.
[0099] In this solution, after the memory buffer is full, the first command frame (e.g., MAX_STREAM_DATA frame, MAX_DATA frame) is sent to the client through the QUIC protocol to stop the client from sending data. After the buffer data is consumed by the upstream service, the second command frame (e.g., MAX_STREAM_DATA frame, MAX_DATA frame) is sent to the client to resume transmission, thereby alleviating the cache pressure of the buffer.
[0100] The technical solution provided by the embodiment of the present application is as follows: in the process of the QUIC listener receiving data sent by the client, the data receiving function is called to write the data received by the QUIC listener into the buffer; in the process of calling the data receiving function to write the data into the buffer, it is determined whether the buffer is full; when the buffer is full, it is determined whether the upstream service corresponding to the buffer is in a writable state; when the upstream service is in a non-writable state, the initial event handler used to write data to the upstream service is replaced with the target event handler, and the activation flag of the QUIC listener read event is turned off, and the function returns from the data receiving function and switches to the event processing loop; the event processing loop is used to trigger the call of the target event handler to write the data in the buffer to the upstream service when the upstream service is in a writable state; after the event processing loop triggers the call of the target event handler to write the data in the buffer to the upstream service, the data receiving function is called back, and the QUIC listener read event activation flag is turned on to continue writing the data received by the listener into the buffer using the data receiving function. Through this application, the efficient multi-channel IO multiplexing mechanism of epoll (event poll, I / O multiplexing technology) can be utilized. After the buffer is full, the original upstream service write event processor can be replaced in time and switched to the event processing loop. In this way, other events can be processed in time to avoid being blocked by the current data receiving function, and the data in the buffer can be written to the upstream service in time when the upstream service is writable. There is no need to expand the temporary buffer in the process, thereby reducing the overhead and burden of the load balancer.
[0101] Figure 2 A flowchart of another embodiment of a method for optimizing transmission behavior based on Nginx forwarding QUIC protocol data provided in an embodiment of the present application. Figure 2 The process shown in Figure 1 Based on the process shown, the following steps are included:
[0102] Step 201: During the process of calling back the data receiving function, determine whether the buffer is full again.
[0103] Step 202: When the buffer is full again, directly call the target event handler to write the data in the buffer into the upstream service.
[0104] For ease of understanding, step 201 and step 202 are described in a unified manner as follows:
[0105] From the above description, it can be seen that in the embodiment of the present application, after the initial event handler is replaced with the target event handler for the first time, when the buffer is full again during the subsequent QUIC listener read event trigger data receiving function, the target event handler is directly called as the current write event handler of the upstream service, and there is no need to switch back to the initial event handler. In this way, the locality of program operation and the correlation of events can be guaranteed, and the operation efficiency can be improved.
[0106] Figure 3 A flowchart of another embodiment of a method for optimizing transmission behavior based on Nginx forwarding QUIC protocol data provided in an embodiment of the present application. Figure 3 The process shown in Figure 1 Based on the process shown, the following steps are included:
[0107] Step 301: When the upstream service is in a writable state, call the initial event handler to read part or all of the data from the buffer, and write the part or all of the data to the upstream service;
[0108] Step 302: After the initial event handler reads part or all of the data from the buffer and writes the part of the data to the upstream service, the data receiving function continues to read the received data and writes it to the buffer to determine whether the buffer is full again.
[0109] Step 303: When the buffer is full again, the initial event handler is replaced with the target event handler, and the activation flag of the QUIC listener read event is turned off, and the event processing loop is switched to. The event processing loop is used to trigger the call of the target event handler to write the data in the buffer to the upstream service when the upstream service is in a writable state.
[0110] From the above description, it can be seen that when the upstream service is in a writable state, the initial event handler can be called first to write part of the data in the buffer to the upstream service, and then the data receiving function can be used to execute the subsequent data receiving process to fill the available interval of the buffer. At this time, if the buffer is full again, it is considered that if the initial event handler is continued to be called, it is still easy to be full. Therefore, the initial event handler is replaced with the target event handler, and switched to the event processing loop. When the upstream service is in a writable state, the event processing loop triggers the call of the target event handler to write the data in the buffer to the upstream service.
[0111] Through this solution, when the upstream service is in a writable state, the initial event handler originally used to write data to the upstream service can be called first to perform the data writing operation, thereby reducing the switching operation of the event handler. After the buffer is full for the second time, the initial event handler is replaced with the target event handler and switched to the event processing loop. Thus, the data receiving function can be blocked from continuing to write data to the buffer, and other event responses can be processed in a timely manner. When the upstream service is writable, the data in the buffer can be written to the upstream service in a timely manner. No additional temporary buffer needs to be expanded during the process, thereby reducing the overhead and burden of the load balancer.
[0112] Figure 4 The overall implementation flow chart of a transmission behavior optimization method based on Nginx forwarding QUIC protocol data provided in the embodiment of the present application. Figure 4 As shown, the following steps are included:
[0113] S1. When the QUIC listener receives traffic sent by the client, it calls the http3-recv Handler (the event handler of the data receiving function) to write the data into the buffer.
[0114] S2. When the buffer is full, first determine whether the write event ready flag of the upstream service is available. If it is available, that is, the upstream service is in a writable state, immediately call the original upstream service write event Handler A once; after calling Handler A (that is, the initial event handler), if part of the buffer or all of the data can be read and written to the upstream service, continue the subsequent data receiving process to fill the available interval of the buffer.
[0115] S3. If the upstream service is in a non-writable state, replace the upstream service write event handler with the customized Handler B (i.e., the target event handler), set the QUIC listener read event active flag corresponding to http3-recv to 0, and then return to the epoll event loop to continue processing other events.
[0116] S4. If the buffer is filled again after Handler A is called (i.e., filled for the second time), then determine again whether the write event ready flag of the upstream service is available. If available, continue to call Handler A for processing, and repeat step S2 until the write event ready flag of the upstream service indicates that it is unavailable. When the upstream service is not writable, the upstream service write event handler is subsequently replaced with the customized Handler B, and the QUIC listener read event active flag corresponding to http3-recv is set to 0, and then return to the epoll event loop to continue processing other events.
[0117] S5. When the upstream service is writable, Handler B will be triggered and called by the epoll event loop. Handler B will continue to process the original write operation and its related accompanying business logic, and call back http3-recvHandler after the write is completed. At this time, the buffer must be writable, and its corresponding read event active is set to 1 again, and the data sent by the client that has not been read is continued to be read, and the above process is repeated. After the callback is completed, the write event handler of the upstream service is restored to Handler A; it can also be directly restored to Handler A, that is, the initial event handler, before calling back http3-recv.
[0118] also, Figure 5 Another processing flow diagram provided in the embodiment of the present application is to replace Handler A with Handler B but not restore it to Handler A, and the buffer is filled up again, such as Figure 5 As shown, the following steps are included:
[0119] S6. At the beginning of the http3-recv Handler operation, the wait_write flag is set to 0. The current write event Handler of the upstream service is Handler B, not the initial Handler A. When the buffer is full for the first time and the upstream service can be written, Handler B is directly called, and http3-recv is directly called back in Handler B; after returning from Handler B for the first time, the wait_write flag is set to 1. Subsequent http3-recv may continue to read the data sent by the client. When the buffer is full again, it can determine whether it can be written according to the ready flag of the upstream service, and decide whether to call Handler B again; because the wait_write flag is already 1, regardless of whether Handler B will be called for the second time, the subsequent fixed process will be followed, the event handler of the upstream service will be set to Handler B, and then return from the initial entry function http3-recv Handler. Because at the system kernel level, receiving and sending have their own buffers, Handler B can definitely make ready 0 after a limited number of writev operations; similarly, http3-recv may also read all the data in the system buffer directly after a limited number of recv operations. In this way, even if there are cyclic calls between functions, due to the reasonable setting of flags such as ready and wait_write, http3-recv can definitely be completed after a limited number of cycles. This can well ensure the locality of program operation and the correlation of events, and improve operation efficiency.
[0120] Figure 6 This is a block diagram of an embodiment of a transmission behavior optimization device based on Nginx forwarding QUIC protocol data provided in an embodiment of the present application. Figure 6 As shown, the device comprises:
[0121] A first calling module 61 is used to call a data receiving function to write the data received by the QUIC listener into a buffer during the process of the QUIC listener receiving data sent by the client;
[0122] A first determining module 62, configured to determine whether the buffer is full during the process of calling a data receiving function to write the data into the buffer;
[0123] A second determination module 63 is used to determine whether the upstream service corresponding to the buffer is in a writable state when the buffer is full;
[0124] The second calling module 64 is used to replace the initial event handler used to write data to the upstream service with the target event handler when the upstream service is in a non-writable state, and at the same time turn off the activation flag of the QUIC listener read event, return from the data receiving function, and switch to the event processing loop;
[0125] A loop processing module 65, configured to trigger calling the target event processor to write the data in the buffer into the upstream service by using the event processing loop when the upstream service is in a writable state;
[0126] The callback module 66 is used to call back the data receiving function and turn on the activation flag of the QUIC listener read event after the event processing loop triggers the call of the target event handler to write the data in the buffer into the upstream service, so as to continue to use the data receiving function to write the data received by the QUIC listener into the buffer.
[0127] In a possible implementation, the device further includes a restoration module, configured to:
[0128] After the callback data receiving function is completed, the event handler of the upstream service is restored to the initial event handler.
[0129] In a possible implementation manner, the device further includes a third calling module, configured to:
[0130] During the process of calling back the data receiving function, determining whether the buffer is full again;
[0131] When the buffer is full again, the target event handler is directly called to write the data in the buffer into the upstream service.
[0132] In a possible implementation manner, the device further includes a fourth calling module, configured to:
[0133] When the upstream service is in a writable state, calling the initial event handler to read part or all of the data from the buffer, and writing the part or all of the data to the upstream service;
[0134] After the initial event handler reads part or all of the data from the buffer and writes part or all of the data to the upstream service, the data receiving function continues to read the received data and write it to the buffer, and determines whether the buffer is full again;
[0135] When the buffer is full again, the initial event handler is replaced by the target event handler, the activation flag of the QUIC listener read event is turned off, and the event processing loop is switched to the event processing loop. The event processing loop is used to trigger the call of the target event handler to write the data in the buffer to the upstream service when the upstream service is in a writable state.
[0136] In a possible implementation manner, the second determining module is specifically configured to:
[0137] Query the write event flag of the upstream service;
[0138] When the value of the write event flag is the first value, determining that the upstream service is in a writable state;
[0139] When the value of the write event flag is a second value, it is determined that the upstream service is in a non-writable state, wherein the first value and the second value are different.
[0140] In a possible implementation manner, the device further includes a closing module, which is used to:
[0141] When the buffer is full, the QUIC listener is controlled to close the streaming upload function so as to forward the complete request data to the upstream service after the complete request data is cached.
[0142] In a possible implementation manner, the device further includes a sending module, configured to:
[0143] When the buffer is full, sending a first command frame to the client to stop the client from sending data;
[0144] After the data in the buffer is completely consumed by the upstream service, a second command frame is sent to the client to enable the client to continue sending data.
[0145] like Figure 7 As shown, an embodiment of the present application provides a device, including a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.
[0146] Memory 113, used for storing computer programs;
[0147] In one embodiment of the present application, the processor 111 is used to execute the program stored in the memory 113 to implement the transmission behavior optimization method based on Nginx forwarding QUIC protocol data provided by any of the aforementioned method embodiments, including:
[0148] In the process of the QUIC listener receiving data sent by the client, calling the data receiving function to write the data received by the QUIC listener into the buffer;
[0149] In the process of calling the data receiving function to write the data into the buffer, determining whether the buffer is full;
[0150] When the buffer is full, determining whether the upstream service corresponding to the buffer is in a writable state;
[0151] When the upstream service is in a non-writable state, the initial event handler used to write data to the upstream service is replaced with the target event handler, and the activation flag of the QUIC listener read event is turned off, and the data receiving function is returned to switch to the event processing loop;
[0152] Using the event processing loop to trigger calling the target event processor to write the data in the buffer into the upstream service when the upstream service is in a writable state;
[0153] After the event processing loop triggers the call to the target event handler to write the data in the buffer to the upstream service, the data receiving function is called back and the activation flag of the QUIC listener read event is turned on to continue writing the data received by the QUIC listener to the buffer using the data receiving function.
[0154] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the transmission behavior optimization method based on Nginx forwarding QUIC protocol data as provided in any of the aforementioned method embodiments are implemented.
[0155] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0156] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0157] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0158] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A transmission behavior optimization method based on Nginx forwarding QUIC protocol data, characterized in that: The method comprises: In the process of the QUIC listener receiving data sent by the client, calling the data receiving function to write the data received by the QUIC listener into the buffer; In the process of calling the data receiving function to write the data into the buffer, determining whether the buffer is full; When the buffer is full, determining whether the upstream service corresponding to the buffer is in a writable state; When the upstream service is in a non-writable state, the initial event handler used to write data to the upstream service is replaced with the target event handler, and the activation flag of the QUIC listener read event is turned off, and the data receiving function is returned to switch to the event processing loop; Using the event processing loop to trigger calling the target event processor to write the data in the buffer into the upstream service when the upstream service is in a writable state; After the event processing loop triggers the call to the target event handler to write the data in the buffer to the upstream service, the data receiving function is called back and the activation flag of the QUIC listener read event is turned on to continue writing the data received by the QUIC listener to the buffer using the data receiving function.
2. The method according to claim 1, characterized in that The method further comprises: After the callback data receiving function is completed, the event handler of the upstream service is restored to the initial event handler.
3. The method according to claim 1, characterized in that The method further comprises: During the process of calling back the data receiving function, determining whether the buffer is full again; When the buffer is full again, the target event handler is directly called to write the data in the buffer into the upstream service.
4. The method according to claim 1, characterized in that: The method further comprises: When the upstream service is in a writable state, calling the initial event handler to read part or all of the data from the buffer, and writing the part or all of the data to the upstream service; After the initial event handler reads part or all of the data from the buffer and writes part or all of the data to the upstream service, the data receiving function continues to read the received data and write it to the buffer, and determines whether the buffer is full again; When the buffer is full again, the initial event handler is replaced by the target event handler, the activation flag of the QUIC listener read event is turned off, and the event processing loop is switched to the event processing loop. The event processing loop is used to trigger the call of the target event handler to write the data in the buffer to the upstream service when the upstream service is in a writable state.
5. The method according to claim 1, characterized in that The determining whether the upstream service corresponding to the buffer is in a writable state includes: Query the write event flag of the upstream service; When the value of the write event flag is the first value, determining that the upstream service is in a writable state; When the value of the write event flag is a second value, it is determined that the upstream service is in a non-writable state, wherein the first value and the second value are different.
6. The method according to claim 1, characterized in that The method further comprises: When the buffer is full, the QUIC listener is controlled to close the streaming upload function so as to forward the complete request data to the upstream service after the complete request data is cached.
7. The method according to claim 1, characterized in that The method further comprises: When the buffer is full, sending a first command frame to the client to stop the client from sending data; After the data in the buffer is completely consumed by the upstream service, a second command frame is sent to the client to enable the client to continue sending data.
8. A transmission behavior optimization device based on Nginx forwarding QUIC protocol data, characterized in that: The device comprises: A first calling module is used to call a data receiving function to write the data received by the QUIC listener into a buffer during the process of the QUIC listener receiving data sent by the client; A first determining module, used for determining whether the buffer is full during the process of calling a data receiving function to write the data into the buffer; A second determination module, configured to determine whether an upstream service corresponding to the buffer is in a writable state when the buffer is full; The second calling module is used to replace the initial event handler used to write data to the upstream service with the target event handler when the upstream service is in a non-writable state, and at the same time turn off the activation flag of the QUIC listener read event, return from the data receiving function, and switch to the event processing loop; A loop processing module, used for triggering the call of the target event processor to write the data in the buffer into the upstream service by using the event processing loop when the upstream service is in a writable state; A callback module is used to call back the data receiving function and turn on the activation flag of the QUIC listener read event after the event processing loop triggers the call of the target event handler to write the data in the buffer into the upstream service, so as to continue to use the data receiving function to write the data received by the QUIC listener into the buffer.
9. A device, characterized in that: include: A processor and a memory, wherein the processor is used to execute a transmission behavior optimization program based on Nginx forwarding QUIC protocol data stored in the memory, so as to implement the transmission behavior optimization method based on Nginx forwarding QUIC protocol data as described in any one of claims 1-7.
10. A storage medium, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the transmission behavior optimization method based on Nginx forwarding QUIC protocol data as described in any one of claims 1-7.