Request sending method, client, electronic device and storage medium

By using three caches in the client's request sending method to optimize the request sending process, the problem of repeated connection creation and concurrency in the C/S architecture is solved, and efficiency and stability are improved.

CN117729260BActive Publication Date: 2024-10-22XINGIN INFORMATION TECH (SHANGHAI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310310167.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-27
Publication Date
2024-10-22
Estimated Expiration
2043-03-27

AI Technical Summary

Technical Problem

In the C/S architecture, when the client frequently sends requests to the server, a large number of repeated connections are created, causing resource consumption and concurrency problems, affecting efficiency.

Method used

By setting three caches on the client: historical connection cache, currently created connection cache and request cache, the request sending process is optimized to avoid repeated connection creation and solve concurrency problems.

Benefits of technology

It improves the efficiency of request sending, avoids waste of resources, and ensures the success and stability of connection creation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117729260B_ABST
    Figure CN117729260B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a request sending method, a client, an electronic device and a storage medium. The method includes: when sending a first request to a server through a first connection, determining whether there is an available first connection between the client and the server based on the historical connection cached in the first cache of the client; if there is, reusing the first connection to send the first request to the server; if not, determining whether the client is currently creating the first connection based on the connection currently being created cached in the second cache of the client; if not, caching the first request to the second cache, and creating the first connection, after the first connection is created, sending the first request cached in the second cache to the server through the created first connection; if so, caching the first request to the third cache of the client, and after the first connection is created, sending the first request cached in the third cache to the server through the created first connection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer network technology, and in particular to a request sending method, a client, an electronic device and a storage medium. Background Art

[0002] In the C / S architecture, network communication between nodes is divided into client and server. In some application scenarios, there may be scenarios where the client sends a large number of requests to the server, which requires a large number of connections to be created between the client and the server. Among these large numbers of connections, some connections are created repeatedly, resulting in repeated creation of connections between the client and the server, which is time-consuming and causes more retries for some connections. At the same time, recycling these connections requires corresponding resource overhead, resulting in a waste of resources; and in the process of establishing these connections, some repeated connections are established at the same time, resulting in concurrency problems. Therefore, when the client has a large number of requests to send to the server, how to avoid resource consumption and concurrency problems caused by creating repeated connections between the client and the server is a technical problem that needs to be solved urgently. Summary of the invention

[0003] The embodiment of the present application provides a request sending method, a client, an electronic device and a storage medium. By setting three caches, the resource consumption problem and the concurrency problem of creating repeated connections are solved, and the efficiency of request sending is improved.

[0004] In a first aspect, an embodiment of the present application provides a request sending method, the method is applied to a client, and the method includes:

[0005] When sending a first request to a server through a first connection, determining whether there is an available first connection between the client and the server based on historical connections cached in a first cache of the client;

[0006] If so, reuse the first connection to send the first request to the server;

[0007] If not, determining whether the client is currently creating the first connection based on the connection currently being created cached in the second cache of the client;

[0008] If not, cache the first request in the second cache, create the first connection, and after the first connection is created, send the first request cached in the second cache to the server through the created first connection;

[0009] If so, cache the first request in a third cache of the client, and after creating the first connection, send the first request cached in the third cache to the server through the created first connection.

[0010] In a second aspect, an embodiment of the present application provides a client, wherein the client includes a processing unit and a transceiver unit;

[0011] The processing unit is configured to determine whether there is an available first connection between the client and the server based on historical connections cached in the first cache of the client when sending a first request to the server through the first connection;

[0012] If so, controlling the transceiver unit to multiplex the first connection to send the first request to the server;

[0013] If not, determining whether the client is currently creating the first connection based on the connection currently being created cached in the second cache of the client;

[0014] If not, cache the first request in the second cache and create the first connection. After the first connection is created, control the transceiver unit to send the first request cached in the second cache to the server through the created first connection;

[0015] If so, cache the first request in a third cache of the client, and after the first connection is created, control the transceiver unit to send the first request cached in the third cache to the server through the created first connection.

[0016] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, the processor is connected to a memory, the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device performs the method described in the first aspect.

[0017] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program enables a computer to execute the method described in the first aspect.

[0018] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer is operable to cause the computer to execute the method described in the first aspect.

[0019] Implementing the embodiments of the present application has the following beneficial effects:

[0020] It can be seen that in an embodiment of the present application, when the client needs to send a first request to the server through the first connection, the client will first determine whether there is a reusable first connection from the historical connections of the first cache; if so, the client can directly reuse the first connection to send the first connection to avoid repeatedly creating the same connection; if it is not reusable, the client will determine whether the first connection is currently being created from the connection currently being created cached in the second cache, and if so, the first request will be cached in the third cache without creating the first connection again, and the first request will be sent through the first connection after the first connection is created, thereby solving the concurrency problem of connection creation; if the first connection is not currently being created, the first request will be cached in the third cache, and the first connection will be created, so that in the case where there is no reusable first connection and the first connection is not being created, the first connection for sending the first request is directly created to ensure that the first request is successfully sent. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0022] Figure 1 A schematic diagram of a request sending system provided in an embodiment of the present application;

