A method, device, electronic device and storage medium for processing a service request

By introducing asynchronous non-blocking select/epoll technology and IO thread pool in the HTTP client library, combined with the HTTP/2 protocol, the problem that the existing library does not support HTTP/2 and multi-threading modes is solved, and high-performance HTTP clients are realized end processing, suitable for the performance requirements of 5G core networks.

CN114629885BActive Publication Date: 2024-12-03ASIAINFO TECH CHINA INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110007752.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-01-05
Publication Date
2024-12-03
Estimated Expiration
2041-01-05

AI Technical Summary

Technical Problem

The existing client libraries that support HTTP communication protocols in C/C++ usually do not support HTTP/2 or multi-threaded modes, and the developers are difficult to learn and have imperfect functions, which cannot meet the high performance requirements of 5G core networks.

Method used

Provides a business request processing method, which creates a request object by receiving business requests from the application client, and uses asynchronous non-blocking select/epoll technology to combine it with IO thread pool and connection pool, supports HTTP/2 protocol, and realizes multi-threaded concurrency. Automatically decompress response data, integrate asynchronous non-blocking communication model and scalable multithreading model.

Benefits of technology

It implements a high-performance C++ HTTP client programming framework that is out of the box in the development interface and supports multiple versions of the HTTP protocol, with high performance and flexibility, and is adapted to various development scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114629885B_ABST
    Figure CN114629885B_ABST
Patent Text Reader

Abstract

The present application provides a method, device, electronic device and storage medium for processing business requests, and relates to the field of network communication and message processing. The method includes: receiving a business request sent by an application client; creating a request object based on the business request, and sending the request object to the application client; receiving the request content submitted asynchronously by the application client through the request object; sending the request content to the server, and receiving the response content of the server; returning the response content to the application client through the request object; when the application client completes receiving the response content, sending a notification message of the completion of the business request processing to the application client. Under the premise that the development interface is ready to use out of the box, the present application supports different versions of the HTTP protocol, automatically decompresses the response data by default, supports multi-threaded scalability, and the load of each thread is relatively balanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of network communication and message processing. Specifically, the present application relates to a method, device, electronic device and computer-readable storage medium for processing a business request. Background Art

[0002] HTTP (Hypertext Transfer Protocol) is the abbreviation of Hypertext Transfer Protocol, which is a transmission protocol used to transfer hypertext from the World Wide Web server to the local browser. Hypertext Transfer Protocol (HTTP) is transaction-oriented. The application layer protocol specifies the format and rules of requests and responses between the browser and the server. It is an important basis for reliable exchange of files (including text, sound, images and other multimedia files) on the World Wide Web. HTTP is a standard (TCP) for client and server requests and responses. Usually, an HTTP client initiates a request to establish a TCP connection to a server-specified port, and the HTTP server listens for requests from the client on that port.

[0003] As mobile telecommunications enter the 5G era, many 5G core network components use HTTP / 2 as the communication protocol and have high requirements for corresponding performance (including latency), while at the same time they need to be compatible with some old systems' HTTP / 1.0 and HTTP / 1.1 communication protocols. After examining many C / C++ client libraries that support the HTTP communication protocol, we found that some of them either do not support HTTP / 2, do not support multi-threaded mode (or support it poorly), do not have multiplexed asynchronous IO processing, require developers to have a high learning gradient, or have incomplete functions. Summary of the invention

[0004] The present application provides a method, device, electronic device and computer-readable storage medium for processing a business request, which can solve the problem that the client library of the HTTP communication protocol does not support HTTP / 2 and does not support multi-threaded mode (or does not support it well). The technical solution is as follows:

[0005] In a first aspect, a method for processing a service request is provided, which is applied to a hypertext transfer client, and the method comprises:

[0006] Receive business requests sent by application clients;

[0007] Create a request object based on the business request and send the request object to the application client;

[0008] Receive the request content submitted asynchronously by the application client through the request object;

[0009] Send the request content to the server and receive the response content from the server;

[0010] Return the response content to the application client via the request object;

[0011] When the application client completes receiving the response content, a notification message of the completion of the business request processing is sent to the application client.

[0012] Preferably, receiving a service request sent by an application client includes:

[0013] Receiving a service request based on the request initiation interface layer in the hypertext transfer client;

[0014] The service request is parsed by initiating the request interface layer to obtain the message information of the service request;

[0015] Extract message information;

[0016] If the message information is extracted successfully, the uniform resource locator URL information, host information, port information and the used transmission protocol information are obtained from the message information;

[0017] If the extraction of message information fails, an exception message is generated.

[0018] Preferably, creating a request object based on a business request and before sending the request object to an application client includes:

[0019] By initiating the request interface layer to check whether there is a corresponding IO worker thread in the input / output IO thread pool according to the URL information;

[0020] If so, get the corresponding IO worker thread;

[0021] If not, determine the target IO worker thread from the thread pool;

[0022] Each IO worker thread in the IO worker thread pool is based on non-blocking select / epoll technology.

