Method, device, storage medium and electronic device for sending query results
By using two waiting groups and multiple coroutines for parallel query in the field of software communication, the problem of low efficiency of data query service is solved and more efficient data query processing is achieved.
Patent Information
- Application Number
- CN202110696032.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-23
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2041-06-23
AI Technical Summary
In the field of software communication, data query services are less efficient, resulting in longer query tasks.
By using two waiting groups and multiple coroutines in parallel inquiries to achieve parallel processing of data query requests. Specific steps include: save the received data query request to the first waiting group, transfer to the second waiting group, and pass the data matching data through multiple coroutines, and finally send the query results to the corresponding user account.
It improves the efficiency of data query, shortens the query time, and solves the problem of low data query efficiency.
Smart Images

Figure CN113434541B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a method, device, storage medium and electronic device for sending query results. Background Art
[0002] In the field of software communication, the client and the backend service need to interact through network requests. The frontend application needs to obtain data from the backend service and present it to the client, as well as upload data to the backend for processing. In this way, data transmission is achieved and data query services are provided to customers.
[0003] When providing data query services to customers, we usually query in the order of query requests. For example, when a user queries information through a system, he needs to call an external interface. Let's assume two interfaces, api1 and api2. The interface api1 takes 200 milliseconds, and the interface api2 takes 300 milliseconds. The external interface can only query the information of a single user at a time. When querying a single user, the total time required for non-concurrent requests is the time taken by api1 and api2. That is, 200ms+300ms=500ms. The total time taken for this query is 500ms. When querying two users, the total time required for non-concurrent requests is twice the time taken by api1 and api2, that is, (200ms+300ms)*2=1000ms, and the total time taken for this query is 1000ms. As a result, the query task takes a long time and the query efficiency is low.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The present application provides a method, device, storage medium and electronic device for sending query results, so as to at least solve the technical problem of low efficiency of data query in related technologies.
[0006] According to one aspect of an embodiment of the present application, a method for sending query results is provided, including: by executing a first task, saving a received data query request to a first waiting group, the data query request being a query request sent by a user account; when the first task is completed, transferring the data query request in the first waiting group to a second waiting group; by executing a second task, calling multiple coroutines to query in parallel the data matching the data query request in the second waiting group, to obtain multiple query results, wherein the second task and the first task have different running time periods; after determining that the multiple coroutine queries are completed, sending each query result to the corresponding user account.
[0007] Optionally, calling multiple coroutines to query in parallel the data that matches the data query request in the second waiting group to obtain multiple query results includes: determining multiple target operations by analyzing all data query requests in the second waiting group, wherein each target operation is used to request to obtain a type of data requested by the data query request; configuring a corresponding coroutine for each target operation to obtain multiple coroutines; and calling multiple coroutines to query in parallel the data requested by the target operation.
[0008] Optionally, determining multiple target operations by analyzing all data query requests in the second waiting group includes processing each data query request in the following manner: determining multiple data types of the query data requested by the first data query request, wherein the first data query request is a query request that has not been processed among all data query requests; in a case where the first data type does not exist among the multiple data types of the first data query request, generating multiple target operations whose number is the same as the number of data types of the first data query request, wherein the first data type belongs to one of the multiple data types of the second data query request, and the second data query request is a query request that has been processed among all data query requests; in a case where the first data type exists among the multiple data types of the first data query request, generating multiple target operations whose number is the same as the second data type, and merging the operation of querying the first data type according to the first data query request into the operation of querying the first data type according to the second data query request, wherein the second data type belongs to the multiple data types of the first data and does not belong to the multiple data types of the second data query request.
[0009] Optionally, calling multiple coroutines to query the data requested by the target operation in parallel includes: obtaining the target port for the data requested to be queried by each target operation; determining the target calling path in the candidate port set according to the target port, wherein the candidate port set stores a plurality of candidate ports and the calling path of each candidate port, and the candidate port is the port for the data requested to be queried by the data query request; calling the target calling path to query the data requested to be queried by the target operation.
[0010] Optionally, calling the target calling path to query the data requested by the target operation request includes: obtaining a first access result of the target calling path; when the first access result is that the access data is obtained, determining the access data as the data requested by the target operation request; when the first access result is that the access data cannot be obtained, re-accessing after delaying a preset access time to obtain a second access result; determining the access data of the second access result as the data requested by the target operation request.
[0011] Optionally, after determining that multiple coroutines have been queried, sending each query result to a corresponding user account includes: obtaining the query result of each coroutine in the multiple coroutines; storing the query results in a result set, wherein the result set corresponds to storing the data query request sent by the received user account and the multiple query results; obtaining the first counter value of the second waiting group, wherein the first counter value is used to indicate the number of multiple coroutines to be queried in the second waiting group; when the first counter value of the second waiting group meets the first preset condition, determining that the query of multiple coroutines in the second waiting group is completed; and sending each query result to the corresponding user account according to the mapping relationship between the data query request and the multiple query result pieces stored in the result set.
[0012] Optionally, transferring the data query requests in the first waiting group to the second waiting group includes: obtaining the number of data query requests in the first waiting group; transferring the data query requests in the first waiting group to the second waiting group one by one; detecting the second counter value of the second counter, wherein the second counter value is used to indicate the number of data query requests to be transferred contained in the first waiting group; when the second counter value satisfies a second preset condition, determining that all data query requests in the first waiting group are transferred to the second waiting group, and controlling the second waiting group to be in a blocked state, wherein the second waiting group in the blocked state cannot store business requests from other waiting groups.
[0013] According to another aspect of an embodiment of the present application, a device for sending query results is also provided, including: a saving module, used to save a received data query request to a first waiting group by executing a first task, wherein the data query request is a query request sent by a user account; a transfer module, used to transfer the data query request in the first waiting group to a second waiting group when the first task is completed; a query module, used to call multiple coroutines in parallel to query data matching the data query request in the second waiting group by executing a second task, to obtain multiple query results, wherein the second task and the first task have different running time periods; a sending module, used to send each query result to a corresponding user account after determining that the multiple coroutine queries are completed.
[0014] According to another aspect of an embodiment of the present application, a storage medium is further provided, which includes a stored program, and the above method is executed when the program is run.
[0015] According to another aspect of an embodiment of the present application, an electronic device is further provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the above method through the computer program.
[0016] In an embodiment of the present application, by executing the first task, the received data query request is saved in the first waiting group, and the data query request is a query request sent by the user account; when the first task is completed, the data query request in the first waiting group is transferred to the second waiting group; by executing the second task, multiple coroutines are called to query the data matching the data query request in the second waiting group in parallel, and multiple query results are obtained, wherein the second task and the first task have different running time periods; after determining that the queries of multiple coroutines are completed, each query result is sent to the corresponding user account, using the first waiting group and the second waiting group, the first waiting group receives the data query request sent by the user account, and in the first waiting group After receiving the data query request from the user account, the data query request is forwarded to the second waiting group. After receiving the data query request forwarded by the first waiting group, the second waiting group calls multiple coroutines to run in parallel, thereby realizing parallel query of the data requested by the data query request, obtaining the query result, and sending the query result obtained by the query to the corresponding user account after all the coroutines of the data query request in the second waiting group are executed. The purpose of using two waiting groups to cyclically execute the acceptance and query operations of the query request and using multiple coroutines to parallelly execute the data query request sent by the user account is achieved, thereby achieving the technical effect of improving the efficiency of data query, and then solving the technical problem of low efficiency of data query. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0019] Figure 1 is a schematic diagram of a hardware environment of a method for sending query results according to an embodiment of the present application;
[0020] Figure 2 is a flowchart of an optional method for sending query results according to an embodiment of the present application;
[0021] Figure 3 is an optional double-loop data query schematic diagram according to an embodiment of the present application;
[0022] Figure 4 is a schematic diagram of an optional query result sending device according to an embodiment of the present application;
[0023] Figure 5 It is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only 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 should fall within the scope of protection of the present application.
[0025] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0026] According to one aspect of an embodiment of the present application, an embodiment of a method for sending a query result is provided.
[0027] Optionally, in this embodiment, the method for sending the query result can be applied to: Figure 1 In the hardware environment composed of the terminal 101 and the server 103 shown in FIG. Figure 1 As shown, the server 103 is connected to the terminal 101 through a network, and can be used to provide services (such as data query services, etc.) to the terminal or the client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server 103. The above network includes but is not limited to: a wide area network, a metropolitan area network or a local area network, and the terminal 101 is not limited to a PC, a mobile phone, a tablet computer, etc. The method for sending the query result of the embodiment of the present application can be executed by the server 103, or by the terminal 101, or by the server 103 and the terminal 101. Among them, the terminal 101 executes the method for sending the query result of the embodiment of the present application, and it can also be executed by the client installed thereon.
[0028] Figure 2is a flowchart of an optional method for sending query results according to an embodiment of the present application, such as Figure 2 As shown, the method may include the following steps:
[0029] Step S202, by executing the first task, saving the received data query request to the first waiting group, the data query request being a query request sent by the user account;
[0030] Step S204, when the first task is completed, the data query request in the first waiting group is transferred to the second waiting group;
[0031] Step S206, by executing the second task, calling multiple coroutines to query in parallel the data matching the data query request in the second waiting group, and obtaining multiple query results, wherein the second task and the first task have different running time periods;
[0032] Step S208, after determining that multiple coroutine queries are completed, each query result is sent to the corresponding user account.
[0033] Through the above steps S202 to S208, the first waiting group and the second waiting group are used, the first waiting group receives the data query request sent by the user account, and after the first waiting group receives the data query request from the user account, the data query request is forwarded to the second waiting group. After receiving the data query request forwarded by the first waiting group, the second waiting group calls multiple coroutines to run in parallel, thereby realizing parallel query of the data requested by the data query request, obtaining the query result, and sending the query result obtained by the query to the corresponding user account after all the coroutines of the data query request in the second waiting group are executed. The purpose of using two waiting groups to cyclically execute the query request acceptance and query operations, and at the same time using multiple coroutines to parallelly execute the data query request sent by the user account is achieved, thereby achieving the technical effect of improving the efficiency of data query, and then solving the technical problem of low efficiency of data query.
[0034] In the technical solution provided in step S202, the number of data query requests may be one or more. The data query request may be a request to call the interface of an external system to query data, or a request to call the interfaces of two external systems to query data, or a request to call the interfaces of multiple external systems to query data. This solution does not limit this.
[0035] Optionally, in this embodiment, the data query requests in the first waiting group may be received within a preset time period, may be a predetermined number of data query requests received, or may be data query requests received with a predetermined buffer size.
[0036] Optionally, in this embodiment, the first waiting group may be constructed according to the received data query request, or may be a pre-set waiting group of a preset size.
[0037] In the technical solution provided in step S204, the data query request is transferred from the first waiting group to the second waiting group by forwarding one by one or in batches.
[0038] Optionally, in this embodiment, during the process of transferring the data query request from the first waiting group to the second waiting group, the data in the first waiting group can be compressed, encrypted and transmitted in batches. For example, the first waiting group issues a data transmission request, and the data transmission request includes the identifier of the first waiting group, the identifier of the second waiting group, etc. The server generates a random password for encryption and decryption, and sends the random password to the first waiting group, which is used to encrypt and compress the data query request in the first waiting group, and forward the encrypted file to the second waiting group. The second waiting group then sends a random password acquisition request to the server, and the password acquisition request includes the first waiting group identifier and the second waiting group identifier. The server compares the identification information and sends the random password to the second waiting group after a match, and decrypts according to the acquired password.
[0039] Optionally, in this embodiment, the second waiting group may be constructed according to the received data query request, or may be a pre-set waiting group of a preset size.
[0040] In the technical solution provided in step S206, when the second waiting group calls the coroutine to execute the data query request, the first waiting group may be in a blocked state, or may be receiving data query requests sent by other accounts, which is not limited in this solution.
[0041] Optionally, in this embodiment, the query result can be the data requested by the data query request, or it can be data related to the data requested by the data query request. For example, the data query request requests to query the company's profit, and the query result can be the company's profit directly queried. When the company's profit cannot be queried, the company's transaction and cost data can also be queried. This solution does not limit this.
[0042] In the technical solution provided in step S208, after all the coroutine tasks in the second waiting group are executed, the query results are sent to the corresponding user accounts, thereby avoiding erroneous sending of the query results.
[0043] As an optional embodiment, calling multiple coroutines to query in parallel the data matching the data query request in the second waiting group to obtain multiple query results includes:
[0044] S11, determining a plurality of target operations by analyzing all data query requests in the second waiting group, wherein each target operation is used to request to obtain a type of data requested by the data query request;
[0045] S12, configuring a corresponding coroutine for each target operation to obtain multiple coroutines;
[0046] S13, calling multiple coroutines to query the data requested by the target operation in parallel.
[0047] Optionally, in this embodiment, a data query request may include one target operation or multiple target operations. For example, a data query request for querying information of a certain object includes operations such as querying identity information and home address information.
[0048] Optionally, in this embodiment, the target operation may be used to obtain a type of data requested by the data query request, and may also be used to obtain certain data requested by the data query request.
[0049] Through the above steps, the target operation contained in the data query request is determined according to the data type requested by the data query request, and the coroutine is configured according to the determined target operation. By calling the coroutine and executing the coroutine tasks in parallel, the parallel execution of the data query request is realized, thereby improving the execution speed of the data query request and shortening the data query time.
[0050] As an optional embodiment, determining multiple target operations by analyzing all data query requests in the second waiting group includes processing each data query request in the following manner:
[0051] S21, determining multiple data types of the query data requested by a first data query request, wherein the first data query request is an unprocessed query request among all data query requests;
[0052] S22, if the first data type does not exist in the multiple data types of the first data query request, generate multiple target operations whose number is the same as the number of data types of the first data query request, wherein the first data type belongs to one of the multiple data types of the second data query request, and the second data query request is a query request that has been processed among all the data query requests;
[0053] S23, when the first data type exists in the multiple data types of the first data query request, generate multiple target operations with the same number as the second data type, and merge the operation of querying the first data type according to the first data query request into the operation of querying the first data type according to the second data query request, wherein the second data type belongs to the multiple data types of the first data and does not belong to the multiple data types of the second data query request.
[0054] Optionally, in this embodiment, the data type can be divided according to the query port or according to the queried data. For example, data query requests using the same port for query can be classified as the same data type, and data query requests with the same data attributes can be classified as the same data type.
[0055] As an optional embodiment, calling multiple coroutines to query the data requested by the target operation in parallel includes:
[0056] S31, obtaining the target port of the query data requested by each target operation;
[0057] S32, determining a target calling path in a candidate port set according to the target port, wherein the candidate port set stores a plurality of candidate ports and a calling path of each candidate port, and the candidate port is a port for which the data query request requests to query data;
[0058] S33, the calling target calls the path to query the data requested by the target operation.
[0059] Optionally, in this embodiment, the candidate port set may be pre-set by a program setting personnel and used to store available query ports and port call paths. The candidate port set may also be obtained by saving historical query records.
[0060] Through the above steps, the target operation includes information about the target port used to request the query data. By obtaining the target port corresponding to the target operation and searching for a matching call path in a preset port set based on the target port, it is avoided that the port path needs to be traversed to query the data when querying the data, thereby improving the accuracy of the determined port call path and thus improving the query efficiency.
[0061] As an optional embodiment, the data requested to be queried by the target calling path query target operation request includes:
[0062] S41, obtaining a first access result of a target calling path;
[0063] S42, when the first access result is that the access data is obtained, determining the access data as the data requested to be queried by the target operation request;
[0064] S43, when the first access result is failure to obtain access data, re-access after a preset access time delay to obtain a second access result;
[0065] S44: Determine the access data of the second access result as the data requested to be queried by the target operation request.
[0066] Optionally, in this embodiment, the preset access time can be flexibly set as needed. The preset access time can be but is not limited to being set to 1 second, 2 seconds, 3 seconds, 5 seconds, etc. When access fails, it may be caused by network fluctuations or path congestion, etc. Therefore, after the access fails, wait for the preset time and then access again to obtain the requested query data.
[0067] Through the above steps, by setting the preset access time, when the data query fails by calling the path access port, the query is repeated after a delay until the data location requested is obtained, thereby avoiding data query failures caused by network fluctuations, path congestion, network delays, etc., greatly optimizing the access process of port access and improving data query efficiency.
[0068] As an optional embodiment, after determining that multiple coroutine queries are completed, sending each query result to a corresponding user account includes:
[0069] S51, obtaining a query result of each coroutine in the multiple coroutines;
[0070] S52, storing the query result in a result set, wherein the result set stores the data query request sent by the received user account and the multiple query results;
[0071] S53, obtaining a first counter value of the second waiting group, wherein the first counter value is used to indicate the number of multiple coroutines to be queried in the second waiting group;
[0072] S54, when the first counter value of the second waiting group meets the first preset condition, determining that the query of multiple coroutines in the second waiting group is completed;
[0073] S55, sending each query result to a corresponding user account according to the mapping relationship between the data query request and the plurality of query result pieces stored in the result set.
[0074] Optionally, in this embodiment, the counter of the second waiting group is used to count the coroutines to be executed in the second waiting group, and the counter value of the second waiting group is reduced by one every time a coroutine in the second waiting group is executed.
[0075] Optionally, in this embodiment, the first preset condition may be that the first counter value returns to zero, the first counter value is less than a certain set threshold, and so on.
[0076] Optionally, in this embodiment, the result set can be a sufficiently large result set pre-set by the program setting personnel, or it can be determined by the query results obtained by the second waiting group querying the data query request received by the first waiting group and the data query request of the first waiting group. This solution does not limit this.
[0077] Optionally, in this embodiment, after the second waiting group receives the data query request from the first waiting group, the second waiting group will be in a blocked state. At this time, the second waiting group will not receive data query requests from other waiting groups. After the second waiting group executes all coroutine tasks, the data query requests in the waiting group will be cleared and the second waiting group will be released. At this time, the second waiting group can continue to receive other data query requests forwarded by the first waiting group.
[0078] Optionally, in this embodiment, the total time for the second waiting group to call the coroutine to execute the data query request is the longest execution time among the data query requests. For example, there are 4 data query requests, and 4 coroutines need to be called to execute the data query requests. Coroutine 1 takes 100 milliseconds, coroutine 2 takes 200 milliseconds, coroutine 3 takes 300 milliseconds, and coroutine 4 takes 300 milliseconds. Therefore, the total time for the second waiting group to call the coroutine to execute the data query request is 300 milliseconds.
[0079] Through the above steps, after the first waiting group receives the data query request, it stores the data query request in the result set for storage. After the second waiting group queries the data query request and obtains the query result, it stores the query result in the result set accordingly. After the coroutine task in the second waiting group is executed, the query results stored in the waiting group are uniformly sent to the corresponding user account, thereby ensuring the accuracy of the query result sending and avoiding data confusion caused by the concurrency of data queries and the large number of query results.
[0080] As an optional embodiment, transferring the data query request in the first waiting group to the second waiting group includes:
[0081] S61, obtaining the number of data query requests in the first waiting group;
[0082] S62, transferring the data query requests in the first waiting group to the second waiting group one by one;
[0083] S63, detecting a second counter value of a second counter, wherein the second counter value is used to indicate the number of data query requests to be transferred contained in the first waiting group;
[0084] S64, when the second counter value meets the second preset condition, determine that all data query requests in the first waiting group are transferred to the second waiting group, and control the second waiting group to be in a blocked state, wherein the second waiting group in the blocked state cannot store business requests from other waiting groups.
[0085] Optionally, in this embodiment, after receiving the data query request, the first waiting group will be in a blocked state. The first waiting group in the blocked state will no longer receive data query requests. After the data in the first waiting group is transferred to the second waiting group, the first waiting group will be released. At this time, the first waiting group can accept data query requests sent by other user accounts again.
[0086] Optionally, in this embodiment, the counter of the first waiting group is used to count the number of data query requests to be forwarded in the first waiting group. Each time a data transmission request in the first waiting group is forwarded, the counter value of the first waiting group is reduced by one.
[0087] Optionally, in this embodiment, the second preset condition may be that the second counter value returns to zero, the second counter value is less than a certain set threshold, and so on.
[0088] Through the above steps, a counter is set for the first waiting group. After the first waiting group completes each data forwarding operation, the counter value of the first waiting group is reduced by one. When the counter value of the second waiting group meets the preset conditions, it is determined that the data query request in the first waiting group is forwarded, and the second waiting group is controlled to be blocked. The second waiting group cannot receive the data query requests forwarded by other waiting groups, thereby ensuring the smooth operation of the program and avoiding query result errors caused by confusion in forwarding data query requests.
[0089] Figure 3 is an optional double-loop data query schematic diagram according to an embodiment of the present application, such as Figure 3 As shown:
[0090] S301, the outer loop defines a waiting group for receiving data query requests sent by user accounts, the outer loop waiting group sets a counter, the initial value of the counter is the data query request value received by the outer loop waiting group, the outer loop forwards the received data query request to the inner loop waiting group and the result set channel, each time the forwarding is completed, the counter value is reduced by one, until the counter value returns to zero, the inner loop waiting group is controlled to be in a blocked state, at which time the inner loop waiting group cannot receive data query requests forwarded from other waiting groups; the inner loop defines a waiting group, the inner loop waiting group is used to call the coroutine to execute the data transmission request forwarded by the outer loop waiting group in parallel; a buffered result set channel is defined, the buffer size can be set by the program setting personnel according to the needs, and can also be set according to the Cartesian product of the slices of the outer loop waiting group and the inner loop waiting group.
[0091] S302, the inner loop calls the coroutines equal to the number of data query requests to execute the data query requests forwarded by the first waiting group in parallel, the inner loop waiting group sets a counter, the counter value is the number of data transmission requests received by the inner loop waiting group, each time the inner loop waiting group completes the execution of a data query request, the counter value of the inner loop waiting group is reduced by one, and the query results are stored in the buffered result set channel accordingly. When the counter value of the inner loop waiting group returns to zero, the blocking state of the inner loop waiting group is released. At this time, the inner loop waiting group can receive the data query requests forwarded by other waiting groups again, and control the result set channel to send the query results to the user account.
[0092] S303, the buffered result set channel stores the data query request and query result sent by the user account. When all data queries of the inner loop waiting group are completed, the result set channel forwards the query result to the corresponding user account according to the corresponding relationship.
[0093] 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 preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0094] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for an electronic device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of each embodiment of the present application.
[0095] According to another aspect of an embodiment of the present application, a query result sending device for implementing the above-mentioned query result sending method is also provided. Figure 4 is a schematic diagram of an optional query result sending device according to an embodiment of the present application, such as Figure 4 As shown, the device may include:
[0096] A saving module 42, configured to save the received data query request to a first waiting group by executing a first task, wherein the data query request is a query request sent by a user account;
[0097] A transfer module 44, configured to transfer the data query request in the first waiting group to the second waiting group when the first task is completed;
[0098] A query module 46 is used to call multiple coroutines to query the data matching the data query request in the second waiting group in parallel by executing the second task, and obtain multiple query results, wherein the second task and the first task have different running time periods;
[0099] The sending module 48 is used to send each query result to the corresponding user account after determining that the multiple coroutine queries are completed.
[0100] It should be noted that the saving module 42 in this embodiment can be used to execute step S202 in the embodiment of the present application, the transfer module 44 in this embodiment can be used to execute step S204 in the embodiment of the present application, the query module 46 in this embodiment can be used to execute step S206 in the embodiment of the present application, and the sending module 48 in this embodiment can be used to execute step S208 in the embodiment of the present application.
[0101] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware.
[0102] Through the above modules, the technical problem of low efficiency of data query can be solved, thereby achieving the technical effect of improving the efficiency of data query.
[0103] Optionally, the query module includes: an analysis unit, used to determine multiple target operations by analyzing all data query requests in the second waiting group, wherein each target operation is used to request to obtain a type of data requested by the data query request; a configuration unit, used to configure a corresponding coroutine for each target operation to obtain multiple coroutines; and a query unit, used to call multiple coroutines to query the data requested by the target operation in parallel.
[0104] Optionally, the analysis unit is used to process each data query request in the following manner: determine multiple data types of the query data requested by the first data query request, wherein the first data query request is a query request that has not been processed among all the data query requests; if the first data type does not exist among the multiple data types of the first data query request, generate multiple target operations with the same number as the number of data types of the first data query request, wherein the first data type belongs to one of the multiple data types of the second data query request, and the second data query request is a query request that has been processed among all the data query requests; if the first data type exists among the multiple data types of the first data query request, generate multiple target operations with the same number as the second data type, and merge the operation of querying the first data type according to the first data query request into the operation of querying the first data type according to the second data query request, wherein the second data type belongs to the multiple data types of the first data and does not belong to the multiple data types of the second data query request.
[0105] Optionally, the query unit is used to: obtain the target port for querying data requested by each target operation; determine the target calling path in the candidate port set according to the target port, wherein the candidate port set stores a plurality of candidate ports and the calling path of each candidate port, and the candidate port is the port for querying data requested by the data query request; call the target calling path to query the data requested by the target operation.
[0106] Optionally, the query unit is used to: obtain a first access result of the target call path; when the first access result is that the access data is obtained, determine the access data as the data requested for query by the target operation request; when the first access result is that the access data fails to be obtained, re-access after delaying a preset access time to obtain a second access result; determine the access data of the second access result as the data requested for query by the target operation request.
[0107] Optionally, the sending module includes: a first acquisition unit, used to obtain the query result of each coroutine in multiple coroutines; a storage unit, used to store the query result in a result set, wherein the result set corresponds to the data query request sent by the received user account and multiple query results; a second acquisition unit, used to obtain the first counter value of the second waiting group, wherein the first counter value is used to indicate the number of multiple coroutines to be queried in the second waiting group; a first determination unit, used to determine that the query of multiple coroutines in the second waiting group is completed when the first counter value of the second waiting group meets a first preset condition; a sending unit, used to send each query result to the corresponding user account according to the mapping relationship between the data query request and the multiple query result pieces stored in the result set.
[0108] Optionally, the transfer module includes: a third acquisition unit, used to acquire the number of data query requests in the first waiting group; a transfer unit, used to transfer the data query requests in the first waiting group to the second waiting group one by one; a detection unit, used to detect the second counter value of the second counter, wherein the second counter value is used to indicate the number of data query requests to be transferred contained in the first waiting group; a second determination unit, used to determine that all data query requests in the first waiting group are transferred to the second waiting group when the second counter value meets a second preset condition, and control the second waiting group to be in a blocked state, wherein the second waiting group in the blocked state cannot store business requests from other waiting groups.
[0109] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.
[0110] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned method for sending query results is also provided.
[0111] Figure 5 is a structural block diagram of an electronic device according to an embodiment of the present application, such as Figure 5 As shown, the electronic device may include: one or more (only one is shown in the figure) processors 501, a memory 503, and a transmission device 505, such as Figure 5 As shown, the electronic device may further include an input / output device 507 .
[0112] Among them, the memory 503 can be used to store software programs and modules, such as the program instructions / modules corresponding to the method and device for sending the query results in the embodiment of the present application. The processor 501 executes various functional applications and data processing by running the software programs and modules stored in the memory 503, that is, the method for sending the query results described above is realized. The memory 503 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 503 may further include a memory remotely arranged relative to the processor 501, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0113] The above-mentioned transmission device 505 is used to receive or send data via a network, and can also be used for data transmission between a processor and a memory. The above-mentioned network specific examples may include wired networks and wireless networks. In one example, the transmission device 505 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 505 is a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.
[0114] Specifically, the memory 503 is used to store application programs.
[0115] The processor 501 can call the application stored in the memory 503 through the transmission device 505 to perform the following steps: by executing the first task, the received data query request is saved to the first waiting group, and the data query request is a query request sent by the user account; when the first task is completed, the data query request in the first waiting group is transferred to the second waiting group; by executing the second task, multiple coroutines are called to query the data matching the data query request in the second waiting group in parallel to obtain multiple query results, wherein the second task and the first task have different running time periods; after determining that the multiple coroutine queries are completed, each query result is sent to the corresponding user account.
[0116] By adopting the embodiment of the present application, a method, device, storage medium and electronic device for sending query results are provided. A first waiting group and a second waiting group are used, the first waiting group receives a data query request sent by a user account, and after the first waiting group receives the data query request from the user account, the data query request is forwarded to the second waiting group, and after the second waiting group receives the data query request forwarded by the first waiting group, multiple coroutines are called to run in parallel, thereby realizing parallel query of the data requested by the data query request, obtaining the query result, and after all the coroutines of the data query request in the second waiting group are executed, the query result obtained by the query is sent to the corresponding user account, achieving the purpose of using two waiting groups to cyclically execute the query request acceptance and query operation, and at the same time using multiple coroutines to execute the data query request sent by the user account in parallel, thereby achieving the technical effect of improving the efficiency of data query, and then solving the technical problem of low efficiency of data query.
[0117] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0118] It can be understood by those skilled in the art that Figure 5The structure shown is for illustration only, and the electronic device may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (MID), a PAD, or other electronic devices. Figure 5 The structure of the electronic device is not limited. Figure 5 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 5 Different configurations are shown.
[0119] A person of ordinary skill 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 the hardware related to the electronic device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0120] The embodiment of the present application further provides a storage medium. Optionally, in this embodiment, the storage medium can be used to execute the program code of the method for sending the query result.
[0121] Optionally, in this embodiment, the storage medium may be located on at least one network device among a plurality of network devices in the network shown in the above embodiment.
[0122] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps: by executing the first task, the received data query request is saved to the first waiting group, and the data query request is a query request sent by the user account; when the first task is completed, the data query request in the first waiting group is transferred to the second waiting group; by executing the second task, multiple coroutines are called to query the data matching the data query request in the second waiting group in parallel to obtain multiple query results, wherein the second task and the first task have different running time periods; after determining that the multiple coroutine queries are completed, each query result is sent to the corresponding user account. Optionally, the specific examples in this embodiment can refer to the examples described in the above embodiments, and this embodiment will not be repeated here.
[0123] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.
[0124] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0125] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, 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, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which can be personal computers, servers or network devices, etc.) to execute all or part of the steps of the methods of each embodiment of the present application.
[0126] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0127] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, for example, 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, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0128] 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.
[0129] 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-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0130] The above are only preferred implementations of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for sending a query result, characterized in that: include: By executing the first task, the received data query request is saved to the first waiting group, wherein the data query request is a query request sent by the user account; When the first task is completed, transferring the data query request in the first waiting group to the second waiting group; By executing the second task, calling multiple coroutines to query the data matching the data query request in the second waiting group in parallel, and obtaining multiple query results, wherein the second task and the first task have different running time periods; After determining that the multiple coroutine queries are completed, sending each of the query results to the corresponding user account; Wherein, transferring the data query requests in the first waiting group to the second waiting group includes: obtaining the number of data query requests in the first waiting group; transferring the data query requests in the first waiting group to the second waiting group one by one; detecting a second counter value of a second counter, wherein the second counter value is used to indicate the number of data query requests to be transferred contained in the first waiting group; when the second counter value satisfies a second preset condition, determining that all data query requests in the first waiting group are transferred to the second waiting group, and controlling the second waiting group to be in a blocked state, wherein the second waiting group in a blocked state cannot store service requests from other waiting groups; Among them, calling the multiple coroutines to query the data matched with the data query request in the second waiting group in parallel to obtain the multiple query results includes: determining multiple target operations by analyzing all data query requests in the second waiting group, wherein each target operation is used to request to obtain a type of data requested by the data query request; configuring a corresponding coroutine for each target operation to obtain the multiple coroutines; calling the multiple coroutines to query the data requested by the target operation in parallel; Among them, after determining that the query of the multiple coroutines is completed, sending each of the query results to the corresponding user account includes: obtaining the query result of each coroutine in the multiple coroutines; storing the query results in a result set, wherein the result set corresponds to storing the data query request sent by the user account and the multiple query results; obtaining the first counter value of the second waiting group, wherein the first counter value is used to indicate the number of the multiple coroutines to be queried in the second waiting group; when the first counter value of the second waiting group meets the first preset condition, determining that the query of the multiple coroutines in the second waiting group is completed; and sending each of the query results to the corresponding user account according to the mapping relationship between the data query request and the multiple query result pieces stored in the result set.
2. The method according to claim 1, characterized in that: Determining the plurality of target operations by analyzing all the data query requests in the second waiting group includes processing each of the data query requests in the following manner: Determine multiple data types of the query data requested by a first data query request, wherein the first data query request is an unprocessed query request among all the data query requests; In a case where the first data type does not exist in the multiple data types of the first data query request, generating a plurality of the target operations whose number is the same as the number of data types of the first data query request, wherein the first data type belongs to one of the multiple data types of the second data query request, and the second data query request is a query request that has been processed among all the data query requests; In the case that the first data type exists among the multiple data types of the first data query request, a plurality of the target operations having the same number as the second data type are generated, and the operation of querying the first data type according to the first data query request is merged into the operation of querying the first data type according to the second data query request, wherein the second data type belongs to the multiple data types of the first data and does not belong to the multiple data types of the second data query request.
3. The method according to claim 1, characterized in that Calling the multiple coroutines to query the data requested by the target operation in parallel includes: Obtaining a target port for querying data requested by each target operation; Determine a target call path in a candidate port set according to the target port, wherein the candidate port set stores a plurality of candidate ports and a call path of each candidate port, and the candidate port is a port for querying data requested by the data query request; The target calling path is called to query the data requested by the target operation.
4. The method according to claim 3, characterized in that: The data requested to be queried by calling the target calling path to query the target operation includes: Obtaining a first access result of the target call path; When the first access result is that access data is obtained, determining the access data as the data requested to be queried by the target operation request; When the first access result is a failure to obtain the access data, re-access after a preset access time delay to obtain a second access result; The access data of the second access result is determined as the data requested to be queried by the target operation request.
5. The method according to claim 1, characterized in that Transferring the data query request in the first waiting group to the second waiting group comprises: Obtaining the number of the data query requests in the first waiting group; Transferring the data query requests in the first waiting group to the second waiting group one by one; detecting a second counter value of a second counter, wherein the second counter value is used to indicate the number of the data query requests to be transferred contained in the first waiting group; When the second counter value meets the second preset condition, it is determined that all the data query requests in the first waiting group are transferred to the second waiting group, and the second waiting group is controlled to be in a blocked state, wherein the second waiting group in the blocked state cannot store business requests from other waiting groups.
6. A device for sending query results, characterized in that: include: A saving module, configured to save the received data query request to a first waiting group by executing a first task, wherein the data query request is a query request sent by a user account; A transfer module, used for transferring the data query request in the first waiting group to the second waiting group when the first task is completed; A query module, configured to call a plurality of coroutines to query in parallel the data matching the data query request in the second waiting group by executing a second task, and obtain a plurality of query results, wherein the second task and the first task have different running time periods; A sending module, configured to send each query result to the corresponding user account after determining that the multiple coroutine queries are completed; The transfer module is further used to: obtain the number of data query requests in the first waiting group; transfer the data query requests in the first waiting group to the second waiting group one by one; detect the second counter value of the second counter, wherein the second counter value is used to indicate the number of data query requests to be transferred contained in the first waiting group; when the second counter value meets the second preset condition, determine that all data query requests in the first waiting group are transferred to the second waiting group, and control the second waiting group to be in a blocked state, wherein the second waiting group in the blocked state cannot store service requests from other waiting groups; The query module includes: an analysis unit, used to determine multiple target operations by analyzing all data query requests in the second waiting group, wherein each target operation is used to request to obtain a type of data requested by the data query request; a configuration unit, used to configure a corresponding coroutine for each target operation to obtain multiple coroutines; a query unit, used to call multiple coroutines to query the data requested by the target operation in parallel; The sending module includes: a first acquisition unit, used to obtain the query result of each coroutine in multiple coroutines; a storage unit, used to store the query result in a result set, wherein the result set stores the data query request sent by the received user account and multiple query results; a second acquisition unit, used to obtain the first counter value of the second waiting group, wherein the first counter value is used to indicate the number of multiple coroutines to be queried in the second waiting group; a first determination unit, used to determine that the query of multiple coroutines in the second waiting group is completed when the first counter value of the second waiting group meets the first preset condition; and a sending unit, used to send each query result to the corresponding user account according to the mapping relationship between the data query request and the multiple query result pieces stored in the result set.
7. A storage medium, characterized in that: The storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 5 when executed.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: The processor executes the method described in any one of claims 1 to 5 through the computer program.
Citation Information
Patent Citations
Data processing method, device and equipment and storage medium
CN111078436A
Data processing method and device, storage medium and electronic device
CN111782635A