[0023] Figure 2 A flowchart of a request sending method provided in an embodiment of the present application;

[0024] Figure 3 A schematic diagram of another request sending method provided in an embodiment of the present application;

[0025] Figure 4 A block diagram of the functional units of a client provided in an embodiment of the present application;

[0026] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0027] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0028] The terms "first", "second", "third" and "fourth" etc. in the specification and claims of the present application and the drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.

[0029] Reference to "embodiments" herein means that a particular feature, result, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0030] First of all, it is explained that the application scenario of this application is a scenario where the client and the server frequently establish connections, especially a scenario where the client needs to send multiple requests to the server within a preset time, and thus needs to establish multiple connections with the server. Optionally, the connection between the client and the server involved in this application is mainly explained by taking TCP / IP connection as an example.

[0031] See also Figure 1 , Figure 1 A schematic diagram of a request sending system provided in an embodiment of the present application. The request sending system includes a client 10 and a server 20, wherein the client 10 includes a first cache 101, a second cache 102 and a third cache 103.

[0032] Among them, the first cache 101 is used to cache the historical connections between the client 10 and the server 20, the second cache is used to cache the connections currently being created, and the third cache is used for target type requests, wherein the target type requests are requests for which the connection required by the client to send the request is currently being created.

[0033] Exemplarily, when the client 10 sends a first request to the server 20 through the first connection, it is determined whether there is an available first connection between the client 10 and the server 20 based on the historical connections cached in the first cache 101 of the client 10; if so, the first connection is reused to send the first request to the server 20; if not, it is determined whether the client 10 is currently creating the first connection based on the connection currently being created cached in the second cache 102 of the client 10; if not, the first request is cached in the second cache 102, and the first connection is created, and after the first connection is created, the first request cached in the second cache 102 is sent to the server 20 through the created first connection; if so, the first request is cached in the third cache 103 of the client 10, and after the first connection is created, the first request cached in the third cache 103 is sent to the server 20 through the created first connection.

[0034] It can be seen that in the embodiment of the present application, when the client 10 needs to send a first request to the server 20 through the first connection, the client 10 will first determine whether there is a reusable first connection from the historical connections of the first cache 101; if so, the client 10 can directly reuse the first connection to send the first connection to avoid repeatedly creating the same connection; if it is not reusable, the client 10 will determine whether the first connection is currently being created from the connection currently being created cached by the second cache 102. If so, the first request is cached in the third cache without creating the first connection again. After the first connection is created, the first request is sent through the first connection, thereby solving the concurrency problem of connection creation; if the first connection is not currently being created, the first request is cached in the second request, and the first connection is created, so that in the absence of a reusable first connection and the first connection is not created, the first connection for sending the first request is directly created to ensure that the first request is successfully sent.

[0035] See also Figure 2 , Figure 2 A flowchart of a request sending method provided in an embodiment of the present application. The method is applied to a client. The method includes but is not limited to the following steps:

[0036] 201: When sending a first request to a server through a first connection, determine whether there is an available first connection between the client and the server based on historical connections cached in a first cache of the client.

[0037] If it exists, execute step 202; if it does not exist, execute step 203.

[0038] Exemplarily, when the client needs to transmit message information with the server, a first request is generated first, wherein the message information is used to instruct the client to exchange information with the server. For example, the client is instructed to upload data to the server, such as uploading the user's login information, etc.; or the client is instructed to obtain data from the server, such as obtaining the user's query information, etc. Therefore, this application does not limit the function of the first request.

[0039] Optionally, when generating the first request, the client determines the connection parameters for sending the first request based on the current remaining resources (for example, the remaining port number), wherein the connection parameters can be a five-tuple, for example, source IP address, destination IP address (i.e., IP address of the server), source port number, destination port number, and transport layer protocol. This application mainly uses the example that the connection parameters are not port numbers and destination IP addresses as examples. After determining the connection parameters, the first connection for sending the first request can be determined, that is, which port is used to send the first request to the server corresponding to the destination IP address. It should be noted that only the first identifier of the first connection (i.e., the destination IP address and port number corresponding to the first connection) is determined here, and the first connection is not established. It should be noted that the identifiers of the connections involved in this application are all unique identifiers determined based on the destination IP address and port number of the connection.

[0040] Furthermore, the message information and the identifier of the first connection are encapsulated to obtain the above-mentioned first request.

[0041] Furthermore, when encapsulating the first request, you can also encapsulate a registration callback event and the number of retries, and other information, where the registration callback event is used to indicate the related operations that the client needs to perform after the first request is successfully sent or the related operations that need to be performed after the sending fails.

[0042] Then, the client is pre-configured with a first cache, and the historical connections between the client and each server are cached in the first cache. Optionally, the historical connections are cached in the first cache in a Map structure, that is, a mapping relationship between the historical connection and the identifier of the historical connection (that is, the destination IP address and port number of the historical connection) is established. Exemplarily, the identifier of each historical connection is determined based on the IP address and port number of the server in the historical connection, that is, the destination IP address and port number of the server in each historical connection are used as the unique identifier of each historical connection. Then, the client first determines whether the first connection exists between the client and the server based on the historical connections cached in the first cache, that is, based on determining whether the identifier corresponding to each historical connection cached in the first cache exists. If it exists, it is determined that the first connection is cached in the first cache. If not, it is determined that the first connection is not cached in the first cache, that is, the first available first connection is not cached in the first cache; if it exists, it is determined whether the first connection is available. When it is determined that the first connection is cached in the first cache, it is determined whether the client and the server are still connected through the first connection, for example, whether the client maintains a heartbeat connection with the server through the first connection. If so, it is determined that an available first connection is cached in the first cache. If not, the first connection is unavailable, that is, it is determined that an available first connection is not cached in the first cache.

[0043] It should be noted that, if the first connection is cached in the first cache and the first connection is unavailable, the first connection is removed from the first cache.

[0044] 202: Reuse the first connection to send the first request to the server.

[0045] Optionally, when it is determined that an available first connection is cached in the first cache, the first connection is directly reused to send the first request to the server, without repeatedly establishing a connection between the client and the server, thereby avoiding waste of resources.

[0046] 203: Determine whether the client is currently creating the first connection based on the connection currently being created that is cached in the second cache of the client.

[0047] If not, execute step 204; if so, execute step 205.

[0048] First, it is explained that the client is pre-configured with a second cache, and the second cache caches the connection that the client is currently establishing. Specifically, when the client sends a request, if there is no available historical connection for a request, and the connection corresponding to the request is created for the first time, the request will be cached in the second cache to trigger the client to establish the connection, and the matter of the client establishing the connection will be cached in the second cache. If the connection is being created, the connection will be cached in the third cache.

[0049] For example, if the client determines that it needs to use connection A to send request A, and the first cache does not cache connection A, and the second cache is not creating connection A, the client will cache request A in the second cache, start to create connection A, and cache the creation of connection A in the second cache. If during the process of creating connection A, the client generates a request B, and request B is also sent through connection A, at this time it is determined that the second cache has cached the client currently creating connection A, so request B will not be cached in the second cache, but cached in the third cache.