[0023] Preferably, before creating a request object based on the business request and sending the request object to the application client, the method further includes:

[0024] By initiating the request interface layer to check whether there is a connection to the server in the connection pool according to the URL information;

[0025] If yes, obtain the existing business request connection object;

[0026] If not, an asynchronous transmission control protocol connection request is automatically initiated to the corresponding server, and a connection object corresponding to the newly created connection is obtained.

[0027] Preferably, creating a request object based on the business request and sending the request object to the application client includes:

[0028] The request interface layer creates a request object based on the business request and sends the request object to the application client.

[0029] Preferably, after creating a request object based on the business request and sending the request object to the application client, the following steps are included:

[0030] Bind the request object to the corresponding connection object;

[0031] Bind the connection object to the select / epoll process object.

[0032] Preferably, receiving the request content asynchronously submitted by the application client through the request object includes:

[0033] A request processor in a hypertext transfer client receives request content asynchronously submitted by an application client through a request object;

[0034] The request content includes: Hypertext Transfer Protocol header parameters and Hypertext Transfer Protocol request body.

[0035] Preferably, sending the request content to the server and receiving the response content from the server include:

[0036] The request processor asynchronously initiates a transmission control protocol connection based on the IO worker thread and connection object bound to the request object to connect to the corresponding server.

[0037] Preferably, after sending the received request content to the server, the method further includes:

[0038] Check whether the TCP connection contains a request to be sent;

[0039] If so, the request to be sent is packaged in turn according to the transmission protocol information to obtain a data packet, and the data packet is asynchronously sent to the corresponding server;

[0040] If not, get the response content corresponding to the request content.

[0041] Preferably, asynchronously initiating a transmission control protocol connection, after connecting to the corresponding server, includes:

[0042] Receive TCP data from the server response;

[0043] Parse the transmission control protocol data to obtain the response content.

[0044] Preferably, the response content is returned to the application client via the request object, including:

[0045] The request handler returns the response content to the application client asynchronously through the request object.

[0046] Preferably, when the application client completes receiving the response content, a notification message of the completion of the service request processing is sent to the application client, including:

[0047] The request completion notification function sends a notification message to the application client indicating that the business request processing is completed.

[0048] In a second aspect, a service request processing device is provided, which is applied to a hypertext transfer client, and the device includes:

[0049] A first processing module, used for receiving a service request sent by an application client;

[0050] The second processing module is used to create a request object based on the business request and send the request object to the application client;

[0051] The third processing module is used to receive the request content asynchronously submitted by the application client through the request object;

[0052] The fourth processing module is used to send the request content to the server and receive the response content from the server;

[0053] A fifth processing module, used for returning the response content to the application client through the request object;

[0054] The sixth processing module is used to send notification information of completion of business request processing to the application client when the application client completes receiving the response content.

[0055] Preferably, the first processing module is specifically used to receive a service request based on the request initiation interface layer in the hypertext transfer client; parse the service request through the request initiation interface layer to obtain message information of the service request;

[0056] Extract the message information; if the message information is extracted successfully, obtain the uniform resource locator URL information, host information, port information and the used transmission protocol information from the message information; if the message information is extracted unsuccessfully, generate exception information.

[0057] Preferably, before creating a request object based on the business request and sending the request object to the application client, it includes: checking whether there is a corresponding IO working thread in the input / output IO thread pool according to the URL information by initiating a request interface layer;

[0058] If so, get the corresponding IO worker thread;

[0059] If not, the target IO worker thread is determined from the thread pool; each IO worker thread in the IO worker thread pool is based on non-blocking select / epoll technology.

[0060] Preferably, before creating a request object based on the business request and sending the request object to the application client, it also includes: checking whether there is a connection to the server in the connection pool according to the URL information by initiating the request interface layer;

[0061] If yes, obtain the existing business request connection object;

[0062] If not, an asynchronous transmission control protocol connection request is automatically initiated to the corresponding server, and a connection object corresponding to the newly created connection is obtained.

[0063] Preferably, the second processing module is specifically used to create a request object based on the business request by initiating a request interface layer, and send the request object to the application client.

[0064] Preferably, after creating a request object based on the business request and sending the request object to the application client, the following steps are included:

[0065] Bind the request object to the corresponding connection object;

[0066] Bind the connection object to the select / epoll process object.

[0067] Preferably, the third processing module is specifically used to receive the request content asynchronously submitted by the application client through the request object based on the request processor in the hypertext transfer client;

[0068] The request content includes: Hypertext Transfer Protocol header parameters and Hypertext Transfer Protocol request body.

[0069] Preferably, the fourth processing module is specifically used to asynchronously initiate a transmission control protocol connection to connect to the corresponding server end through the request processor according to the IO working thread and connection object bound to the request object.

[0070] Preferably, after sending the received request content to the server, the method further includes:

[0071] Check whether the TCP connection contains a request to be sent;

