Disclosure of Invention
The invention provides a request transmission method, a server, a client, a system and electronic equipment, which are used for solving the problems of more resources consumed by request transmission and higher implementation cost.
According to a first aspect of the present invention, there is provided a request transmission method applied to a system including a client and a server, where a gateway layer and a business layer are deployed, the method including:
the client converts the format of the first request to obtain a second request;
the client sends the second request to the server, and the data size of the second request is smaller than that of the first request;
the gateway layer performs format reduction on the second request to obtain the first request;
the gateway layer sends the first request to the service layers, and the number of the service layers is larger than that of the gateway layers;
and the service layer executes corresponding processing operation according to the first request to obtain a processing result.
According to a second aspect of the present invention, there is provided a request transmission method applied to a server, where a gateway layer and a service layer are deployed, the method including:
the gateway layer receives a second request sent by a client, wherein the second request is obtained by the client through format conversion according to a first request, and the data size of the second request is smaller than that of the first request;
the gateway layer performs format reduction on the second request to obtain the first request;
the gateway layer sends the first request to the service layers, and the number of the service layers is larger than that of the gateway layers;
and the service layer executes corresponding processing operation according to the first request to obtain a processing result.
According to a third aspect of the present invention, there is provided a request transmission method applied to a client, the method including:
carrying out format conversion on the first request to obtain a second request;
and sending the second request to a server, wherein the data size of the second request is smaller than that of the first request.
According to a fourth aspect of the present invention, there is provided a request transmission system comprising: the system comprises a client and a server, wherein a gateway layer and a service layer are deployed in the server;
the client is used for carrying out format conversion on the first request to obtain a second request;
the client is further used for sending the second request to the server; the data size of the second request is smaller than the data size of the first request;
the gateway layer is used for carrying out format reduction on the second request to obtain the first request;
the gateway layer is further configured to send the first request to the service layer; the number of the service layers is greater than that of the gateway layers;
and the service layer is used for executing corresponding processing operation according to the first request to obtain a processing result.
According to a fifth aspect of the present invention, there is provided a server, comprising: a gateway layer and a service layer;
the gateway layer is used for receiving a second request sent by the client; the second request is obtained by the client through format conversion according to the first request, and the data size of the second request is smaller than that of the first request;
the gateway layer is further configured to perform format reduction on the second request to obtain the first request;
the gateway layer is further configured to send the first request to the service layer; wherein the number of the service layers is greater than the number of the gateway layers;
and the service layer is used for executing corresponding processing operation according to the first request to obtain a processing result.
According to a sixth aspect of the present invention, there is provided a client, comprising:
the conversion module is used for carrying out format conversion on the first request to obtain a second request;
the sending module is used for sending the second request to a server; wherein the data size of the second request is smaller than the data size of the first request.
In yet another aspect of the present invention, there is also provided a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to execute the request transmission method of the second aspect described above.
In yet another aspect of the present invention, there is also provided a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to execute the request transmission method of the third aspect described above.
In yet another aspect of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform the request transmission method according to the second aspect described above.
In yet another aspect of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform the request transmission method according to the third aspect.
Aiming at the prior art, the invention has the following advantages:
the client can perform format conversion on the first request to obtain a second request, and send the second request to the server, wherein the data size of the second request is smaller than that of the first request, then, a gateway layer in the server performs format reduction on the second request to obtain the first request, and sends the first request to the service layer, wherein the number of the service layers is larger than that of the gateway layers, and the service layer executes corresponding processing operation according to the first request to obtain a processing result. Therefore, the first request is converted into the second request with smaller data size for transmission, so that the resource consumed during the request transmission can be reduced, and the transmission efficiency can be improved. Meanwhile, the gateway layer is established in advance, the second request is restored into the first request based on the gateway layer and then is sent to the service layer for response, so that the code of the service layer does not need to be changed, and the number of the service layers is not more than that of the gateway layers, so that the processing amount spent on establishing the gateway layer is less than the code change amount of the service layer to a certain extent under the condition of realizing request restoration. Therefore, the transmission efficiency can be improved, the transmission cost is reduced, and the implementation cost is reduced.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Detailed Description
Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the invention are shown in the drawings, it should be understood that the invention can be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
Fig. 1 is a flowchart of steps of a request transmission method provided in an embodiment of the present invention, where the method may be applied to a system including a client and a server, and a gateway layer and a service layer may be deployed in the server, as shown in fig. 1, the method may include:
step 101, the client performs format conversion on the first request to obtain a second request.
Step 102, the client sends the second request to the server; the data size of the second request is smaller than the data size of the first request.
In the embodiment of the present invention, the client may also be referred to as an APP front end, and may be used to provide Application (APP) front end services. The server, which may also be referred to as a service backend, may be used to provide services to clients. For example, the server may be a background server corresponding to the APP. The first request can be a request which needs to be sent to the server by the client, the first request is determined according to the operation of the client by the user, and the first request can be used for requesting the service from the server. The information carried by the second request and the information carried by the first request can be the same, and the request structures can be different, so that the data size of the second request can be smaller than that of the first request, the resource consumed during request transmission is reduced, and the transmission efficiency is improved. For example, the first request may be a GET request carrying request parameters in the form of URLs, and the second request may be a POST request carrying compressed request parameters, where the compressed request parameters are carried by a request body (body).
And 103, the gateway layer performs format reduction on the second request to obtain the first request.
And step 104, the gateway layer sends the first request to the service layers, and the number of the service layers is greater than that of the gateway layers.
In the embodiment of the present invention, the gateway layer may be a virtual service that is preset to implement the reduction of the second request into the first request and send the first request to the service layer. By way of example, it may be an executable software program. The service layer may be configured to respond to the received first request, and further provide a corresponding service for the functions supported by the client, so that each function supported by the client can be performed normally. Furthermore, in the embodiment of the present invention, the second request is restored to the first request and then sent to the service layer for processing, so that the service layer can still process the first request according to the original request processing logic while improving the transmission efficiency and reducing the transmission cost. Compared with the mode of modifying the service layer and directly processing the service layer according to the second request, the embodiment of the invention does not need to modify the processing logic of the service layer, thereby reducing the implementation cost to a certain extent.
Further, since the client often has a plurality of supported functions, the server often has a plurality of service layers. For example, assuming that the functions supported by the client include private chat, group chat, comment, video playing, video sharing, and video sharing, the server may include a plurality of business layers supporting the functions. And if the codes of all service layers in the server are modified in advance, each service layer is provided with a restoring logic for restoring the second request into the first request. In this way, the first request can be converted into the second request for transmission, and the second request can be directly restored by the service layer. However, the number of service layers is often large, which results in a large amount of modification and high cost for the service end. In the embodiment of the invention, only a gateway layer is needed to be added, and the code of the service layer is not needed to be changed, so that the transmission efficiency can be improved, the transmission cost is reduced, meanwhile, the invasion to the service layer is reduced to the greatest extent, and the implementation cost is reduced. It should be noted that the number of service layers and the number of gateway layers may be set according to actual requirements, which is not limited in the embodiment of the present invention. Optionally, the number of service layers may be 1, so that implementation cost can be maximally saved.
And 105, the service layer executes corresponding processing operation according to the first request to obtain a processing result.
In the embodiment of the invention, the service layer can execute the processing operation corresponding to the first request to obtain the processing result and make the corresponding response according to the processing result. The processing operation corresponding to the first request can be determined by the role of the first request. For example, assuming that the first request is for obtaining video data of video a, the service layer may search for the video data of video a and return the video data to the client.
In summary, in the request transmission method provided in the embodiment of the present invention, the client may perform format conversion on the first request to obtain a second request, and send the second request to the server, where the data size of the second request is smaller than the data size of the first request, then, the gateway layer in the server performs format reduction on the second request to obtain the first request, and sends the first request to the service layer, where the number of the service layers is greater than the number of the gateway layers, and the service layer executes corresponding processing operation according to the first request to obtain a processing result. Therefore, the first request is converted into the second request with smaller data size for transmission, so that the resource consumed during the request transmission can be reduced, and the transmission efficiency can be improved. Meanwhile, the gateway layer is established in advance, the second request is restored into the first request based on the gateway layer and then is sent to the service layer for response, so that the code of the service layer does not need to be changed, and the number of the service layers is not more than that of the gateway layers, so that the processing amount spent on establishing the gateway layer is less than the code change amount of the service layer to a certain extent under the condition of realizing request restoration. Therefore, the transmission efficiency can be improved, the transmission cost is reduced, and the implementation cost is reduced.
Furthermore, in the embodiment of the present invention, by reducing the resources required to be consumed in transmitting the request, the traffic and the bandwidth required for transmission can be further reduced, and thus the traffic and the bandwidth resources can be saved.
Further, fig. 2 is a flowchart of steps of another request transmission method provided in an embodiment of the present invention, where the method may be applied to a client, and as shown in fig. 2, the method may include:
step 201, converting the format of the first request to obtain a second request.
Step 202, sending the second request to a server, where the data size of the second request is smaller than the data size of the first request.
In summary, in the request transmission method provided in the embodiment of the present invention, the client may perform format conversion on the first request to obtain the second request, and send the second request to the server, where a data size of the second request is smaller than a data size of the first request, so that resources required to be consumed in transmitting the request may be reduced and transmission efficiency may be improved by converting the first request into the second request with a smaller data size for transmission.
Optionally, the operation of performing format conversion on the first request to obtain the second request may be implemented by the following steps a to B:
and step A, selecting a target conversion mode from preset optional conversion modes.
In this embodiment of the present invention, the selectable conversion manner may be a preset manner for converting the first request into the second request. An optional conversion mode may correspond to a conversion mode under a conversion protocol or a conversion mode under a conversion version. That is, the conversion modes characterized by different optional conversion modes have different conversion protocols, or the versions of the conversion modes characterized by different optional conversion modes are different. When the target conversion mode is selected from the preset selectable conversion modes, the conversion configuration information may be read first, and then the selectable conversion mode corresponding to the conversion configuration information may be determined as the target conversion mode. The conversion configuration information may be set by the user according to actual requirements.
And B, carrying out format conversion on the first request according to the target conversion mode to obtain a second request, wherein the second request carries a target conversion identifier corresponding to the target conversion mode.
In the embodiment of the present invention, the target conversion identifier may be used to uniquely identify a target conversion manner, and the representation form of the target conversion identifier may be a number, a character, a combination thereof, or the like. And converting by a target conversion mode, so that the conversion mode can meet the requirements of users. Meanwhile, the second request carries the target conversion identifier corresponding to the target conversion mode, so that the server can conveniently acquire the conversion mode used in the conversion in the subsequent steps, and further conveniently select the corresponding recovery mode.
Optionally, the first request may include a request path and request parameters. The request paths are used for pointing to corresponding service layers in the server, and the service layers pointed by different request paths are different. The request parameters may include parameters required by the service layer in response to the first request, such as parameters for performing authentication, parameters indicating the required content of the request, and so on. The second request may include a first flag bit, a header, and a body. Optionally, converting the format of the first request according to a target conversion manner, and obtaining the second request may include sub-step B1 to sub-step B1:
substep B1: and extracting a request path and request parameters in the first request.
Substep B2: and taking the request path as a designated zone bit of a second request to be generated, taking the target conversion identifier as a head of the second request to be generated, taking the request parameter as a body of the second request to be generated according to the target conversion mode, and compressing the body to obtain the second request.
In the embodiment of the present invention, the first request may be analyzed first, and then the request path and the request parameter may be extracted from the analyzed first request. The designated flag bit can be preset according to actual requirements and is used for storing the position of the request path. In the embodiment of the invention, the request path is independently stored, so that the path information can be conveniently and rapidly acquired when a second request is sent to the service layer according to the request path, and the sending efficiency is further improved. Meanwhile, the target conversion identifier is used as a header (header) of the second request to be generated, so that the server side in the subsequent step can conveniently acquire the conversion mode used in the conversion, and further conveniently select the corresponding reduction mode.
Further, when the request parameter is used as a body of the second request to be generated, the processing modes corresponding to different target conversion modes are different. Optionally, the selectable conversion manner may include a first selectable conversion manner and a second selectable conversion manner, and a processing manner corresponding to the first selectable conversion manner may be to directly use the request parameter as a body. The processing mode corresponding to the second optional conversion mode may be that the request parameter is used as a body according to a Key-Value pair (KV) form. Specifically, the operation of using the request parameter as a body may include: substep (1): and when the target conversion mode is the first optional conversion mode, directly taking the request parameter as a body. Therefore, the amount of change of the content in the request parameters can be reduced as much as possible by directly putting the request parameters into the device, and further parameter errors are avoided. Substep (2): and when the target conversion mode is a second optional conversion mode, combining the parameter name of each parameter in the request parameters and the corresponding parameter value into a key value pair, and taking the key value pair as a body. Therefore, the data carried in the body can be more orderly by putting the data in a key value pair mode, and the data is convenient to transmit.
Further, a compression mode to be used may be defined in the target conversion mode. For example, fig. 3 is a schematic diagram of a conversion provided by the embodiment of the present invention, as shown in fig. 3, 01 denotes a first request, where the content in the block shown in 01 is a partial content of the first request. And 02 denotes the converted second request. 02a denotes the designated flag of the second request, and the content in the box denoted 02a shows part of the content of the request path. 02b represents the header of the second request, wherein "Content-Encoding" is a field in the target translation identifier for representing the compression method used by the target translation method. For example, it is assumed that the compression method supported by the target conversion method is a gzip compression algorithm or a brotli compression algorithm. The value of the Content-Encoding field may be "gzip/br" as shown in fig. 3. Accordingly, when compressing the body according to the target conversion manner, one of the compression manners supported by the target conversion manner may be selected for compression, for example, the body may be compressed according to a gzip compression algorithm, or the body may be compressed according to a brotli compression algorithm. Further, assuming that the target conversion manner is a first optional conversion manner with a Version of "1.0", the identifier corresponding to the first optional conversion manner may be "Convert-Version: 1.0". Further, 02c denotes a compressed body, and the content in the box shown in 02c shows a part of the content of the request parameter.
It should be noted that sometimes a client may need to directly send a POST request to a server, in this case, the server may directly receive and process the POST request without restoring. Therefore, in the embodiment of the present invention, the target conversion identifier may be added to the second request when the server needs to perform the restoration, so that the server can conveniently know whether the restoration needs to be performed, and further, unnecessary restoration operations are prevented from being performed.
It should be noted that, the designated flag may also store a network protocol version adopted by the first request, which is not limited in this embodiment of the present invention. For example, assume that the first request is a GET request with a size of 1634 bytes (byte) with a network protocol version of HTTP/1.1:
“http://mpaas.iqiyi.com/control/1.0/locateapp_k=b398b8ccbaeacca840073a7ee9b7e7e6&app_v=11.3.0&app_gv=&app_t=0&platform_id=10&dev_os=4.4.2&dev_ua=H60-L01&net_sts=1&qyid=4e3d2c2d72eac2d7818ccfa5f791efa51104&imei=25352a6b26d4721fc80b7980a7e2a758&aid=c3e829014537e725&mac=9c:c1:72:f9:f7:bb&scrn_scale=2&lang=zh_CN&app_lm=cn&oaid=7feb9dfb-ffff-7ff3-dbaf-4fb7ff1912bc&psp_uid=&psp_sub_uid=&psp_cki=&psp_status=1&secure_v=1&secure_p=GPhone&cupid_id=357143042125630&cupid_v=3.45.004&core=1&api_v=10.7&profile=%7B%22group%22%3A%221%2C2%22%2C%22counter%22%3A2%2C%22hy_id%22%3A%22%22%2C%22recall_firstdate%22%3A%22-1%22%2C%22first_time%22%3A%2220170823%22%7D&unlog_sub=0&cust_count=&dev_hw=%7B%22mem%22%3A%22430.6MB%22%2C%22cpu%22%3A1708800%2C%22gpu%22%3A%22%22%7D&net_ip=%7B%22province%22%3A%22%E6%B1%9F%E8%A5%BF%22%2C%22area%22%3A%22%E5%8D%8E%E4%B8%9C%22%2C%22respcode%22%3A0%2C%22timeout%22%3A0%2C%22cc%22%3A%22%E7%A7%BB%E5%8A%A8%22%2C%22city%22%3A%22%E4%B9%9D%E6%B1%9F%22%2C%22country%22%3A%22%E4%B8%AD%E5%9B%BD%22%7D&scrn_sts=1&scrn_res=720,1184&scrn_dpi=320&psp_vip=0&client_ip=%7B%22province%22%3A%22%E6%B1%9F%E8%A5%BF%22%2C%22area%22%3A%22%E5%8D%8E%E4%B8%9C%22%2C%22respcode%22%3A0%2C%22timeout%22%3A0%2C%22cc%22%3A%22%E7%A7%BB%E5%8A%A8%22%2C%22city%22%3A%22%E4%B9%9D%E6%B1%9F%22%2C%22country%22%3A%22%E4%B8%AD%E5%9B%BD%22%7D&province_id=14004&service_filter=&used_skinid=-1&youth_model=0&no_rec=0&xas=1&gps=115.954512,29.66844&gps_st=3”
converting the first request to a second request, i.e., after converting to a POST request, the request may include:
and (3) specifying a flag bit: POST HTTP:// mpaas. iqiiyi. com/control/1.0/locate HTTP/1.1
Body is the compressed character stream;
heads (heads):
Content-Encoding:gzip
Convert-Version:1.0。
where the size of the converted second request may be 989 bytes, it can be seen that the amount of data occupied by the request is reduced by about 45%. Accordingly, the processing resources consumed to transmit the second request may be less than the processing resources consumed to transmit the first request. Meanwhile, in the embodiment of the invention, the length of the request can be shortened by converting the first request into the second request. Therefore, the problem that the request fails due to data loss caused by the fact that the request data is intercepted in the sending process due to the overlong request can be solved.
Fig. 4 is a flowchart of steps of another request transmission method according to an embodiment of the present invention, where the method may be applied to a server, and a gateway layer and a service layer may be deployed in the server. As shown in fig. 4, the method may include:
step 301, the gateway layer receives a second request sent by a client, where the second request is obtained by the client performing format conversion according to the first request, and the data size of the second request is smaller than the data size of the first request.
And step 302, the gateway layer performs format reduction on the second request to obtain the first request.
Step 303, the gateway layer sends the first request to the service layers, and the number of the service layers is greater than that of the gateway layers.
And step 304, the service layer executes corresponding processing operation according to the first request to obtain a processing result.
In summary, in the request transmission method provided in the embodiment of the present invention, the gateway layer in the server may receive the second request sent by the client, and perform format reduction on the second request to obtain the first request. The second request is obtained by the client through format conversion according to the first request, and the data size of the second request is smaller than that of the first request. And finally, the service layer can execute corresponding processing operation according to the first request to obtain a processing result. Therefore, the first request is converted into the second request with smaller data size for transmission, so that the resource consumed during the request transmission can be reduced, and the transmission efficiency can be improved. Meanwhile, the gateway layer is established in advance, the second request is restored into the first request based on the gateway layer and then is sent to the service layer for response, so that the code of the service layer does not need to be changed, and the number of the service layers is not more than that of the gateway layers, so that the processing amount spent on establishing the gateway layer is less than the code change amount of the service layer to a certain extent under the condition of realizing request restoration. Therefore, the transmission efficiency can be improved, the transmission cost is reduced, and the implementation cost is reduced.
Optionally, the gateway layer and the service layer may be deployed in the same server; alternatively, the gateway layer and the service layer may be deployed in different servers in the same local area network. The server running the gateway layer may be called a front-end processor (Nginx), and the service layer may run in the same server as the gateway layer, so that the gateway layer transmits the first request to the service layer inside the device, and further, transmission resources consumed when the gateway layer sends the first request to the service layer are reduced to the greatest extent.
It should be noted that the processing logic executed by the front-end processor may be implemented by the lua script. The service layer and the gateway layer operate in different server scenes, the server operating the gateway layer can be called a service worker node, and after restoration is completed, the front-end processor can send a second request to the service worker node configured by the upstream.
Further, in an actual application scenario, the client is often far away from the server and located in a different local area network, and therefore, a large amount of transmission resources are often consumed in the process of directly sending the first request to the server by the client. The embodiment of the invention deploys the gateway layer and the service layer in different servers in the same local area network. Because the gateway layer and the service layer are in the same local area network, the transmission resource consumed by the gateway layer for sending the first request to the service layer is less than the transmission resource consumed by the client for directly sending the first request to the service layer. Therefore, the gateway layer can be operated by using a special server, and the transmission resource can be saved while the server can provide sufficient resources to operate the gateway layer.
Optionally, the second request may be obtained by the client performing format conversion on the first request according to the target conversion mode, and the second request may carry a target conversion identifier corresponding to the target conversion mode. Specifically, the implementation process of the conversion performed by the client may refer to the description in the related step.
Correspondingly, the gateway layer performs format reduction on the second request to obtain the first request, which can be realized through the following steps C to E:
and step C, extracting the target conversion identifier contained in the second request.
In the embodiment of the invention, the gateway layer can analyze the second request, and then read the content of the designated zone bit in the analyzed second request, thereby obtaining the target conversion identifier.
And D, determining a target conversion mode according to the target conversion identifier.
And E, according to the target conversion mode, carrying out format reduction on the second request to obtain the first request.
In the embodiment of the present invention, the process of restoring the second request to the first request may be understood as an inverse operation of the conversion operation performed by the client. In order to ensure that the second request can be correctly restored to the first request, in the embodiment of the present invention, the gateway layer may restore the target conversion manner indicated by the target conversion identifier. Optionally, according to the target conversion manner, performing format reduction on the second request to obtain the first request may be implemented by the following sub-steps E1 to E2:
sub-step E1: and decompressing the content in the body of the second request according to a reduction algorithm corresponding to the target conversion mode, and extracting the request parameter according to the decompressed content.
In this step, the compression algorithm used in the conversion may be determined according to the target conversion identifier. For example, assuming that the value of the content-encoding field in the target transform identifier is "gzip", the compression algorithm used may be determined to be gzip compression algorithm, and assuming that the value of the content-encoding field in the target transform identifier is "br", the compression algorithm used may be determined to be brotli compression algorithm. Accordingly, the gateway layer can decompress by using a restoration algorithm corresponding to the compression algorithm used in the conversion.
Further, when extracting the request parameter from the decompressed content, the corresponding putting mode may be determined according to the conversion mode indicated by the target conversion identifier, and the extracting mode may be determined according to the putting mode. For example, when the putting mode is direct putting, the content obtained after decompression may be directly extracted as the request parameter. When the input mode is a key value pair mode, each key value pair can be extracted from the content obtained after decompression, and then the content in all the key value pairs is combined to obtain the request parameter.
Sub-step E2: and extracting a request path from the designated zone bit of the second request, and generating the first request according to the request parameter and the request path within the default request length supported by the server.
In the embodiment of the present invention, the default request length may be the maximum length of the request that can be supported by the server, and if the request exceeds the default request length, the request is truncated to ensure that the request length is specific within the default request length, and a value in the designated flag bit may be read to obtain the request path. And then combining the request parameters and the request path to obtain a first request. Wherein the length of the combined request does not exceed the default request parameter length. Optionally, in this embodiment of the present invention, before performing sub-step D2, the length of the default request parameter supported by the server may be increased, specifically, the configuration parameter of the server may be set, so as to set the default request length as the maximum length supported by the server. In this way, the probability of the first request being truncated can be reduced, thereby ensuring the integrity of the first request.
Optionally, fig. 5 is a schematic structural diagram provided in an embodiment of the present invention, and as shown in fig. 5, the client, that is, the APP front end, may include an APP service layer and an APP network library, where the first request may be generated by the APP service layer, and the operation of converting the first request into the second request may be implemented by the APP network library. Therefore, conversion can be realized without changing the APP service layer, and the realization cost can be reduced. The server, namely, the service back end, can implement restoration through the front-end processor gateway layer, and send the first request obtained after restoration to the back-end service layer.
Further, fig. 6 is another schematic structural diagram provided in the embodiment of the present invention, as shown in fig. 6, the client may be amobile terminal 01, and for example, themobile terminal 01 may send the POST request obtained after the conversion to a front-end processor 03 operating a gateway layer according to a domain name of a network andother servers 02 in the network, such as a transit server and a Load Balancing (LB) server. The domain name used by themobile terminal 01 may be "mpass. Further, after the gateway layer completes the restoration, the GET request obtained by the restoration may be sent to theservice server cluster 04, where one service server may correspond to one service layer. Further, GET requests transmitted to each service server in the spoke cluster can be passed through the front-end processor (NGINX: 80) with the port of "80" to the process (jetty: 8080) for processing.
Optionally, in the embodiment of the present invention, a failure rate of a manner of directly sending the first request and a failure rate of a request transmission method provided by the embodiment of the present invention may also be counted. For example, in a scenario where the first request is directly sent, the sampled data may be: total number of transmissions: 39856, wherein the number of failures: 302, accordingly, the failure rate is 302/39856 ═ 0.76%. In a scenario where the request transmission method provided by the embodiment of the present invention is used, the sampled data may be: total number of transmissions: 73333, wherein the number of failures: 332, the failure rate was 302/39856 ═ 0.45% accordingly
It can be seen that the failure rate is reduced from 0.76% to 0.45% and by about 40% compared to the direct transmission method. Therefore, the first request is converted into the second request to be sent, and the data volume required to be transmitted is reduced, so that the failure rate caused by overlong request is reduced.
Fig. 7 is a structural diagram of a request transmission system according to an embodiment of the present invention, and as shown in fig. 7, the system 70 may include: aclient 701 and aserver 702, wherein a gateway layer and a service layer are deployed in the server;
theclient 701 is configured to perform format conversion on the first request to obtain a second request;
theclient 701 is further configured to send the second request to theserver 702; the data size of the second request is smaller than the data size of the first request;
the gateway layer is used for carrying out format reduction on the second request to obtain the first request;
the gateway layer is further configured to send the first request to the service layer; the number of the service layers is greater than that of the gateway layers;
and the service layer is used for executing corresponding processing operation according to the first request to obtain a processing result.
In summary, in the system provided in the embodiment of the present invention, the client may perform format conversion on the first request to obtain a second request, and send the second request to the server, where the data size of the second request is smaller than the data size of the first request, then, the gateway layer in the server performs format reduction on the second request to obtain the first request, and sends the first request to the service layer, where the number of the service layers is greater than the number of the gateway layers, and the service layer executes corresponding processing operations according to the first request to obtain a processing result. Therefore, the first request is converted into the second request with smaller data size for transmission, so that the resource consumed during the request transmission can be reduced, and the transmission efficiency can be improved. Meanwhile, the gateway layer is established in advance, the second request is restored into the first request based on the gateway layer and then is sent to the service layer for response, so that the code of the service layer does not need to be changed, and the number of the service layers is not more than that of the gateway layers, so that the processing amount spent on establishing the gateway layer is less than the code change amount of the service layer to a certain extent under the condition of realizing request restoration. Therefore, the transmission efficiency can be improved, the transmission cost is reduced, and the implementation cost is reduced.
Fig. 8 is a block diagram of a server according to an embodiment of the present invention, and as shown in fig. 8, theserver 80 may include:
agateway layer 801 and aservice layer 802;
thegateway layer 801 is configured to receive a second request sent by a client; the second request is obtained by the client through format conversion according to the first request, and the data size of the second request is smaller than that of the first request;
thegateway layer 801 is further configured to perform format restoration on the second request to obtain the first request;
thegateway layer 801 is further configured to send the first request to the service layer; wherein the number of the service layers is greater than the number of the gateway layers;
theservice layer 802 is configured to execute a corresponding processing operation according to the first request to obtain a processing result.
Optionally, the second request is obtained by the client performing format conversion on the first request according to a target conversion mode; the second request carries a target conversion identifier corresponding to the target conversion mode;
thegateway layer 801 is specifically configured to:
extracting the target conversion identifier contained in the second request;
determining a target conversion mode according to the target conversion identifier;
and according to the target conversion mode, carrying out format reduction on the second request to obtain the first request.
Optionally, thegateway layer 801 is further specifically configured to:
decompressing the content in the request body of the second request according to the reduction algorithm corresponding to the target conversion mode, and extracting the request parameter from the decompressed content;
and extracting a request path from the designated zone bit of the second request, and generating the first request according to the request parameter and the request path within the default request length supported by the server.
Optionally, theserver 80 further includes: the increasing module is used for setting the default request length as the maximum length supported by the server.
Optionally, theserver 80 is a server; thegateway layer 801 and theservice layer 802 are deployed in the same server; alternatively, thegateway layer 802 and theservice layer 802 are deployed in different servers in the same lan.
In summary, in the server provided in the embodiment of the present invention, the gateway layer may receive the second request sent by the client, and perform format restoration on the second request to obtain the first request. The second request is obtained by the client through format conversion according to the first request, and the data size of the second request is smaller than that of the first request. And finally, the service layer can execute corresponding processing operation according to the first request to obtain a processing result. Therefore, the first request is converted into the second request with smaller data size for transmission, so that the resource consumed during the request transmission can be reduced, and the transmission efficiency can be improved. Meanwhile, the gateway layer is established in advance, the second request is restored into the first request based on the gateway layer and then is sent to the service layer for response, so that the code of the service layer does not need to be changed, and the number of the service layers is not more than that of the gateway layers, so that the processing amount spent on establishing the gateway layer is less than the code change amount of the service layer to a certain extent under the condition of realizing request restoration. Therefore, the transmission efficiency can be improved, the transmission cost is reduced, and the implementation cost is reduced.
Fig. 9 is a block diagram of a client according to an embodiment of the present invention, and as shown in fig. 9, the client 90 may include:
a converting module 901, configured to perform format conversion on the first request to obtain a second request;
a sending module 902, configured to send the second request to a server; wherein the data size of the second request is smaller than the data size of the first request.
Optionally, the conversion module 901 is specifically configured to:
selecting a target conversion mode from preset optional conversion modes;
and according to the target conversion mode, carrying out format conversion on the first request to obtain a second request, wherein the second request carries a target conversion identifier corresponding to the target conversion mode.
Optionally, the conversion module 901 is further specifically configured to:
extracting a request path and request parameters in the first request;
and taking the request path as a designated zone bit of a second request to be generated, taking the target conversion identifier as a header of the second request to be generated, taking the request parameter as a request body of the second request to be generated according to the target conversion mode, and compressing the request body to obtain the second request.
In summary, the client provided in the embodiment of the present invention may perform format conversion on the first request to obtain the second request, and send the second request to the server, where the data size of the second request is smaller than the data size of the first request, so that by converting the first request into the second request with smaller data size for transmission, the resource consumed during request transmission may be reduced, and the transmission efficiency is improved.
For the above device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and for the relevant points, refer to the partial description of the method embodiment.
The embodiment of the present invention further provides an electronic device, as shown in fig. 10, which includes aprocessor 1001, acommunication interface 1002, amemory 1003 and acommunication bus 1004, wherein theprocessor 1001, thecommunication interface 1002 and thememory 1003 complete mutual communication through thecommunication bus 1004,
amemory 1003 for storing a computer program;
theprocessor 1001 is configured to implement the request transmission method according to any of the embodiments described above when executing the program stored in thememory 1003.
The communication bus mentioned in the above terminal may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the terminal and other equipment.
The Memory may include a Random Access Memory (RAM) or a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the Integrated Circuit may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component.
In yet another embodiment of the present invention, a computer-readable storage medium is further provided, which has instructions stored therein, and when the instructions are executed on a computer, the instructions cause the computer to execute the request transmission method described in any of the above embodiments.
In yet another embodiment, the present invention further provides a computer program product containing instructions which, when run on a computer, cause the computer to perform the request transmission method described in any of the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.