[0050] Therefore, if there is no available first connection cached in the first cache, the client will first determine whether the client is currently creating the first connection based on the second cache.

[0051] First, it is explained that based on obtaining the identifier carried by each request cached in the second cache, the identifier of the connection currently being created cached in the second cache is determined; then, it is determined whether the identifier of the connection currently being created cached in the second cache has the first identifier of the first connection; if so, it is determined that the client is currently creating the first connection; if not, it is determined that the client is not currently creating the first connection.

[0052] 204: Cache the first request in the second cache and create the first connection. After the first connection is created, send the first request cached in the second cache to the server through the created first connection.

[0053] Exemplarily, if the connection currently being created and cached by the second cache does not contain the first connection, that is, the client has not currently created the first connection, then the first request is cached in the second cache and the first connection is created. In the present application, the first request can be cached in the second cache as a trigger signal. When the client detects that the first request is cached in the second cache, the first request can be parsed and the first connection can be created based on the identifier of the first connection carried in the first request. After it is detected that the first connection is created, the first request cached in the second cache is sent to the server through the created first connection, that is, the first request is read from the second cache, and the first request is sent to the server through the first connection.

[0054] Furthermore, after the first request is sent, the first request is deleted from the second cache to prevent the client from detecting that the second cache has been caching the first request and creating the first connection. It can be understood that deleting the first request from the second cache is equivalent to deleting the fact that the client is currently creating the first connection from the second cache. In other words, the connection currently being created cached in the second cache does not include the first connection.

[0055] Furthermore, after deleting the created first connection from the second cache, the created first connection is cached in the first cache, so that when the first connection is used later, the first connection can be directly reused from the first cache.

[0056] Optionally, before caching the first connection to the first cache, first determine whether the server meets the preset conditions. If the server meets the preset conditions, cache the created first connection to the first cache; if the server does not meet the preset conditions, release the created first connection. The preset condition may be that the server is a server in a preset server set. Exemplarily, the client analyzes historical connection data, determines the number of connections with each server in the historical connection, and puts the servers whose number of connections is greater than a threshold into a preset set to obtain the preset server set.

[0057] 205: Cache the first request in a third cache of the client, and after creating the first connection, send the first request cached in the third cache to the server through the created first connection.

[0058] Exemplarily, when it is determined that the client is currently creating a first connection, that is, the second cache caches a request sent through the first connection, the first request is directly cached in the third cache, and after detecting that the first connection is created, the first request cached in the third cache is sent to the server through the created first connection, that is, the first request is read from the third cache, and then the first request is sent to the server through the created first connection.

[0059] It can be seen that if the first connection is currently being established, the first request is cached in the third cache, so that the first connection is established again while the first connection is established, avoiding concurrent conflicts in connection establishment and reducing resource competition.

[0060] It can be seen that in an embodiment of the present application, when the client needs to send a first request to the server through the first connection, the client will first determine whether there is a reusable first connection from the historical connections of the first cache; if so, the client can directly reuse the first connection to send the first connection to avoid repeatedly creating the same connection; if it is not reusable, the client will determine whether the first connection is currently being created from the connection currently being created cached in the second cache, and if so, the first request will be cached in the third cache without creating the first connection again, and the first request will be sent through the first connection after the first connection is created, thereby solving the concurrency problem of connection creation; if the first connection is not currently being created, the first request will be cached in the third cache, and the first connection will be created, so that in the case where there is no reusable first connection and the first connection is not being created, the first connection for sending the first request is directly created to ensure that the first request is successfully sent.

[0061] In one embodiment of the present application, after the first request cached in the third cache is sent to the server through the established first connection, the first request is deleted from the third cache to avoid repeatedly sending the first request to the server.

