Request processing method, device, computer-readable storage medium and electronic device

By asynchronously receiving and processing the call request, and querying the long connection in the connection pool of the target service, the problem of waste of connection pool maintenance resources in the existing technology is solved, and the data processing efficiency is improved.

CN113032139BActive Publication Date: 2025-01-24RUITING NETWORK TECH (SHANGHAI) CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202011631567.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-30
Publication Date
2025-01-24
Estimated Expiration
2040-12-30

AI Technical Summary

Technical Problem

In the prior art, a set of connection pools for multiple service processes is needed to be maintained, which wastes a lot of processing resources and reduces the data processing efficiency of electronic devices.

Method used

Require the call request sent by the second device for the second device, and when obtaining the service information, check the long connection between the first device and the second device from the connection pool of the target service, create a long connection communication process, asynchronous asynchronous, asynchronous Send service information.

Benefits of technology

Reduced the processing resources required to maintain the connection pool, improved the efficiency of service calls, and avoided the waste of resources caused by the maintenance of the connection pool in high concurrent scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113032139B_ABST
    Figure CN113032139B_ABST
Patent Text Reader

Abstract

The present application provides a request processing method, device, computer-readable storage medium and electronic device, which belongs to the field of computer technology. The method includes: asynchronously receiving a call request sent by a second device to a target service; when monitoring that service information has been obtained according to the call request, querying the long connection between the first device and the second device from the connection pool of the target service to create a long connection communication process for the long connection; and asynchronously sending the service information to the second device through the long connection communication process. This solution implements the communication process of the service to communicate by sharing a long connection in a connection pool in an asynchronous non-blocking manner, thereby reducing the processing resources required to maintain the connection pool and improving the efficiency of service calls.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of computer technology, and in particular, relates to a request processing method, device, computer-readable storage medium, and electronic device. Background Art

[0002] As a technology that can create and manage a buffer pool of connections between electronic devices, connection pooling can prevent used connections from being closed for subsequent reuse, effectively reducing the processing resources required to establish connections.

[0003] In the prior art, a connection pool is usually set for each service process. However, in a high-concurrency scenario, the service process needs to include multiple sub-service processes, so a connection pool needs to be generated for each sub-service process. This requires maintenance of a set of connection pools, which wastes a lot of processing resources and reduces the data processing efficiency of electronic devices. Summary of the invention

[0004] In view of this, the present application provides a request processing method, device, computer-readable storage medium and electronic device, which to a certain extent solves the problem in the prior art that a set of connection pools for multiple service processes needs to be maintained, which wastes a lot of processing resources and reduces the data processing efficiency of the electronic device.

[0005] According to a first aspect of the present application, a request processing method is provided, which is applied to a first device, and the method includes:

[0006] Asynchronously receiving a call request sent by a second device to a target service;

[0007] When it is monitored that the service information has been obtained according to the call request, querying the persistent connection between the first device and the second device from the connection pool of the target service to create a persistent connection communication process of the persistent connection;

[0008] The service information is asynchronously sent to the second device through the long connection communication process.

[0009] Optionally, before the asynchronously receiving the call request sent by the second device to the target service, the method further includes:

[0010] Asynchronously receiving a persistent connection request sent by the second device to the target service;

[0011] A persistent connection between the first device and the second device is established in the connection pool of the target service through a maintenance process, and a persistent connection establishment notification is asynchronously sent to the second device.

[0012] Optionally, before the asynchronously receiving the persistent connection request sent by the second device to the target service, the method further includes:

[0013] A maintenance process for maintaining each connection pool is created based on a user-defined process in an asynchronous network communication engine.

[0014] Optionally, after establishing a persistent connection between the first device and the second device in the connection pool of the target service through the maintenance process, and asynchronously sending a persistent connection establishment notification to the second device, the method further includes:

[0015] When the number of long connections in the connection pool is less than a quantity threshold, the number of long connections in the connection pool is expanded to be above the quantity threshold through the maintenance process.

[0016] Optionally, after establishing a persistent connection between the first device and the second device in the connection pool of the target service through the maintenance process, and asynchronously sending a persistent connection establishment notification to the second device, the method further includes:

[0017] When there are no idle long connections in the connection pool, a preset number of long connections are established in the connection pool through the maintenance process.

[0018] Optionally, before asynchronously sending the service information to the second device through the long connection communication process when the service information has been acquired according to the call request, the method further includes:

[0019] Monitoring the processing result of the call request;

[0020] When the processing result includes a communication event handle, it is determined that the service information has been acquired.

[0021] Optionally, the long connection communication process of creating the long connection includes:

[0022] The long connection communication process of the long connection is created based on the task subprocess in the abnormal network communication engine.

[0023] According to a second aspect of the present application, a request processing device is provided, which may include:

[0024] A receiving module, configured to asynchronously receive a call request sent by the second device to the target service;

[0025] a query module configured to query the persistent connection between the first device and the second device from the connection pool of the target service when it is monitored that the service information has been obtained according to the call request, so as to create a persistent connection communication process of the persistent connection;

[0026] The sending module is configured to asynchronously send the service information to the second device through the long connection communication process.

[0027] Optionally, the device further comprises:

[0028] The maintenance module is configured as follows:

[0029] Asynchronously receiving a persistent connection request sent by the second device to the target service;

[0030] A persistent connection between the first device and the second device is established in the connection pool of the target service through a maintenance process, and a persistent connection establishment notification is asynchronously sent to the second device.

[0031] Optionally, the maintenance module is further configured to:

[0032] A maintenance process for maintaining each connection pool is created based on a user-defined process in an asynchronous network communication engine.

[0033] Optionally, the maintenance module is further configured to: when the number of long connections in the connection pool is less than a quantity threshold, expand the number of long connections in the connection pool to above the quantity threshold through the maintenance process.

[0034] Optionally, the maintenance module is further configured to:

[0035] When there are no idle long connections in the connection pool, a preset number of long connections are established in the connection pool through the maintenance process.

[0036] Optionally, the query module is further configured to:

[0037] Monitoring the processing result of the call request;

[0038] When the processing result includes a communication event handle, it is determined that the service information has been acquired.

[0039] Optionally, the query module is further configured to:

[0040] The long connection communication process of the long connection is created based on the task subprocess in the abnormal network communication engine.

[0041] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the request processing method described in the first aspect are implemented.

[0042] In a fourth aspect, the present application provides an electronic device comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the request processing method described in the first aspect are implemented.

[0043] Compared with the prior art, this application has the following advantages:

[0044] The embodiments of the present application provide a request processing method, device, computer-readable storage medium and electronic device. The solution implements communication through an asynchronous and non-blocking manner, in which the communication processes of the services share a long connection in a connection pool for communication, thereby reducing the processing resources required to maintain the connection pool and improving the efficiency of service calls. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0046] Figure 1 It is a flowchart of a request processing method provided by an embodiment of the present application;

[0047] Figure 2 is a flowchart of another request processing method provided by an embodiment of the present application;

[0048] Figure 3 It is a flowchart of the steps of a connection pool management method provided in an embodiment of the present application;

[0049] Figure 4 is a structural block diagram of a request processing device provided in an embodiment of the present application;

[0050] Figure 5 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0051] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.

[0052] The request processing method in the embodiment of the present application is described in detail below.

[0053] Figure 1is a flowchart of a request processing method provided by an embodiment of the present application, which is applied to a first device. The method may include:

[0054] Step 101: asynchronously receive a call request sent by a second device to a target service.

[0055] In the embodiment of the present application, the first device and the second device are electronic devices with functions such as data processing, storage, and transmission. The first device and the second device can exchange data through a communication connection. For the sake of convenience, the first device is used as the service callee, and the second device is used as the service caller. In actual applications, the first device and the second device can be replaced. The target service is a service that the second device needs to call from the first device. For the first device, the service process of the target service may need to provide service information for multiple second devices at the same time. Therefore, it is usually necessary to set multiple sub-service processes in the target service to improve the processing efficiency of the service process to adapt to the high concurrency requirements of the call request. With the increase in the number of processes, if a synchronous communication method is adopted, if the first device cannot feedback the service information in time when receiving the call request sent by the second device, the first device and the second device need to maintain a connection for a long time, which wastes the processing resources of the first device. Therefore, this solution adopts an asynchronous communication method, and immediately feedbacks the response information to end the communication process after receiving the call request from the second device, thereby reducing the processing resources of the first device.

[0056] Step 102, when it is monitored that the service information has been obtained according to the call request, query the persistent connection between the first device and the second device from the connection pool of the target service to create a persistent connection communication process of the persistent connection.