[0072] If so, the request to be sent is packaged in turn according to the transmission protocol information to obtain a data packet, and the data packet is asynchronously sent to the corresponding server;

[0073] If not, get the response content corresponding to the request content.

[0074] Preferably, asynchronously initiating a transmission control protocol connection, after connecting to the corresponding server, includes:

[0075] Receive TCP data from the server response;

[0076] Parse the transmission control protocol data to obtain the response content.

[0077] Preferably, the fifth processing module is specifically used to request the processor to asynchronously return the response content to the application client through the request object.

[0078] Preferably, the sixth processing module is specifically used to send notification information of completion of business request processing to the application client through a request end notification function.

[0079] In a third aspect, a server is provided, the server comprising:

[0080] one or more processors;

[0081] Memory;

[0082] One or more applications, wherein the one or more applications are stored in a memory and configured to be executed by one or more processors, and the one or more programs are configured to perform operations corresponding to the method for processing business requests as shown in the first aspect of the present application.

[0083] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for processing the business request shown in the first aspect of the present application is implemented.

[0084] The beneficial effects of the technical solution provided by this application are:

[0085] Receive the business request sent by the application client; create a request object based on the business request and send the request object to the application client; receive the request content submitted asynchronously by the application client through the request object; send the request content to the server and receive the response content from the server; return the response content to the application client through the request object; when the application client completes receiving the response content, send a notification message to the application client that the business request processing is complete. In this way, under the premise of the development interface being ready to use, it supports multiple different stage versions of the HTTP protocol, supports common compression algorithms, and automatically decompresses the response data by default. In terms of performance, it integrates the asynchronous non-blocking communication model with the scalable multi-threaded model, thereby realizing a C++HTTP client programming framework that has high performance guarantees, is easy to use, and is flexible to adapt to various development scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0086] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in describing the embodiments of the present application are briefly introduced below.

[0087] Figure 1 A flowchart of a method for processing a service request provided by an embodiment of the present application;

[0088] Figure 2 A flowchart of a method for processing a service request provided in another embodiment of the present application;

[0089] Figure 3 A structural diagram of a method for processing a business request provided in yet another embodiment of the present application;

[0090] Figure 4 A schematic diagram of the structure of a device for processing a service request provided in another embodiment of the present application;

[0091] Figure 5 A schematic diagram of the structure of an electronic device for processing a service request provided in yet another embodiment of the present application. DETAILED DESCRIPTION

[0092] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present invention.

[0093] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.

[0094] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0095] First, several terms involved in this application are introduced and explained:

[0096] Asynchronous call is a method that allows the operation to continue without waiting for the return value of the called function. In asynchronous calls, the caller does not need to wait for the return result of the called function and can continue to perform its own operations. Therefore, there must be a mechanism for the called party to notify the caller when there is a return value. There are many means that can be used in the same process, and the commonly used means are callbacks, mutex objects, and messages. The callback method is very simple: when calling an asynchronous function, put a function address in the parameter, the asynchronous function saves this address, and calls back this function after the result is obtained to notify the caller. If the asynchronous function is packaged into an object, the callback function address can be replaced with an event, and the caller can be notified through the event handling routine.

[0097] The business request processing method, device, electronic device and computer-readable storage medium provided in this application are intended to solve the above technical problems in the prior art.

[0098] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0099] In one embodiment, a method for processing a service request is provided, which is applied to a hypertext transfer client, such as Figure 1 As shown, the method includes:

[0100] Step S101, receiving a service request sent by an application client;

[0101] The application client is the upper layer application, which issues a business request, which mainly refers to the HTTP request. The hypertext transfer client includes a request initiation interface layer and a request processor, which is a client that can communicate with the server and get a response. Here, it refers to the request initiation interface layer of the hypertext transfer client that receives the business request sent by the client.

[0102] Step S102, creating a request object based on the business request, and sending the request object to the application client;

[0103] When the request initiation interface layer of the hypertext transfer client receives an HTTP request, it parses the HTTP request message, creates a request object based on the parsed results, namely, the HTTP request object, and returns the HTTP request object to the application client, namely, to the upper-layer application.

[0104] Step S103, receiving the request content asynchronously submitted by the application client through the request object;

[0105] After returning the created HTTP request object to the application client, the application client will construct the request content and asynchronously submit the request content to the request processor of the hypertext transfer client through the HTTP request object. This process can be interpreted as the application client initiating the actual request operation through the HTTP request object. Through this operation, the data of the request content is packaged in HTTP format and enters the network transmission stage. Before executing this operation, the ownership of the HTTP request object belongs to the application client. After executing this operation, the ownership of the HTTP request object belongs to the hypertext transfer client. Among them, ownership means that an object can only be bound to one transaction, and this transaction is the owner of this object, that is, this transaction has the ownership of this object.

[0106] Step S104, sending the request content to the server, and receiving the response content from the server;

[0107] The request processor receives the request content, establishes a TCP connection with the server, and sends the request content to the server. The server processes the received request content, constructs the response content, and sends the response content to the request processor. By default, the request content is not compressed. Only when the application client explicitly specifies the compression algorithm, the request will be compressed before sending.