[0062] It should be noted that if the number of requests that need to be sent through the first connection is cached in the third cache is multiple. For example, before caching the first request in the third cache, the client also caches other requests that need to be sent through the first connection. Therefore, the client will obtain the cache time of each of the above multiple requests cached in the third cache, and send the above multiple requests to the server in sequence through the created first connection according to the cache time from front to back. Similarly, after each request is sent, each request is deleted from the third cache.

[0063] In one embodiment of the present application, for the first cache, a first historical connection cached in the first cache is kept available through a heartbeat mechanism, that is, a heartbeat signal is sent between the client and the server through the first historical connection to ensure the availability of the first historical connection, wherein the first historical connection is any historical connection cached in the first cache.

[0064] It should be understood that if each historical connection cached in the first cache maintains a heartbeat connection, then as time accumulates, a large number of historical connections will be cached in the first cache, greatly affecting the performance of the first cache, and maintaining the availability of a large number of historical connections through heartbeat signals will occupy a large amount of computing resources of the client. Therefore, a cache cleaning mechanism is also provided in this application for the first cache.

[0065] Optionally, the first cache is cleared according to the survival time of the historical connection. Specifically, the survival time of the first historical connection is obtained, where the survival time can be the time from the moment when the first historical connection is cached to the current moment; if the survival time of the first historical connection is greater than a first threshold, the first historical connection is released.

[0066] Optionally, the first cache is cleared by the number of historical connections. Specifically, the number of historical connections cached in the first cache is obtained; when the number of historical connections cached in the first cache is greater than a second threshold, the number of historical usages of each historical connection cached in the first cache is obtained, wherein the number of historical usages of each historical connection is the total number of requests sent using the historical connection; and historical connections whose number of historical usages is less than the third threshold are deleted from the first cache.

[0067] Similarly, for the third cache, in order to avoid caching a large number of requests in the third cache, a corresponding cache clearing strategy must be set. Exemplarily, the cache duration of any request cached in the third cache is obtained; if the cache duration of any request is greater than a fourth threshold, the any request is deleted from the third cache. Optionally, in order to prevent the request in the third cache from expiring due to abnormal reasons (for example, network timeout or unknown reasons), resulting in the request cached in the third cache being unable to be sent, before deleting any request from the third cache, resend any request to the server, that is, follow Figure 2 The method shown re-executes the entire process of sending the arbitrary request.

[0068] In one embodiment of the present application, the client asynchronously creates the first connection by calling the operating system, that is, the client asynchronously creates the first connection. In the present application, when creating a connection, the client creates the connection in an asynchronous manner, thereby allowing the user thread to be decoupled from the IO thread, reducing the number of threads created, reducing context switching, improving overall performance, and reducing the impact of IO jitter, so that the user computing thread runs more stably.

[0069] See also Figure 3 , Figure 3 A schematic diagram of another request sending method provided in an embodiment of the present application.

[0070] like Figure 3As shown, when the client needs to send a first request to the server through the first connection, it is first determined whether the first connection is cached in the first cache. If the first connection is not cached, it is determined based on the second cache whether the client is currently creating the first connection; if the first connection is cached, it is determined whether the first connection is available. If available, the first connection is directly reused to send the first request to the server; if the first connection is not available, the first connection is removed from the first cache, and it is determined based on the second cache whether the client is currently creating the first connection.

[0071] Further, in the case of determining whether the client is currently creating the first connection, if the first connection is not currently being created, the first request is cached in the second cache, and the first connection is created; after the first connection is successfully created, the first request is sent to the client through the first connection, and the first connection is cached in the first cache; then, the first request is removed from the second cache, thereby avoiding the client from constantly creating the first connection; if the first connection is currently being created, the first request is cached in the third cache, and after the first connection is successfully created, the first request is sent to the client through the first connection, and the first request is deleted from the third cache; and when the request cached in the third cache expires, the request is also removed, but before removal, a retry process is triggered for the request, and the request is resent.

[0072] See also Figure 4 , Figure 4 The present application provides a functional unit block diagram of a client. The client 400 includes: a processing unit 401 and a transceiver unit 402;

[0073] A processing unit 401 is configured to determine whether there is an available first connection between the client and the server based on a historical connection cached in a first cache of the client when sending a first request to the server through a first connection;