[0057] In an embodiment of the present application, a connection pool is a buffer pooling area for a long connection of a storage service process, and the long connection can make the connection completed by the user between devices not closed, so as to be reused for the next communication. Generally, it is necessary to create a connection pool for the service process of each service, so when a sub-service process is included under the service process, it is necessary to generate a connection pool for each sub-service process, and when an individual sub-service process is destroyed, it is necessary to initialize all sub-service processes in the service process, resulting in a waste of processing resources. Therefore, an embodiment of the present application reduces the processing resources required for maintaining the connection pool by sharing a connection pool among each sub-service process in the service process of the target service. If multiple sub-service processes are to share a connection pool, it is necessary to ensure the effective utilization of long connections in the connection pool and to ensure that multiple sub-service processes can run. If a blocking communication waiting method is adopted, that is, the long connection communication process is suspended while waiting for service information to be generated, it will obviously reduce the effective utilization rate of the long connection. Therefore, the embodiment of the present application adopts a non-blocking communication waiting method, that is, the long connection between the first device and the second device is obtained from the connection pool to create a long connection communication process when the service information is obtained. While waiting for the service information to be obtained, the long connection communication process is closed and the long connection in the connection pool is no longer occupied, thereby effectively improving the effective utilization rate of the long connection in the connection pool and further reducing the processing resources of the first device to process the call request.

[0058] Step 103: asynchronously send the service information to the second device through the long connection communication process.

[0059] In the embodiment of the present application, the method of asynchronously receiving the call request in step 101 is adapted, and the first device also adopts an asynchronous communication method when sending service information to the second device, that is, actively sending service information to the second device in the form of notification, etc., and the second device does not need to wait for the service information, but only needs to be passive, so that the first device will run the long connection communication process with the second device only when it has obtained the service information, thereby reducing the processing resources required for the first device to process the call request.

[0060] A request processing method provided in an embodiment of the present application implements communication by using an asynchronous non-blocking method so that the communication processes of services share a long connection in a connection pool for communication, thereby reducing the processing resources required to maintain the connection pool and improving the efficiency of service calls.

[0061] Figure 2 is a flowchart of another request processing method provided in an embodiment of the present application, which is applied to a first device. The method may include:

[0062] Step 201: asynchronously receive a call request sent by a second device to a target service.

[0063] This step can refer to the detailed description of step 101 and will not be repeated here.

[0064] Step 202: monitor the processing result of the call request.

[0065] Step 203: When the processing result includes a communication event handle, it is determined that the service information has been acquired.

[0066] For the above steps 202 and 203, the three inter-process communication methods provided by the existing asynchronous network communication engine (swoole) are task subprocess (Task), user-defined process (UserProcess), and process pool (Process\Pool). Since only Task and UserProcess support the creation of sub-service processes, but Task and UserProcess can only implement synchronous blocking communication waiting methods, the embodiment of the present application introduces the Socket communication method, no longer using the native inter-process communication method encapsulated by swoole, and uses Socket communication instead. Its communication method is UnixSocket (a method in which Socket implements the function of inter-process communication), and 1 million reads and writes between processes only take 1.2 seconds to complete. Each long connection communication process will have a handle fd, and fd is added to the epoll event monitoring through the swoole_event_add method. The bottom layer will automatically be set to non-blocking mode, thereby realizing asynchronous non-blocking inter-process communication. That is, the acquired event of the service information is monitored by the handle in the processing result, so as to trigger the long connection communication process between the first device and the second device when the service information is obtained.

[0067] Step 204, when it is monitored that the service information has been obtained according to the call request, query the long connection between the first device and the second device from the connection pool of the target service to create a long connection communication process of the long connection based on the task subprocess in the abnormal network communication engine.

[0068] In an embodiment of the present application, since the task subprocess (Task) in the asynchronous network communication engine (swoole) supports the management of generating multiple sub-service processes, a Task process can be generated as a long connection communication process, thereby improving the processing efficiency of the service process.

[0069] Step 205: asynchronously send the service information to the second device through the long connection communication process.

[0070] This step can refer to the detailed description of step 103 and will not be repeated here.

[0071] Optionally, the connection pool can be Figure 3A connection pool management method is pre-created, the method comprising:

[0072] Step 206: Create a maintenance process for maintaining each connection pool based on the user-defined process in the asynchronous network communication engine.