[0108] Step S105, returning the response content to the application client through the request object;

[0109] The request processor receives the response content from the server and sends it to the request initiating interface layer. The request initiating interface layer detects whether it needs to be decompressed or converted into a JSON object for processing according to the requirements of the application client. The request initiating interface layer returns the processed response content to the application client through the HTTP request object. That is, the application client waits for the arrival of the response content through the HTTP request object.

[0110] Step S106: When the application client completes receiving the response content, a notification message of the completion of the service request processing is sent to the application client.

[0111] After the response corresponding to a request is completely received, the IO worker thread calls back the end notification function and sends a business request to the application client. If the request response sending times out, this end notification function is also called back.

[0112] Receive the business request sent by the application client; create a request object based on the business request and send the request object to the application client; receive the request content submitted asynchronously by the application client through the request object; send the request content to the server and receive the response content from the server; return the response content to the application client through the request object; when the application client completes receiving the response content, send a notification message to the application client that the business request processing is complete. In this way, under the premise of the development interface being ready to use, it supports multiple different stage versions of the HTTP protocol, supports common compression algorithms, and automatically decompresses the response data by default. In terms of performance, it integrates the asynchronous non-blocking communication model with the scalable multi-threaded model, thereby realizing a C++HTTP client programming framework that has high performance guarantees, is easy to use, and is flexible to adapt to various development scenarios.

[0113] In another embodiment, a method for processing a service request is provided, such as Figure 2 As shown, the method includes:

[0114] Step S201, receiving a service request sent by an application client;

[0115] The application client is the upper-layer application. The upper-layer application issues a business request. The business request here mainly refers to the HTTP request. The request initiation interface layer is part of the hypertext transfer client and will receive the HTTP request from the application client.

[0116] The client interface layer provides compression support and JSON support. By default, the application client does not compress the data. Only when the application client explicitly specifies the compression algorithm, the request data sent will be compressed before sending. When receiving the response, the custom decompression function is enabled by default, and the gzip compression algorithm is used by default. For customized compression algorithms, the open response registration interface allows the compression format to be customized. JSON is widely used in HTTP network communications, and the application interface layer uses rapidjson. Like HTTP protocol parsing, in the process of converting JSON objects to HTTP request body messages, and HTTP response bodies to JSON objects, the corresponding Reader / Writer is customized so that the sliced ​​data groups mentioned in HTTP protocol parsing can be received, thereby reducing the redundant memory allocation and memory copy overhead caused by the intermediate carrier (such as a continuous block of memory).

[0117] Step S202, parsing the service request to obtain message information of the service request;

[0118] After receiving the HTTP request, the request initiator interface layer will parse the HTTP request. The HTTP request message can be divided into three parts: request line, request header and request body. The request line contains information such as request method, URL, protocol version, etc. Request method: GET and POST are common, and DELETE, HEAD, OPTIONS, PUT and TRACE are also included. URL refers to the address corresponding to the requested resource, which and the Host attribute of the message header form a complete request URL. The protocol version supports HTTP / 1.0, HTTP / 1.1 and HTTP / 2. http-parser is used to parse the HTTP1.x data part, and nghttp2 (extracting the HTTP / 2 protocol parsing part) is used to parse the HTTP / 2 data. When receiving the request body, since the length of the received data is uncertain, the processing method here is to store them in the form of slice groups instead of splicing them into a whole block of continuous memory data, thereby reducing memory application and memory data copying. Of course, for relatively small request body data (for example, less than 4050 bytes), they will be in a continuous memory. The client interface layer provides compression support and JSON support. By default, the application client does not compress data. Only when the application client explicitly specifies the compression algorithm, the request data sent will be compressed before sending. When receiving the response, the custom decompression function is enabled by default, and the gzip compression algorithm is used by default. For customized compression algorithms, the open response registration interface allows you to customize the compression format.

[0119] JSON is widely used in HTTP network communication, and the application interface layer uses rapidjson. Just like HTTP protocol parsing, the corresponding Reader / Writer is customized to receive the slice data group mentioned in HTTP protocol parsing, thereby reducing the redundant memory allocation and memory copy overhead caused by the intermediate carrier (such as a continuous memory block).

[0120] Step S203, extracting message information;

[0121] Step S204, if the message information is extracted successfully, then obtain the uniform resource locator URL information, host information, port information and the used transmission protocol information from the message information;

[0122] Step S205: if the extraction of message information fails, abnormal information is generated.

[0123] After parsing the HTTP request message, the parsed information is extracted based on the parsing results of the HTTP message. If the extraction is successful, the URL information, host information, port information and the used transmission protocol information are obtained. If the extraction fails, an exception message is generated to notify the application client that the information extraction failed.

[0124] Step S206, checking whether there is a corresponding IO worker thread in the input / output IO thread pool according to the URL information;

[0125] Step S207: If yes, obtain the IO worker thread;