[0074] If so, controlling the transceiver unit 402 to multiplex the first connection to send the first request to the server;

[0075] If not, determining whether the client is currently creating the first connection based on the connection currently being created cached in the second cache of the client;

[0076] If not, cache the first request to the second cache, and create the first connection. After the first connection is created, control the transceiver unit 402 to send the first request cached in the second cache to the server through the created first connection;

[0077] If yes, the first request is cached in a third cache of the client, and after the first connection is created, the control transceiver unit 402 sends the first request cached in the third cache to the server through the created first connection.

[0078] In one embodiment of the present application, in terms of determining whether the client is currently creating the first connection based on the connection currently being created cached in the second cache of the client, the processing unit 401 is specifically configured to:

[0079] Obtaining an identifier of a connection currently being created that is cached in the second cache;

[0080] Determine whether the identifier of the connection currently being created cached in the second cache has the first identifier of the first connection;

[0081] If so, determining that the client is currently creating the first connection;

[0082] If not, it is determined that the client is not currently creating the first connection.

[0083] In one embodiment of the present application, when the first request is cached in the second cache, after the first request cached in the second cache is sent to the server through the created first connection, the processing unit 401 is also used to: delete the first request from the second cache.

[0084] In one embodiment of the present application, after deleting the first request from the second cache, the processing unit 401 is also used to: when the server meets the preset conditions, cache the created first connection to the first cache; when the server does not meet the preset conditions, release the created first connection.

[0085] In one embodiment of the present application, when the first request is cached in the third cache of the client, after the first request cached in the third cache is sent to the server through the created first connection, the processing unit 401 is also used to: delete the first request from the third cache.

[0086] In one embodiment of the present application, the processing unit 401 is also used to control the transceiver unit 402 to send a heartbeat signal to the server through the first connection for a first historical connection cached in the first cache, so as to keep the first historical connection available, wherein the first historical connection is any historical connection cached in the first cache.

[0087] In one embodiment of the present application, the processing unit 401 is also used to obtain the survival time of the first historical connection cached in the first cache, wherein the first historical connection is any historical connection cached in the first cache; when the survival time of the first historical connection is greater than a first threshold, the first historical connection is released.

[0088] In one embodiment of the present application, the processing unit 401 is further configured to:

[0089] Obtaining the number of historical connections cached in the first cache;

[0090] If the number of historical connections cached in the first cache is greater than a second threshold, obtaining a historical usage count of each historical connection cached in the first cache;

[0091] The historical connections whose historical usage times are less than the third threshold are deleted from the first cache.

[0092] In one embodiment of the present application, the processing unit 401 is further configured to:

[0093] Obtaining a cache duration of any request cached in the third cache;

[0094] If the cache duration of any one of the requests is greater than a fourth threshold, the any one of the requests is deleted from the third cache.

[0095] In one embodiment of the present application, before deleting the any one request from the third cache, the processing unit 401 is further configured to: resend the any one request to the server.

[0096] In one embodiment of the present application, the first connection is asynchronously created by the client calling the operating system.

[0097] See also Figure 5 , Figure 5 The structure diagram of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 4 The client shown. Figure 5 As shown, the electronic device 500 includes a transceiver 501, a processor 502, a memory 503, a first cache 505, a second cache 506, and a third cache 507. They are connected via a bus 504. The memory 503 is used to store computer programs and data, and can transmit the data stored in the memory 503 to the processor 502.

[0098] The processor 502 is used to read the computer program in the memory 503 and perform the following operations:

[0099] When sending a first request to a server through a first connection, determining whether there is an available first connection between the client and the server based on historical connections cached in the first cache 505 of the client;

[0100] If so, control the transceiver 501 to multiplex the first connection to send the first request to the server;

[0101] If not, determining whether the client is currently creating the first connection based on the connection currently being created cached in the second cache 506 of the client;

[0102] If not, cache the first request to the second cache 506, and create the first connection. After the first connection is created, control the transceiver 501 to send the first request cached in the second cache 506 to the server through the created first connection;