[0073] In the embodiment of the present application, since the business coupling degree of Task in swoole is very high, many other tasks need to be completed in Task, including heartbeat reporting, business log, statistical management, etc., the core function of connection pool cannot be put into Task for processing. Therefore, we can use UserProcess to create an independent maintenance process, which is responsible for maintaining all connection pools without interference from other processes, thereby ensuring the normal use of the connection pool.

[0074] Step 207: asynchronously receive a long connection request sent by the second device to the target service.

[0075] Step 208: Establish a persistent connection between the first device and the second device in the connection pool of the target service through a maintenance process, and asynchronously send a persistent connection establishment notification to the second device.

[0076] For step 207 and step 208, the maintenance process can also communicate with the process in the second device through an asynchronous non-blocking communication method, so that after receiving the long connection request sent by the second device to the target service, it directly feedbacks and establishes a long connection in the connection pool of the service process of the target service, and actively sends a long connection establishment notification to the second device, so that the second device can be free from language restrictions and only needs to establish socket communication to call mysql (a relational database), wredis (a key-value database), wtable (a hive database), scf (a complete set of general frameworks that can be used to build basic projects), http (HyperText Transfer Protocol), tcp (Transmission Control Protoco, transport layer communication protocol) and other types of connection pools. Therefore, process engines such as FPM (FastCGI Process Manager) that initialize a long connection once for each request call can also be called and used.

[0077] Step 209: When the number of persistent connections in the connection pool is less than a quantity threshold, the number of persistent connections in the connection pool is expanded to be greater than the quantity threshold through the maintenance process.

[0078] In an embodiment of the present application, the quantity threshold is the minimum number of long connections in the connection pool, which can be set according to actual needs. The number of long connections in each connection pool is periodically detected through a maintenance process. When the number of long connections is less than the quantity threshold, the long connections in the connection pool can be expanded by copying existing long connections to ensure that there are sufficient long connections in the connection pool and to ensure the normal use of the connection pool.

[0079] Step 210: When there are no idle long connections in the connection pool, a preset number of long connections are established in the connection pool through the maintenance process.

[0080] In an embodiment of the present application, the idle long connections in each connection pool are periodically detected through a maintenance process. If no idle long connections are detected, the long connections in the connection pool can be expanded by copying the existing long connections to ensure that there are sufficient available long connections in the connection pool and to ensure the normal use of the connection pool.

[0081] Another request processing method provided by an embodiment of the present application implements communication by using an asynchronous non-blocking method so that the communication processes of the services share a long connection in a connection pool for communication, thereby reducing the processing resources required to maintain the connection pool and improving the efficiency of service calls.

[0082] Figure 4 : is a structural block diagram of a request processing device 30 provided in an embodiment of the present application. The device 30 may include:

[0083] The receiving module 301 is configured to asynchronously receive a call request sent by the second device to the target service;

[0084] The query module 302 is configured to query the persistent connection between the first device and the second device from the connection pool of the target service when it is monitored that the service information has been obtained according to the call request, so as to create a persistent connection communication process of the persistent connection;

[0085] The sending module 303 is configured to asynchronously send the service information to the second device through the long connection communication process.

[0086] Optionally, the device further comprises:

[0087] The maintenance module is configured as follows:

[0088] Asynchronously receiving a persistent connection request sent by the second device to the target service;

[0089] A persistent connection between the first device and the second device is established in the connection pool of the target service through a maintenance process, and a persistent connection establishment notification is asynchronously sent to the second device.

[0090] Optionally, the maintenance module is further configured to:

[0091] A maintenance process for maintaining each connection pool is created based on a user-defined process in an asynchronous network communication engine.

[0092] Optionally, the maintenance module is further configured to: when the number of long connections in the connection pool is less than a quantity threshold, expand the number of long connections in the connection pool to above the quantity threshold through the maintenance process.

[0093] Optionally, the maintenance module is further configured to:

[0094] When there are no idle long connections in the connection pool, a preset number of long connections are established in the connection pool through the maintenance process.

[0095] Optionally, the query module 302 is further configured to:

[0096] Monitoring the processing result of the call request;

[0097] When the processing result includes a communication event handle, it is determined that the service information has been acquired.

[0098] Optionally, the query module 302 is further configured to:

[0099] The long connection communication process of the long connection is created based on the task subprocess in the abnormal network communication engine.

[0100] The request processing device provided in the embodiment of the present application has a functional module corresponding to executing the request processing method, and can execute the request processing method provided in any one of Embodiments 1 to 9 of the present application, and can achieve the same beneficial effects.