[0126] Step S208, if not, determine the target IO worker thread from the thread pool;

[0127] The function of the thread pool is to limit the number of execution threads in the system. Creating a thread pool can detect the number of times a thread is created and destroyed. Each IO worker thread can be reused to execute multiple tasks. According to the server address in the URL information, check whether there is an IO worker thread corresponding to the server address in the thread pool. If so, obtain the IO worker thread; if not, select an IO worker thread from the thread pool as the IO worker thread corresponding to the URL information.

[0128] Each newly created IO worker thread in the IO worker thread pool is based on non-blocking select / epoll technology.

[0129] select and epoll are IO multiplexing methods to implement concurrent service programs. select / epoll technology is mainly responsible for establishing and closing TCP connections, data sending and receiving processing, protocol data packaging and parsing, etc. select / epoll combines the advantages of select and epoll, has no maximum concurrency restrictions, good portability, and saves the overhead of copying some file descriptors during system calls.

[0130] Step S209, checking whether there is a connection to the server in the connection pool according to the URL information;

[0131] Step S210: If yes, obtain the existing service request connection object;

[0132] The relationship between threads and connections is flexible. When an IO worker thread needs a connection (the connection exists), it will asynchronously initiate a remote connection and monopolize the connection. When the connection is no longer needed, it will release the connection, making it "free" and able to be used by other threads or by the IO worker thread next time.

[0133] If there is already a connection to the server in the connection pool, then get the connection object corresponding to the connection.

[0134] Step S211: If not, an asynchronous TCP connection request is automatically initiated to the corresponding server, and a newly created connection object is obtained.

[0135] If there is no connection to the server in the connection pool, the IO worker thread needs to initiate an asynchronous TCP connection request from the hypertext transfer client to the server. After the connection is successful, the connection object corresponding to the connection is obtained. When the IO worker thread has finished using the connection, it will return it to the connection pool so that it can be used by other threads that want to use it. The connection pool can reduce the time to create a connection, simplify the programming model, and reduce the waste of resources.

[0136] Step S212, creating a request object based on the business request, and sending the request object to the application client;

[0137] When the request initiation interface layer of the hypertext transfer client receives an HTTP request, it parses the HTTP request message, creates a request object based on the parsed results, namely, the HTTP request object, and returns the HTTP request object to the application client, namely, to the upper-layer application.

[0138] In a preferred embodiment of the present invention, creating a request object based on a service request and sending the request object to an application client includes:

[0139] The request initiation interface layer creates a request object based on the business request and returns the request object to the application client.

[0140] Specifically, the request initiation interface layer is part of the hypertext transfer client. When the request initiation interface layer completes the parsing of the HTTP request and checks whether to create an IO worker thread and a connection pool, it will create an HTTP request object and return the HTTP request object to the application client. After returning it to the application client, the ownership of the HTTP request object belongs to the application client. Ownership means that an object can only be bound to one transaction, and this transaction is the owner of the object, that is, this transaction has the ownership of the object.

[0141] In a preferred embodiment of the present invention, after creating a request object based on a business request and sending the request object to an application client, the following steps are included:

[0142] Bind the request object to the corresponding connection object;

[0143] Bind the connection object to the select / epoll process object.

[0144] Bind the request object to the connection object, and then bind the connection object to a select / epoll connection object. A select / epoll process object only runs in a certain IO thread, thereby greatly reducing thread concurrency problems and reducing the performance consumption caused by multi-thread synchronization.

[0145] Step S213, receiving the request content asynchronously submitted by the application client through the request object;

[0146] After returning the created HTTP request object to the application client, the application client will construct the request content, and asynchronously submit the request content to the request processor of the hypertext transfer client through the HTTP request object. This process can be explained as the application client initiating an actual request operation through the HTTP request object, through which the data of the request content is packaged in HTTP format and enters the network transmission stage; before this operation, the ownership of the HTTP request phenomenon belongs to the application client, and after this operation, the ownership of the HTTP request object belongs to the hypertext transfer client.

[0147] In a preferred embodiment of the present invention, receiving the request content asynchronously submitted by the application client through the request object includes:

[0148] A request processor in a hypertext transfer client receives request content asynchronously submitted by an application client through a request object;

[0149] The request content includes: Hypertext Transfer Protocol header parameters and Hypertext Transfer Protocol request body.

[0150] Before receiving the request content submitted asynchronously by the application client through the request object, the ownership of the request object belongs to the application client. After receiving the request content submitted asynchronously by the application client through the request object, the ownership of the request object belongs to the request processor.

[0151] The application client constructs the request content, which includes: Hypertext Transfer Protocol (HTTP) header parameters, Hypertext Transfer Protocol (HTTP) request body, and submits the request content to the hypertext transfer client through the HTTP request object. The initiating request interface layer of the hypertext transfer end receives the request content and asynchronously submits the request content to the request processor. The HTTP request object is created by the initiating request client and returned to the application client. After being returned to the application client, the ownership of the HTTP request object belongs to the application client. Before receiving the request content asynchronously submitted by the application client through the request object, the ownership of the request object belongs to the application client. After receiving the request content asynchronously submitted by the application client through the request object, the ownership of the request object belongs to the request processor. In addition, the request object that completes the response has only read-only permissions.