[0103] If so, the first request is cached in the third cache 507 of the client, and after the first connection is created, the transceiver 501 is controlled to send the first request cached in the third cache 507 to the server through the created first connection.

[0104] In one embodiment of the present application, in terms of determining whether the client is currently creating the first connection based on the connection currently being created cached in the second cache 506 of the client, the processor 502 is specifically configured to perform the following operations:

[0105] Obtaining an identifier of a connection currently being created that is cached in the second cache 506;

[0106] Determine whether the identifier of the connection currently being created cached in the second cache 506 contains the first identifier of the first connection;

[0107] If so, determining that the client is currently creating the first connection;

[0108] If not, it is determined that the client is not currently creating the first connection.

[0109] In one embodiment of the present application, when the first request is cached in the second cache 506, after sending the first request cached in the second cache 506 to the server through the created first connection, the processor 502 is also used to perform the following operations: deleting the first request from the second cache 506.

[0110] In one embodiment of the present application, after deleting the first request from the second cache 506, the processor 502 is further used to perform the following operations: when the server meets the preset conditions, cache the created first connection to the first cache 505; when the server does not meet the preset conditions, release the created first connection.

[0111] In one embodiment of the present application, when the first request is cached in the third cache 507 of the client, after sending the first request cached in the third cache 507 to the server through the created first connection, the processor 502 is also used to perform the following operations: deleting the first request from the third cache 507.

[0112] In one embodiment of the present application, the processor 502 is further configured to perform the following operations:

[0113] For the first historical connection cached in the first cache 505 , the control transceiver 501 sends a heartbeat signal to the server through the first connection to keep the first historical connection available, wherein the first historical connection is any historical connection cached in the first cache 505 .

[0114] In one embodiment of the present application, the processor 502 is further configured to perform the following operations:

[0115] For the first historical connection cached in the first cache 505, obtain the survival time of the first historical connection, wherein the first historical connection is any historical connection cached in the first cache 505; when the survival time of the first historical connection is greater than a first threshold, release the first historical connection.

[0116] In one embodiment of the present application, the processor 502 is further configured to perform the following operations:

[0117] Obtain the number of historical connections cached in the first cache 505;

[0118] If the number of historical connections cached in the first cache 505 is greater than a second threshold, obtaining a historical usage count of each historical connection cached in the first cache 505;

[0119] The historical connections whose historical usage times are less than the third threshold are deleted from the first cache.

[0120] In one embodiment of the present application, the processor 502 is further configured to perform the following operations:

[0121] Obtaining a cache duration of any request cached in the third cache 507;

[0122] If the cache duration of any one of the requests is greater than a fourth threshold, the any one of the requests is deleted from the third cache 507 .

[0123] In one embodiment of the present application, before deleting any one request from the third cache 507, the processor 502 is further configured to perform the following operations:

[0124] Resend any one of the requests to the server.

[0125] In one embodiment of the present application, the first connection is asynchronously created by the client calling the operating system.

[0126] Specifically, the transceiver 501 may be Figure 4 The transceiver unit 402 of the client 400 of the embodiment described above, the processor 502 may be Figure 4 The processing unit 401 of the client 400 of the described embodiment.

[0127] It should be understood that the client in this application may include a smart phone (such as an Android phone, an iOS phone, a Windows Phone phone, etc.), a tablet computer, a PDA, a laptop computer, a mobile Internet device MID (Mobile Internet Devices, referred to as: MID) or a wearable device, etc. The above electronic devices are only examples, not exhaustive, and include but are not limited to the above electronic devices. In practical applications, the above electronic devices may also include: smart vehicle terminals, computer equipment, etc.

[0128] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. The computer program is executed by a processor to implement part or all of the steps of any one of the request sending methods recorded in the above method embodiments.

[0129] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute part or all of the steps of any one of the request sending methods recorded in the above method embodiments.

[0130] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.

[0131] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0132] In the several embodiments provided in the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of the units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be electrical or other forms.

[0133] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0134] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of a software program module.