[0101] In another embodiment provided by the present application, an electronic device is also provided, which may include: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the program, each process of the above request processing method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it is not described here. For example, Figure 5 As shown, the electronic device may specifically include: a processor 401, a storage device 402, a display screen 403 with a touch function, an input device 404, an output device 405, and a communication device 406. The number of processors 401 in the electronic device may be one or more. Figure 5A processor 401 is taken as an example. The processor 401, storage device 402, display screen 403, input device 404, output device 405 and communication device 406 of the electronic device may be connected via a bus or other means.

[0102] In another embodiment provided in the present application, a computer-readable storage medium is provided, in which instructions are stored. When the computer-readable storage medium is executed on a computer, the computer executes the request processing method described in any one of the above embodiments.

[0103] In another embodiment provided by the present application, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the request processing methods described in the above embodiments.

[0104] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0105] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0106] The above description is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims

1. A request processing method, characterized in that: Applied to a first device, the method includes: Asynchronously receiving a persistent connection request sent by a second device to a target service; Establishing a persistent connection between a first device and a second device in a connection pool of a target service through a maintenance process, and asynchronously sending a persistent connection establishment notification to the second device; the service process of the target service includes a plurality of sub-service processes, and the plurality of sub-service processes share the connection pool of the target service; Asynchronously receiving a call request sent by a second device to a target service; Feedback response information to the second device to end the long connection communication process; Acquire service information according to the call request, and close the long connection communication process between the first device and the second device while waiting for the service information to be acquired; When it is monitored that the service information has been obtained according to the call request, querying the persistent connection between the first device and the second device from the connection pool of the target service to create a persistent connection communication process of the persistent connection; The service information is asynchronously sent to the second device through the long connection communication process.

2. The method according to claim 1, characterized in that Before the asynchronously receiving the persistent connection request sent by the second device to the target service, the method further includes: A maintenance process for maintaining each connection pool is created based on a user-defined process in an asynchronous network communication engine.

3. The method according to claim 1, characterized in that After establishing a persistent connection between the first device and the second device in the connection pool of the target service through the maintenance process, and asynchronously sending a persistent connection establishment notification to the second device, the method further includes: When the number of long connections in the connection pool is less than a quantity threshold, the number of long connections in the connection pool is expanded to be above the quantity threshold through the maintenance process.

4. The method according to claim 1, characterized in that After establishing a persistent connection between the first device and the second device in the connection pool of the target service through the maintenance process, and asynchronously sending a persistent connection establishment notification to the second device, the method further includes: When there are no idle long connections in the connection pool, a preset number of long connections are established in the connection pool through the maintenance process.

5. The method according to claim 1, characterized in that Before asynchronously sending the service information to the second device through the long connection communication process when the service information has been acquired according to the call request, the method further includes: Monitoring the processing result of the call request; When the processing result includes a communication event handle, it is determined that the service information has been acquired.

6. The method according to claim 1, characterized in that The long connection communication process of creating the long connection includes: The long connection communication process of the long connection is created based on the task subprocess in the abnormal network communication engine.

7. A request processing device, characterized in that: Applied to a first device, the apparatus comprises: A maintenance module is configured to asynchronously receive a persistent connection request sent by a second device to a target service; establish a persistent connection between the first device and the second device in a connection pool of the target service through a maintenance process, and asynchronously send a persistent connection establishment notification to the second device; the service process of the target service includes a plurality of sub-service processes, and the plurality of sub-service processes share the connection pool of the target service; A receiving module, configured to asynchronously receive a call request sent by the second device to the target service; a query module configured to query the persistent connection between the first device and the second device from the connection pool of the target service when it is monitored that the service information has been obtained according to the call request, so as to create a persistent connection communication process of the persistent connection; a sending module, configured to asynchronously send the service information to the second device through the long connection communication process; The device is also configured to: after the receiving module asynchronously receives a call request sent by the second device for the target service, and before the query module monitors that the service information has been obtained according to the call request, feedback response information to the second device to end the long connection communication process; obtain service information according to the call request, and while waiting for the service information to be obtained, close the module of the long connection communication process between the first device and the second device.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the request processing method according to any one of claims 1 to 6 are implemented.

9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the request processing method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Interactive processing method based on TCP (Transmission Control Protocol) of server

    CN102546808A

  • Data interaction method and server

    CN111586140A

  • Service processing method, device and electronic equipment and storage medium

    CN111770157A