[0152] In addition, when the IO worker thread is processing request sending, if the protocol supports the group commit method (such as HTTP / 2 supports frame sending), it will be batched into the HTTP protocol data actually to be sent, and then sent to the network in batches.

[0153] Step S214, sending the request content to the server, and receiving the response content from the server;

[0154] The request processor receives the request content, establishes a TCP connection with the server, and sends the request content to the server. The server processes the received request content, constructs the response content, and sends the response content to the request processor.

[0155] In a preferred embodiment of the present invention, sending the request content to the server and receiving the response content from the server include:

[0156] The request processor asynchronously initiates a TCP connection to the corresponding server based on the IO worker thread and connection object bound to the request object;

[0157] The request processor receives the request content submitted asynchronously by the application client through the request object, and asynchronously initiates a TCP connection through the IO worker thread and connection object bound to the request object, connects to the corresponding server, and asynchronously exchanges the request content with the server. After the TCP connection with the server is successful, if it is HTTP / 2, the corresponding SETTINGS and other messages are exchanged asynchronously. The specific HTTP protocol version to be tried is set by the external user before sending the request, but internally, we send it out in priority over HTTP / 2 (if the server supports the HTTP / 2 protocol).

[0158] In a preferred embodiment of the present invention, after asynchronously requesting content exchange with the server, the following steps are included:

[0159] Check whether there are requests to be sent on the TCP connection;

[0160] If so, the request to be sent is packaged according to the transmission protocol information and sent asynchronously to the corresponding server;

[0161] If not, get the response to the request to be sent.

[0162] If there are corresponding requests waiting to be sent on the connection at this time, the data will be packaged according to the protocol and then sent asynchronously to the corresponding server. The requests are sent in the form of window queues. Due to the window queue sending logic, the application client can control the maximum request load on a connection and allow a request process to be initiated without actually establishing a connection with the server. For this reason, from the application client's point of view, the writing and actual operation of the HTTP client code are smooth, without blocking in the middle, until you want to wait for a response to a request; if there are no requests waiting to be sent on the connection at this moment, the corresponding content corresponding to the current request content is obtained.

[0163] In a preferred embodiment of the present invention, a TCP connection is initiated asynchronously, and after connecting to the corresponding server, the following steps are included:

[0164] Receive the TCP data from the server response, and parse the TCP data to get the response content;

[0165] The request handler returns the response content to the application client asynchronously through the request object.

[0166] The server responds with TCP data. The IO worker thread parses the received TCP data to obtain the response content. For methods that support response group commit (such as HTTP / 2), the IO worker thread will receive a batch of responses at one time, and then parse them one by one until a response is received completely, and then initiate the corresponding response notification mechanism in turn.

[0167] Step S215, returning the response content to the application client through the request object;

[0168] The request processor receives the response content from the server and sends it to the request initiating interface layer. The request initiating interface layer detects whether it needs to be decompressed or converted into a JSON object for processing according to the requirements of the application client. The request initiating interface layer returns the processed response content to the application client through the HTTP request object. That is, the application client waits for the arrival of the response content through the HTTP request object.

[0169] Step S216: When the application client completes receiving the response content, a notification message of the completion of the service request processing is sent to the application client.

[0170] After the response corresponding to a request is completely received, the IO worker thread calls back the end notification function and sends a business request to the application client. If the request response sending times out, this end notification function is also called back.

[0171] In a preferred embodiment of the present invention, the callback request end notification function notifies the application client of the request completion, including:

[0172] The request end notification function will release the ownership of the request object and send an end notification according to the request end notification mechanism.

[0173] In the request end notification function, the ownership of the request will be released, and then the corresponding notification action will be sent according to the request end notification mechanism. The callback process is still in the internal working thread.

[0174] Figure 3The invention discloses a structural schematic diagram of a method for processing a business request of the present invention, which is a complete process of processing a business request. A hypertext transfer client (internal work thread manager) includes a request processor, a request initiation interface layer, and a request object (the request object belongs to the hypertext transfer client after the application client asynchronously submits the actual request content, and belongs to the application client before the application client asynchronously submits the actual request content). The whole process is as follows: the application client sends a business request to the request initiation interface layer, the request initiation interface layer parses the business request and checks whether an IO work thread and a connection pool are created, if yes, a connection object is obtained; if no, a TCP connection is asynchronously initiated to obtain a newly created connection object; after the request object is created, the request object and the connection object are bound, and the request object is returned to the application client, the application client asynchronously submits the actual request content to the request processor through the request object, the IO work thread (located in the internal work thread manager) initiates a TCP connection, connects to the server, sends the actual request content after the connection is successful, the server generates TCP data in response to the actual request content, parses the TCP data to obtain the response content, and sends the response content to the application client through the request object, and when the response ends, the IO work thread calls back the request end notification function to notify the application client that the request is completed.