[0135] If the integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a memory, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned memory includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or CD-ROM and other media that can store program codes.

[0136] A person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable memory, and the memory can include: a flash drive, a read-only memory (English: Read-Only Memory, abbreviated as: ROM), a random access memory (English: Random Access Memory, abbreviated as: RAM), a magnetic disk or an optical disk, etc.

[0137] The embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of ​​the present application. At the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A request sending method, It is characterized in that The method is applied to a client, and the method comprises: When sending a first request to a server through a first connection, determining whether there is an available first connection between the client and the server based on historical connections cached in a first cache of the client; If so, reuse the first connection to send the first request to the server; If not, determining whether the client is currently creating the first connection based on the connection currently being created cached in the second cache of the client, including: obtaining the identifier of the connection currently being created cached in the second cache; determining whether the identifier of the connection currently being created cached in the second cache has the first identifier of the first connection; if not, determining that the client is not currently creating the first connection; if so, determining that the client is currently creating the first connection; If not, cache the first request in the second cache, create the first connection, and after the first connection is created, send the first request cached in the second cache to the server through the created first connection; If so, cache the first request in a third cache of the client, and after creating the first connection, send the first request cached in the third cache to the server through the created first connection.

2. The method according to claim 1, It is characterized in that In the case where the first request is cached in the second cache, after sending the first request cached in the second cache to the server through the created first connection, the method further includes: The first request is deleted from the second cache.

3. The method according to claim 2, It is characterized in that After deleting the first request from the second cache, the method further includes: When the server meets a preset condition, the created first connection is cached in the first cache; When the server does not meet the preset condition, the created first connection is released.

4. The method according to any one of claims 1 to 3, It is characterized in that In the case where the first request is cached in the third cache of the client, after sending the first request cached in the third cache to the server through the created first connection, the method further includes: The first request is deleted from the third cache.

5. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: For a first historical connection cached in the first cache, a heartbeat signal is sent to the server through the first connection to keep the first historical connection available, wherein the first historical connection is any historical connection cached in the first cache.

6. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: For a first historical connection cached in the first cache, obtaining a survival time of the first historical connection, wherein the first historical connection is any historical connection cached in the first cache; When the survival time of the first historical connection is greater than a first threshold, the first historical connection is released.

7. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: Obtaining the number of historical connections cached in the first cache; If the number of historical connections cached in the first cache is greater than a second threshold, obtaining a historical usage count of each historical connection cached in the first cache; The historical connections whose historical usage times are less than the third threshold are deleted from the first cache.

8. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: Obtaining a cache duration of any request cached in the third cache; If the cache duration of any one of the requests is greater than a fourth threshold, the any one of the requests is deleted from the third cache.

9. The method according to claim 8, It is characterized in that Before deleting any one of the requests from the third cache, the method further includes: Resend any one of the requests to the server.

10. The method according to any one of claims 1 to 3, It is characterized in that The first connection is asynchronously created by the client calling the operating system.

11. A client, It is characterized in that The client comprises a processing unit and a transceiver unit; The processing unit is configured to determine whether there is an available first connection between the client and the server based on historical connections cached in the first cache of the client when sending a first request to the server through the first connection; If so, controlling the transceiver unit to multiplex the first connection to send the first request to the server; If not, determining whether the client is currently creating the first connection based on the connection currently being created cached in the second cache of the client, including: obtaining the identifier of the connection currently being created cached in the second cache; determining whether the identifier of the connection currently being created cached in the second cache has the first identifier of the first connection; if not, determining that the client is not currently creating the first connection; if so, determining that the client is currently creating the first connection; If not, cache the first request in the second cache and create the first connection. After the first connection is created, control the transceiver unit to send the first request cached in the second cache to the server through the created first connection; If so, cache the first request in a third cache of the client, and after the first connection is created, control the transceiver unit to send the first request cached in the third cache to the server through the created first connection.

12. An electronic device, It is characterized in that include: A processor and a memory, wherein the processor is connected to the memory, the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device executes the method as described in any one of claims 1 to 10.

13. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method according to any one of claims 1 to 10.