[0175] Receive the business request sent by the application client; create a request object based on the business request and send the request object to the application client; receive the request content submitted asynchronously by the application client through the request object; send the request content to the server and receive the response content from the server; return the response content to the application client through the request object; when the application client completes receiving the response content, send a notification message to the application client that the business request processing is complete. In this way, under the premise of the development interface being ready to use, it supports multiple different stage versions of the HTTP protocol, supports common compression algorithms, and automatically decompresses the response data by default. In terms of performance, it integrates the asynchronous non-blocking communication model with the scalable multi-threaded model, thereby realizing a C++HTTP client programming framework that has high performance guarantees, is easy to use, and is flexible to adapt to various development scenarios.

[0176] In another embodiment, a device for processing a service request is provided, such as Figure 4 As shown, the request processing device 40 may include:

[0177] The first processing module 401 is used to receive a service request sent by an application client;

[0178] The second processing module 402 is used to create a request object based on the business request and send the request object to the application client;

[0179] The third processing module 403 is used to receive the request content submitted asynchronously by the application client through the request object;

[0180] The fourth processing module 404 is used to send the request content to the server and receive the response content from the server;

[0181] The fifth processing module 405 is used to return the response content to the application client through the request object;

[0182] The sixth processing module 406 is used to send notification information of completion of service request processing to the application client when the application client completes receiving the response content.

[0183] Receive the business request sent by the application client; create a request object based on the business request and send the request object to the application client; receive the request content submitted asynchronously by the application client through the request object; send the request content to the server and receive the response content from the server; return the response content to the application client through the request object; when the application client completes receiving the response content, send a notification message to the application client that the business request processing is complete. In this way, under the premise of the development interface being ready to use, it supports multiple different stage versions of the HTTP protocol, supports common compression algorithms, and automatically decompresses the response data by default. In terms of performance, it integrates the asynchronous non-blocking communication model with the scalable multi-threaded model, thereby realizing a C++HTTP client programming framework that has high performance guarantees, is easy to use, and is flexible to adapt to various development scenarios.

[0184] In another embodiment of the present application, an electronic device is provided, the electronic device comprising: a memory and a processor; at least one program stored in the memory, and when executed by the processor, compared with the prior art, the following can be achieved:

[0185] Receive the business request sent by the application client; create a request object based on the business request and send the request object to the application client; receive the request content submitted asynchronously by the application client through the request object; send the request content to the server and receive the response content from the server; return the response content to the application client through the request object; when the application client completes receiving the response content, send a notification message to the application client that the business request processing is complete. In this way, under the premise of the development interface being ready to use, it supports multiple different stage versions of the HTTP protocol, supports common compression algorithms, and automatically decompresses the response data by default. In terms of performance, it integrates the asynchronous non-blocking communication model with the scalable multi-threaded model, thereby realizing a C++HTTP client programming framework that has high performance guarantees, is easy to use, and is flexible to adapt to various development scenarios.

[0186] In an alternative embodiment, an electronic device is provided, such as Figure 5 As shown, Figure 5 The electronic device 5000 shown includes: a processor 5001 and a memory 5003. The processor 5001 and the memory 5003 are connected, such as through a bus 5002. Optionally, the electronic device 5000 may also include a transceiver 5004. It should be noted that in actual applications, the transceiver 5004 is not limited to one, and the structure of the electronic device 5000 does not constitute a limitation on the embodiments of the present application.

[0187] Processor 5001 may be a CPU, a general-purpose processor, a DSP, an ASIC, an FPGA or other programmable logic device, a transistor logic device, a hardware component or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 5001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0188] The bus 5002 may include a path to transmit information between the above components. The bus 5002 may be a PCI bus or an EISA bus, etc. The bus 5002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0189] The memory 5003 may be a ROM or other type of static storage device that can store static information and instructions, a RAM or other type of dynamic storage device that can store information and instructions, or an EEPROM, a CD-ROM or other optical disk storage, an optical disk storage (including a compressed optical disk, a laser disk, an optical disk, a digital versatile disk, a Blu-ray disk, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.

[0190] The memory 5003 is used to store application code for executing the solution of the present application, and the execution is controlled by the processor 5001. The processor 5001 is used to execute the application code stored in the memory 5003 to implement the content shown in any of the above method embodiments.

[0191] Among them, electronic devices include but are not limited to: mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc.

[0192] Another embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer-readable storage medium is run on a computer, the computer can execute the corresponding content in the aforementioned method embodiment. Compared with the prior art, a business request sent by an application client is received; a request object is created based on the business request, and the request object is sent to the application client; the request content submitted asynchronously by the application client through the request object is received; the request content is sent to the server, and the response content of the server is received; the response content is returned to the application client through the request object; when the application client completes receiving the response content, a notification message of the completion of the business request processing is sent to the application client. In this way, under the premise that the development interface is ready to use, multiple different stage versions of the HTTP protocol are supported, a general compression algorithm is supported, and the response data is automatically decompressed by default. In terms of performance, the asynchronous non-blocking communication model is integrated with the scalable multi-threaded model, thereby realizing a C++HTTP client programming framework with high performance guarantee, easy to use, and flexible adaptation to various development scenarios.

[0193] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0194] The above descriptions are only some embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for processing a service request, characterized in that: Applied to a hypertext transfer client, the method comprises: Receive business requests sent by application clients; Parsing the message based on the service request, creating a request object according to the parsing result, and sending the request object to the application client; Receiving request content asynchronously submitted by the application client through the request object; Determine a protocol version for asynchronous interaction with a server, send the request content to the server, and receive a response content from the server; Returning the response content to the application client through the request object; When the application client completes receiving the response content, a notification message indicating that the service request processing is completed is sent to the application client.

2. The method for processing a service request according to claim 1, characterized in that: The receiving of the service request sent by the application client includes: Receiving the service request based on the request initiation interface layer in the hypertext transfer client; Parsing the service request through the request initiation interface layer to obtain message information of the service request; Extracting the message information; If the message information is extracted successfully, then the uniform resource locator URL information, host information, port information and the used transmission protocol information are obtained from the message information; If the extraction of message information fails, an exception message is generated.

3. The method for processing a service request according to claim 2, characterized in that: The step of creating a request object based on the business request and sending the request object to the application client includes: The request initiation interface layer checks whether there is a corresponding IO worker thread in the input / output IO thread pool according to the URL information; If yes, then obtain the corresponding IO worker thread; If not, determine the target IO worker thread from the thread pool; Each IO worker thread in the IO worker thread pool is based on non-blocking select / epoll technology.

4. The method for processing a service request according to claim 2, characterized in that: The step of creating a request object based on the business request and sending the request object to the application client includes: Checking whether there is a connection to the server in the connection pool according to the URL information through the request initiation interface layer; If yes, obtain the existing business request connection object; If not, an asynchronous transmission control protocol connection request is automatically initiated to the corresponding server, and a connection object corresponding to the newly created connection is obtained.

5. The method for processing a service request according to claim 2, characterized in that: The step of creating a request object based on the business request and sending the request object to the application client includes: A request object is created based on the business request through the request initiation interface layer, and the request object is sent to the application client.

6. The method for processing a service request according to claim 1, characterized in that: The step of creating a request object based on the business request and sending the request object to the application client includes: Binding the request object to the corresponding connection object; Bind the connection object to the select / epoll process object.

7. The method for processing a service request according to claim 1, characterized in that: The receiving the request content asynchronously submitted by the application client through the request object includes: Receiving the request content asynchronously submitted by the application client through the request object based on the request processor in the hypertext transfer client; The request content includes: Hypertext Transfer Protocol header parameters and Hypertext Transfer Protocol request body.

8. The method for processing a service request according to claim 7, characterized in that: The sending of the request content to the server and receiving the response content from the server includes: The request processor asynchronously initiates a transmission control protocol connection based on the IO working thread and the connection object bound to the request object to connect to the corresponding server end.

9. The method for processing a service request according to claim 8, characterized in that: After sending the received request content to the server, it also includes: Detecting whether the transmission control protocol connection contains a request to be sent; If so, the requests to be sent are packaged in turn according to the transmission protocol information to obtain a data packet, and the data packet is asynchronously sent to the corresponding server; If not, obtain the response content corresponding to the request content.

10. The method for processing a service request according to claim 8, characterized in that: The asynchronously initiating transmission control protocol connection, after connecting to the corresponding server, includes: Receive TCP data from the server response; The transmission control protocol data is parsed to obtain response content.

11. The method for processing a service request according to claim 7, characterized in that: The returning the response content to the application client through the request object includes: The request processor returns the response content to the application client asynchronously through the request object.

12. The method for processing a service request according to claim 1, characterized in that: When the application client completes receiving the response content, sending notification information of completion of the service request processing to the application client includes: The request completion notification function sends a notification message indicating that the service request processing is completed to the application client.

13. A device for processing a service request, characterized in that: Applicable to hypertext transfer clients, including: A first processing module, used for receiving a service request sent by an application client; A second processing module is used to parse the message based on the service request, create a request object according to the parsing situation, and send the request object to the application client; A third processing module receives the request content asynchronously submitted by the application client through the request object; The fourth processing module determines the protocol version for asynchronous interaction with the server, sends the request content to the server, and receives the response content from the server; A fifth processing module, configured to return the response content to the application client through the request object; The sixth processing module is used to send notification information of completion of processing the business request to the application client when the application client completes receiving the response content.

14. A server, characterized in that: It includes: one or more processors; Memory; One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to: execute the method for processing a business request according to any one of claims 1 to 11.

15. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store computer instructions, and when the computer-readable storage medium is executed on a computer, the computer can execute the method for processing a business request according to any one of claims 1 to 11.