CN110489444B - Asynchronous query method and device, computer equipment and storage medium - Google Patents

Asynchronous query method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN110489444B
CN110489444B CN201910777851.XA CN201910777851A CN110489444B CN 110489444 B CN110489444 B CN 110489444B CN 201910777851 A CN201910777851 A CN 201910777851A CN 110489444 B CN110489444 B CN 110489444B
Authority
CN
China
Prior art keywords
query
preset time
result
time
time interval
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910777851.XA
Other languages
Chinese (zh)
Other versions
CN110489444A (en
Inventor
谢滨泽
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Original Assignee
Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd filed Critical Shenzhen Qianhai Huanrong Lianyi Information Technology Service Co Ltd
Priority to CN201910777851.XA priority Critical patent/CN110489444B/en
Publication of CN110489444A publication Critical patent/CN110489444A/en
Application granted granted Critical
Publication of CN110489444B publication Critical patent/CN110489444B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention discloses an asynchronous query method, an asynchronous query device, computer equipment and a storage medium, wherein the asynchronous query method comprises the following steps: calling a data submitting interface to submit data, and then calling a query result interface to query results; if the result is not queried, a query result interface is called for querying the result at intervals of preset time; wherein, the control strategy of the preset time interval is as follows: if the current time is within a first preset time range, setting the preset time interval as a fixed value; if the current time exceeds the first preset time range, the preset time interval is set to be increased based on the increase of the times of calling the query result interface. Based on the control strategy, the query frequency can be increased in the stage of possible query of the result in the early stage, and the query frequency can be reduced in the later stage, so that the result can be queried in time, and invalid query is reduced.

Description

Asynchronous query method and device, computer equipment and storage medium
Technical Field
The present invention relates to the field of data processing, and in particular, to an asynchronous query method, an asynchronous query device, a computer device, and a storage medium.
Background
In the prior art, a plurality of platforms for providing interface services externally exist, although different technologies adopted by different platforms are different, the provided interface services have a characteristic that data are submitted asynchronously, for calling a query interface party, the query is actually uncertain when the query should be performed, if the query is triggered manually, the problem of reduced user experience is obviously caused, and the results cannot be queried in most cases; if the timing or polling inquiry is adopted, the inquiry frequency has no definite standard, and no matter how high or low the frequency is, the condition that most inquiry operations are invalid inquiry is avoided, and the server resources and the bandwidth are occupied.
Therefore, how to optimize the query method to achieve not only timely query results, but also reduce invalid queries is a technical problem that needs to be solved by those skilled in the art at present.
Disclosure of Invention
The invention aims to provide an asynchronous query method, an asynchronous query device, computer equipment and a storage medium, and the query method is optimized to realize timely query of results and reduction of invalid queries.
In a first aspect, an embodiment of the present invention provides an asynchronous query method, including the steps of:
calling a data submitting interface to submit data, and then calling a query result interface to query results;
if the result is not queried, a query result interface is called for querying the result at intervals of preset time;
wherein, the control strategy of the preset time interval is as follows: if the current time is within a first preset time range, setting the preset time interval as a fixed value; if the current time exceeds the first preset time range, the preset time interval is set to be increased based on the increase of the times of calling the query result interface.
In a second aspect, an embodiment of the present invention provides an asynchronous query device, including:
the first query module is used for calling the submitted data interface to submit data and then calling the query result interface to query results;
the second query module is used for calling a query result interface at intervals of preset time to query results if the results are not queried;
wherein, the control strategy of the preset time interval is as follows: if the current time is within a first preset time range, setting the preset time interval as a fixed value; if the current time exceeds the first preset time range, the preset time interval is set to be increased based on the increase of the times of calling the query result interface.
In a third aspect, embodiments of the present invention further provide a computer apparatus comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the asynchronous query method of the first aspect when executing the computer program.
In a fourth aspect, an embodiment of the present invention further provides a computer readable storage medium, where a computer program is stored, where the computer program is executed by a processor to implement the asynchronous query method according to the first aspect.
The embodiment of the invention provides an asynchronous query method, which comprises the steps of firstly calling a data submitting interface to submit data, and then calling a query result interface to query results; if the result is not queried, a query result interface is called for querying the result at intervals of preset time; wherein, the control strategy of the preset time interval is as follows: if the current time is within a first preset time range, setting the preset time interval as a fixed value; if the current time exceeds the first preset time range, the preset time interval is set to be increased based on the increase of the times of calling the query result interface. Based on the control strategy, the query frequency can be increased in the stage of possible query of the result in the early stage, and the query frequency can be reduced in the later stage, so that the results can be queried in time, and invalid queries can be reduced.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic flow chart of an asynchronous query method according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of an asynchronous query device according to an embodiment of the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
It is to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in the present specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes such combinations.
Referring to fig. 1, fig. 1 is a flow chart of an asynchronous query method according to an embodiment of the invention, as shown in the figure, including the steps of:
s101, calling a data submitting interface to submit data, and then calling a query result interface to query results;
after the data interface is called and submitted, so that a service provider providing an interface can process the data so as to output a result. After submitting the data, the query result interface is called immediately to perform result query (or simply query, or query operation), namely whether the query has an output result or not. There are two possible cases of the above actions, one is that the result is queried, the other is that the result is not queried, and for the case that the result is queried, the query flow is directly ended, and the query is stopped. For the case where the result is not queried, detailed description is made below.
S102, if no result is inquired, a result inquiry interface is called for carrying out result inquiry at intervals of preset time; wherein, the control strategy of the preset time interval is as follows: if the current time is within a first preset time range, setting the preset time interval as a fixed value; if the current time exceeds the first preset time range, the preset time interval is set to be increased based on the increase of the times of calling the query result interface.
Because the submitted data interface and the query result interface are not the same interface, if the submitted data interface is called to submit thousands of data, only one result can be queried each time, that is, the service provider needs a certain time for processing the data, at this time, the service provider is uncertain when the service provider can process the data, and if the service provider encounters network failure, service provider maintenance and other uncertain problems, the service provider is uncertain when the service provider can process the data. Therefore, after data is submitted, the query result interface can be called once immediately, but the great probability of querying the result is that the result cannot be obtained, and in this case, the query result interface needs to be called once at preset time intervals to query the result. That is, after submitting the data, the data can be queried once immediately, and if the result is not queried, the data is polled so as to query the result in time.
However, in the embodiment of the present invention, the timing polling is not always performed at a fixed predetermined time interval, and the embodiment of the present invention presets the control policy for the predetermined time interval. The control strategy is specifically as follows: if the current time is within a first preset time range, setting the preset time interval as a fixed value; if the current time exceeds the first preset time range, the preset time interval is set to be increased based on the increase of the times of calling the query result interface. In short, the control strategy is to fix the predetermined time interval in the early stage, gradually increase the predetermined time interval in the later stage, and increase the predetermined time interval by a larger magnitude as the number of queries increases.
Generally, after submitting data, the result is generally output within a short period of time after submitting, and in this period of time (i.e., the first predetermined time range), the query result interface may be called once every predetermined time interval to perform result query, that is, query with a fixed query frequency, if the result is not queried for this period of time, or query is continuously performed according to the predetermined time interval, then most of the subsequent time may be ineffective query, which obviously increases the resources consumed by the server and increases the cost, so that the predetermined time interval needs to be increased according to the control policy, and the query frequency needs to be reduced.
Specifically, the first predetermined time may be fixed in advance (i.e., preset to a fixed value) according to past experience or dynamically set according to a predetermined rule.
Specifically, in the embodiment of the present invention, the first predetermined time may be preset according to previous experience, and the time period from the current time to the final query result of the same type of query operation is obtained, where the time period is the time period spent by each type of query operation from the start of the query to the final result, i.e., the query time period, and the obtained time periods of the queries are averaged, so as to obtain the average time period from the start of the query (the time period when the data is submitted and the data is immediately queried once, i.e., the time period when the data is submitted is called) to the final result, and finally, according to the average time period, the first predetermined time period may be determined, for example, the first predetermined time period may be set to 1/2 or 2/3 of the average time period, for example, the first predetermined time period may be set to 25 minutes, and preferably, the first predetermined time period is set to 30 minutes later, so as to have sufficient elasticity, that the average time period is only average, and in the case that the average time period is actually the first predetermined time period is delayed to be 1/2 after the average time period, the first predetermined time period is set to 2/3 minutes, and the average time period is obtained. As for the acquisition of the first deferred time, it may be determined according to the statistical result, and the overall principle is that the probability of querying the result in the first deferred time range is higher. In the above embodiment, the first predetermined time is fixedly set, i.e., once determined, no adjustment is made. The query operations of the same type mentioned in the embodiments of the present invention may refer to that the data submitted to the submitted data interface is of the same type, or may refer to that the types of results to be output are of the same type, or may refer to that the ways of processing the data are of the same type, which may be specific according to the actual situation. In addition, it should be noted that in the above process, the duration of the final query result of the same type of query operation in a period of time is required to be obtained, but there are some cases that the latest query operation may not query the result, and such query operation may be directly eliminated, and only the data with the query duration is obtained.
In a specific application scenario, the first predetermined time may also be dynamically set, which may make the embodiment of the present invention more suitable for an application scenario that is continuously changed, and dynamically adapt to various possible situations. That is, the embodiment of the present invention dynamically sets the first predetermined time. As for the manner of dynamic setting, it may be to adjust the first predetermined time at regular intervals, for example, once every other adjustment period, which is fixed; it is also possible to adjust the first predetermined time at an indefinite time, i.e. the adjustment period is not fixed. The specific adjustment strategy is that, when each adjustment is performed, the time length of finally inquiring the result for the same type of inquiry operation in a past period of time is obtained from the current time, namely the time length of the inquiry (the time length from the beginning of the inquiry to the result), the obtained time length of the inquiry is averaged, so that the average time length from the beginning of the inquiry to the result is obtained, and finally, the first preset time can be determined according to the average time length (the determination mode can be determined according to the previous mode, for example, 1/2 or 2/3 of the average time length is added with the delay time). The first predetermined time thus determined finally takes into account the query duration in the last period of time, so that the change situation of the query duration can be adapted (it is to be noted that, when the first predetermined time is fixedly set, the duration of the final query to the result for the same type of query operation in a period of time elapsed from the "current time" is also acquired, and the step is to acquire the data from the "current time", which is not the "current time", where the fixed setting situation is the moment when the first predetermined time is preset, which is a fixed time, and the "current time" is dynamic, and the current time is the moment when the first predetermined time is required to be adjusted. It should be noted that, in the embodiment of the present invention, for the case that no result is queried, the subsequent query is continued, and the multiple query operations performed on the same result are determined to be the same query operation.
For the first preset time, a timing adjustment mode or an irregular adjustment mode is adopted, specifically, the timing adjustment mode can be selected according to different application scenes, for example, in a certain application scene, the query time length is changed regularly, the timing adjustment mode can be selected, and in another application scene, the query time length is changed irregularly, even when the query time length is increased or reduced suddenly, the irregular adjustment mode can be selected. For the timing adjustment mode, the adjustment period can be determined empirically, i.e. according to previous data; for the untimely adjustment mode, the adjustment mode can be determined according to the change rule of the past query time length, for example, in a time period, the change amplitude of the query time length is faster, the adjustment period is reduced, the adjustment frequency is accelerated, or in a time period, the change amplitude of the query time length is slower, the adjustment period can be increased, the adjustment frequency is reduced, specifically, the time length of the final query result of the query operation in the past time period can be counted, the change rule of the query time length is judged, and therefore the adjustment period is dynamically set.
In the foregoing embodiment, the "acquiring the past period of time from the present time" mentioned above may be a fixed period of time or a specified period of time. Wherein the fixed time period is a time period formed from the current time to a certain time point in the past, for example, the current time is 8 months, 6 days, 11:00, and the fixed time period is 2 days, and the statistical information is information in the time period from 8 months, 4 days, 11:00 to 8 months, 6 days, 11:00; still alternatively, the current time is 8 months, 7 days, 11:00, and the fixed time period is 2 days, then the statistical information is information of the time period from 8 months, 5 days, 11:00 to 8 months, 7 days, 11:00. The specified time period refers to a time period formed from the current time to a past specified time point, for example, the current time is 8 months, 6 days, 11:00, the specified time period is a time period formed from the current time to 8 months, 1 days, 11:00 (the specified time point is 8 months, 1 days, 11:00), then the statistical information is information in the time period from 8 months, 1 days, 11:00 to 8 months, 6 days, 11:00, or the current time is 8 months, 7 days, 11:00, then the statistical information is information in the time period from 8 months, 1 days, 11:00 to 8 months, 7 days, 11:00. The embodiment of the invention can adopt the scheme of the fixed time period and the scheme of the appointed time period, has respective benefits for different application scenes, and the scheme of the fixed time period enables the finally obtained first preset time to be more fit with the condition of the last time period, and the scheme of the appointed time period also takes the condition of the last time period into consideration and the condition of the earlier time period into consideration. According to the scheme, different schemes can be selected according to different specific application scenes, and finally, the determined first preset time is more accurate.
In the embodiment of the invention, in the first preset time range, the preset time interval is fixed, namely the preset time interval is unchanged in the whole first preset time range, and although the probability of inquiring the result is higher in the first preset time range, some time periods exist in the first preset time range, the probability of inquiring the result is lower in the first preset time range, other time periods exist at the same time, the probability of inquiring the result in the time periods is higher, other time periods exist at the same time, and the probability of inquiring the result in the time periods is medium. Therefore, in a preferred case of the embodiment of the present invention, the first predetermined time is processed in a segmented manner, that is, the first predetermined time is divided into a plurality of sub-time periods in advance, each sub-time period has a fixed predetermined time interval, and the setting manner is closer to the actual application scenario, so that not only can the result be queried in time, but also some invalid queries can be avoided. This arrangement is important for practical applications, because if all query operations are performed at a higher frequency, then if the query operations are performed in a certain period, the query operations are performed in a concentrated manner, which obviously causes a sudden increase in server pressure, so that for a first predetermined time, the embodiment of the present invention performs a segmentation process on the first predetermined time, and sets a fixed predetermined time interval for each sub-period, so that the pre-query pressure is greatly reduced, and unnecessary query operations are reduced.
As for the division of the first predetermined time, the division may be performed equally or unequally. If the dividing is performed, the dividing number can be determined according to the length of the first preset time, so that the length of the sub-time period is more reasonable and is not too long or too short. If unequal division is performed, the first predetermined time period may be divided according to the probability of occurrence of the query result.
The preferred scheme of the embodiment of the invention is to divide the first preset time in an unequal manner. Since the time to query the results does not change regularly with time, it is preferable to make the division into halves. Specifically, the distribution of the time points at which the results are found by the conventional type of query operation is counted within the first predetermined time range, for example, 10 times are found concentrated at 0 to 5 minutes, 32 times are found concentrated at 5 to 8 minutes, 21 times are found concentrated at 8 to 12 minutes, 10 times are found concentrated at 12 to 18 minutes, and 38 times are found concentrated at 18 to 30 minutes in the conventional type of query operation. And then dividing the first preset time in an unequal manner according to the distribution to obtain a section with high occurrence probability and a section with low occurrence probability, wherein the sections form sub-time periods. In this way, a lower predetermined time interval may be set for the interval with high occurrence probability, a higher predetermined time interval may be set for the interval with low occurrence probability, and the obtained interval may also include a plurality of intervals with high occurrence probability, or a plurality of intervals with low occurrence probability.
For the determination of the second predetermined time, the aforementioned counted average duration may be taken as the second predetermined time, and the second delay time may be added at the same time, that is, the average duration plus the second delay time is taken as the second predetermined time, so that the result may be queried with a high probability in the second predetermined time range. And if the second preset time is exceeded, the preset time interval can be rapidly increased, and the query frequency can be reduced. The first delay time and the second delay time may be set to be the same or different, for example, the second delay time may be set to be twice the first delay time. Assuming that the average duration is 50 minutes and the first delay time is 5 minutes, the first predetermined time may be 50×1/2+5=30 minutes and the second predetermined time may be 50+5×2=60 minutes.
If the current time exceeds the first predetermined time range, the predetermined time interval will increase with the number of times the query result interface is invoked, that is, the longer the number of invocations, the longer the predetermined time, and the longer the interval of invocations. Thus, when no query result is found within a period of time, the regular polling is not needed according to the prior interval, but the query is performed at an appropriately increased interval, so that most ineffective query actions can be avoided.
Specifically, the setting is based on an increase in the number of times the query result interface is invoked, and the increasing the predetermined time interval includes:
s201, if the current time is in a range from a first preset time to a second preset time, setting that the increment amplitude of the preset time interval is the same each time;
the purpose of the above steps is to specifically define the case in which the increase in the predetermined time interval is the same in the first predetermined time to the second predetermined time range. For example, when the current time exceeds the first predetermined time, the predetermined time interval is set to be n, and after n of the predetermined time interval is elapsed, the next time the query result interface is called to query the result and the result is not yet queried, at this time, the predetermined time interval is updated to be n+m, where m is the increasing amplitude of the predetermined time interval. Then after n+m predetermined time interval has elapsed, the next time the query result interface is invoked to query the results and no results are yet queried, at which time the predetermined time interval is updated to n+2m, where m is the increasing amplitude of the predetermined time interval. Then after n+2m of the predetermined time interval has elapsed, the next time the query result interface is called to query the result, and the result is not yet queried, at this time, the predetermined time interval is updated to n+3m, where m is the increasing amplitude of the predetermined time interval. So on, in the range from the first preset time to the second preset time, each time the query result interface is called, the preset time interval is updated at the same time, and the next time the query result interface is called according to the updated preset time interval. Finally, until the current time exceeds the second predetermined time range.
In a specific application scenario, the initial value of the predetermined time interval is less than 10s. That is, the time interval between adjacent calls to the query result interface is less than 10s. In other words, the predetermined time interval is small at the initial stage of the query, so that it can be ensured that the result can be queried in time if the result is output within a period of time after the data is submitted.
In a specific application scenario, m is equal to n, that is, the increasing amplitude of each predetermined time interval is equal to the initial predetermined time interval, for example, the initial predetermined time interval is 5s, then the next predetermined time interval is 5+5=10s, the next predetermined time interval is 10+5=15s, and so on, to obtain the predetermined time interval after each update.
In another specific application scenario, m is not equal to n, that is, the increasing amplitude of each predetermined time interval is not equal to the initial predetermined time interval, for example, the initial predetermined time interval is 5s, the next predetermined time interval is 5+3=8s, the next predetermined time interval is 8+3=11s, and so on, to obtain the predetermined time interval after each update.
In the step, the increasing amplitude of the preset time interval is fixed, and a gradient change condition is formed, so that the timely inquiry of the result can be ensured, too many ineffective inquiry operations are avoided, and the inquiry efficiency is improved. The step is based on the fact that the probability of outputting the result is high within the range from the first predetermined time to the second predetermined time, so that the predetermined time interval is not increased substantially, but is increased step by step, so that the time for querying the result is prevented from being much later than the time for outputting the result.
The magnitude of the increase in the predetermined time interval determines the size of the next predetermined time interval, so the magnitude of the increase also determines the query interval in the first predetermined time to second predetermined time range. The specific value of the increase is particularly important since it is a fixed setting. The determination of the increasing amplitude m of the predetermined time interval may be based on the length of the first predetermined time to the second predetermined time, and if the length of the first predetermined time to the second predetermined time is long, m may be set large, and if the length of the first predetermined time to the second predetermined time is small, m may be set small, i.e., the general principle is that the number of times of the query performed each time from the first predetermined time to the second predetermined time is kept at a reasonable level, because the second predetermined time is determined based on the first predetermined time (the aforementioned second probability is determined by the first probability), so that the second predetermined time may be long, and does not represent that the probability that the result can be queried over such a long time range will be evenly distributed. In order to save server resources and reduce invalid queries, the embodiment of the invention controls the number of queries performed between the first preset time and the second preset time to be kept within a preset range.
S202, if the current time exceeds the second preset time range, setting the preset time interval to be doubled by one preset time interval each time.
The purpose of the above steps is to define in particular the case where the current time exceeds the second predetermined time range, i.e. in the case described above the increasing amplitude of the predetermined time interval is increasing and the increasing amplitude increases exponentially with increasing number of calls. For example, when the current time exceeds the second predetermined time, the predetermined time interval is set to be n, and after n of the predetermined time interval is elapsed, the next time the query result interface is called to query the result and the result is not yet queried, at this time, the predetermined time interval is updated to n×2=2n, where n is the increasing amplitude of the predetermined time interval. Then after 2n of the predetermined time interval has elapsed, the next call to the query result interface is performed to query the result, and the result is not yet queried, at this time, the predetermined time interval is updated to 2n×2=4n, where 2n is the increasing amplitude of the predetermined time interval. Then after a predetermined time interval of 4n has elapsed, the next call to the query results interface is performed to query the results and no results are yet queried, and at this time, the predetermined time interval is updated to 4n×2=8n, where 4n is the increasing amplitude of the predetermined time interval. So on the same time, in the case that the current time exceeds the second preset time, each time the query result interface is called, the preset time interval is updated at the same time, and the next time the query result interface is called according to the updated preset time interval. Finally, until the result is queried.
As can be seen from the above, the increase in the predetermined time interval is multiplied by n each time, the first time, the second time, the third time, the 4n, and the fourth time, the 8 n. With the increase of the calling times, the increase of the following preset time interval is multiplied, so the time interval of the following calling of the query result interface is huge relative to the initial time interval, the calling frequency is greatly reduced after the current time exceeds the second preset time, the calling interval is greatly increased, the calling times in unit time are greatly reduced, and the invalid query operation is greatly reduced. This step is based on the fact that the time at which the result is output is indefinitely too high after the current time exceeds the second predetermined time range, so that the predetermined time interval needs to be increased substantially instead of being increased step by step to waste the excessive query operations.
In a specific application scenario, the initial predetermined time interval is 60s, then the next predetermined time interval is 60×2=120s, the next predetermined time interval is 120×2=240 s, and so on, to obtain the predetermined time interval after each update.
In the embodiment of the invention, when the query result interface is called to query the result, the control strategy at a preset time interval is optimized, the query result interface is called according to a fixed calling frequency in the early stage, the calling frequency is reduced slowly in the middle stage, and the calling frequency is reduced greatly in the later stage, so that the control strategy is more in line with the real query scene according to the change of time, the result can be queried in time, the occupation of server resources and bandwidth by frequent calling can be avoided, and the query efficiency is improved.
Further, before invoking the query result interface to perform the result query, the method comprises:
judging whether the equipment required to be used when the query result interface is called for carrying out result query is online or not, if so, calling the query result interface for carrying out result query, and if not, ending the result query.
When some interface providers provide interface services, the corresponding equipment is needed to output results, for example, the current set temperature of the intelligent air conditioner needs to be queried nowadays, if the intelligent air conditioner is not online, the corresponding set temperature obviously cannot be queried, so that the equipment can be judged to be online firstly, if the equipment is online, the query result interface is called for result query, and if the equipment is not online, the result query is ended, so that invalid query can be avoided, and because the equipment is not online and cannot output any result, the result query can be ended at the moment.
Further, the ending the result query if not online includes:
detecting the time length of the equipment which is not on-line, and ending the result query if the time length of the equipment which is not on-line exceeds a time threshold.
In some cases, the device is only temporarily offline, that is, is not online for the current period of time, after a period of time, the device may be online, in other words, the longer the period of time that the device is offline, the lower the probability of online for the subsequent period of time, so in the embodiment of the present invention, it is preferable to end the result query if the period of time that the device is detected to be offline exceeds the time threshold. The time threshold may be between 5 minutes and 15 minutes, for example 10 minutes, i.e. the device is not on-line for more than 10 minutes, ending the result query.
Further, if the result is not queried, the request data required by the result query is temporarily stored in a cache for the next result query. Because the required request data is basically the same each time when the result inquiry is carried out, the request data used for carrying out the result inquiry for the first time can be temporarily stored in a cache, namely a redis cache when the result inquiry is carried out for the first time and the result is not inquired, and the request data only needs to be directly read from the cache when the result inquiry is carried out for the next time, so that the reading and writing speed can be improved, and the inquiry efficiency is further improved.
Even for the case of submitting multiple data, as the required request data is smaller during inquiry, only one or two fields are needed, various request data can still be temporarily stored in the cache for different results of multiple inquiry, and the excessive data in the cache is avoided.
Further, if the result is queried, deleting the corresponding request data in the cache. Specifically, in any query operation, if a result is queried, the corresponding request data in the cache can be directly deleted, and after the result is queried, the query flow is ended, and the corresponding request data is not needed to be used any more, so that the request data can be directly deleted.
In some cases, the inquiry can be performed only after the login is completed, so when the request of the login of the user is detected, the inquiry is awakened once, namely, the result inquiry interface is called for inquiry, and after the login is successful, the inquiry can be performed according to the mode of the embodiment.
Referring to fig. 2, fig. 2 is a schematic structural diagram of an asynchronous query device according to an embodiment of the present invention;
the apparatus may include:
the first query module 201 is configured to invoke a query result interface to query results after invoking the submitted data interface to submit data;
the second query module 202 is configured to invoke a query result interface to query results at intervals of a predetermined time if no results are queried;
wherein, the control strategy of the preset time interval is as follows: if the current time is within a first preset time range, setting the preset time interval as a fixed value; if the current time exceeds the first preset time range, the preset time interval is set to be increased based on the increase of the times of calling the query result interface.
Further, the apparatus may further include:
and the judging module is used for judging whether the equipment required to be used when the query result interface is called for carrying out result query is online, if so, the query result interface is called for carrying out result query, and if not, the result query is ended.
Further, the ending the result query if not online includes:
detecting the time length of the equipment which is not on-line, and ending the result query if the time length of the equipment which is not on-line exceeds a time threshold.
Further, the initial value of the predetermined time is less than 10s.
Further, the setting is based on an increase in the number of times the query result interface is invoked, and increasing the predetermined time interval includes:
if the current time is in the range from the first preset time to the second preset time, setting the increment amplitude of the preset time interval to be the same each time;
if the current time exceeds the second preset time range, setting the preset time interval to be doubled by one preset time interval each time.
Further, if the result is not queried, the request data required by the result query is temporarily stored in a cache for the next result query.
Further, if the result is queried, deleting the corresponding request data in the cache.
Since the embodiments of the apparatus portion and the embodiments of the method portion correspond to each other, the embodiments of the apparatus portion are referred to the description of the embodiments of the method portion, and are not repeated herein.
The present invention also provides a computer-readable storage medium having stored thereon a computer program which, when executed, implements the method provided by the above embodiments. The storage medium may include: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The invention also provides a computer device, which can comprise a memory and a processor, wherein the memory stores a computer program, and the processor can realize the method provided by the embodiment when calling the computer program in the memory. Of course the computer device may also include various network interfaces, power supplies, and the like.
In the description, each embodiment is described in a progressive manner, and each embodiment is mainly described by the differences from other embodiments, so that the same similar parts among the embodiments are mutually referred. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the invention can be made without departing from the principles of the invention and these modifications and adaptations are intended to be within the scope of the invention as defined in the following claims.
It should also be noted that in this specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.

Claims (9)

1. An asynchronous query method, comprising the steps of:
calling a data submitting interface to submit data, and then calling a query result interface to query results;
if the result is not queried, a query result interface is called for querying the result at intervals of preset time;
wherein, the control strategy of the preset time interval is as follows: if the current time is within a first preset time range, setting the preset time interval as a fixed value; if the current time exceeds a first preset time range, setting an increment based on the number of times of calling the query result interface, and incrementing the preset time interval;
the first preset time is adjusted once every other adjustment period, the adjustment strategy is that when each adjustment is performed, the query duration of the final query result of the same type of query operation in a past period is obtained from the current time, the obtained query duration is averaged, the average duration from the beginning of the query to the query result is obtained, and finally the first preset time is determined according to the average duration;
dividing the first preset time into a plurality of sub-time periods in advance, wherein each sub-time period has a fixed preset time interval;
the setting is based on an increase in the number of times the query result interface is invoked, and increasing the predetermined time interval includes:
if the current time is in the range from the first preset time to the second preset time, setting the increment amplitude of the preset time interval to be the same each time; and the increasing amplitude is associated with the interval from the first preset time to the second preset time, and the longer the interval is, the larger the increasing amplitude is;
if the current time exceeds the second preset time range, setting the preset time interval to be doubled by one preset time interval each time.
2. The asynchronous query method of claim 1, wherein prior to invoking the query result interface to perform the result query, comprising:
judging whether the equipment required to be used when the query result interface is called for carrying out result query is online or not, if so, calling the query result interface for carrying out result query, and if not, ending the result query.
3. The asynchronous query method of claim 2, wherein ending the result query if not online comprises:
detecting the time length of the equipment which is not on-line, and ending the result query if the time length of the equipment which is not on-line exceeds a time threshold.
4. The asynchronous query method of claim 1, wherein the initial value of the predetermined time interval is less than 10s.
5. The method of claim 1, wherein if no results are queried, the requested data required for the results are buffered in a buffer for use in the next results query.
6. The method of claim 5, wherein if a result is queried, the corresponding request data in the cache is deleted.
7. An asynchronous query device, comprising:
the first query module is used for calling the submitted data interface to submit data and then calling the query result interface to query results;
the second query module is used for calling a query result interface at intervals of preset time to query results if the results are not queried;
wherein, the control strategy of the preset time interval is as follows: if the current time is within a first preset time range, setting the preset time interval as a fixed value; if the current time exceeds a first preset time range, setting an increment based on the number of times of calling the query result interface, and incrementing the preset time interval;
the first preset time is adjusted once every other adjustment period, the adjustment strategy is that when each adjustment is performed, the query duration of the final query result of the same type of query operation in a past period is obtained from the current time, the obtained query duration is averaged, the average duration from the beginning of the query to the query result is obtained, and finally the first preset time is determined according to the average duration;
dividing the first preset time into a plurality of sub-time periods in advance, wherein each sub-time period has a fixed preset time interval;
the setting is based on an increase in the number of times the query result interface is invoked, and increasing the predetermined time interval includes:
if the current time is in the range from the first preset time to the second preset time, setting the increment amplitude of the preset time interval to be the same each time; and the increasing amplitude is associated with the interval from the first preset time to the second preset time, and the longer the interval is, the larger the increasing amplitude is;
if the current time exceeds the second preset time range, setting the preset time interval to be doubled by one preset time interval each time.
8. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the asynchronous query method of any of claims 1 to 6 when the computer program is executed by the processor.
9. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon a computer program which, when executed by a processor, implements the asynchronous query method according to any of claims 1 to 6.
CN201910777851.XA 2019-08-22 2019-08-22 Asynchronous query method and device, computer equipment and storage medium Active CN110489444B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910777851.XA CN110489444B (en) 2019-08-22 2019-08-22 Asynchronous query method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910777851.XA CN110489444B (en) 2019-08-22 2019-08-22 Asynchronous query method and device, computer equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110489444A CN110489444A (en) 2019-11-22
CN110489444B true CN110489444B (en) 2023-06-13

Family

ID=68552944

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910777851.XA Active CN110489444B (en) 2019-08-22 2019-08-22 Asynchronous query method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110489444B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115314530B (en) * 2022-06-30 2024-01-05 中国第一汽车股份有限公司 Information processing method and device and vehicle

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105306618A (en) * 2015-09-25 2016-02-03 互联网域名系统北京市工程研究中心有限公司 Method and device for automatically defending DNS from analyzing and requesting DDoS attacks

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107515571B (en) * 2017-07-12 2020-05-05 广东美的制冷设备有限公司 Monitoring data acquisition method, device and system
CN110019261B (en) * 2017-09-30 2021-11-23 北京国双科技有限公司 Data query method and device
CN107943828B (en) * 2017-10-18 2020-06-30 深圳市牛鼎丰科技有限公司 Service state query method and device, computer equipment and storage medium
CN109727010A (en) * 2018-05-14 2019-05-07 网联清算有限公司 Service inquiry method, apparatus, computer equipment and storage medium

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105306618A (en) * 2015-09-25 2016-02-03 互联网域名系统北京市工程研究中心有限公司 Method and device for automatically defending DNS from analyzing and requesting DDoS attacks

Also Published As

Publication number Publication date
CN110489444A (en) 2019-11-22

Similar Documents

Publication Publication Date Title
CN106888135B (en) Task state query method and device
CN105656810B (en) Method and device for updating application program
CN111858055B (en) Task processing method, server and storage medium
CN110489444B (en) Asynchronous query method and device, computer equipment and storage medium
CN111291252B (en) Method and device for adjusting query rate per second, electronic equipment and storage medium
CN107329832B (en) Data receiving method and device
CN115480713A (en) Method, device and medium for determining cold and hot data
CN111191134B (en) Intelligent pushing method and terminal
CN108134817A (en) A kind of method and device of adjust automatically caching duration
CN113760974A (en) Dynamic caching method, device and system
CN115002216B (en) Downloading method, downloading device, terminal equipment and readable storage medium
CN112073455B (en) Data processing method, device, equipment and storage medium
CN111107019A (en) Data transmission method, device, equipment and computer readable storage medium
CN111984681A (en) Post-credit investigation method and device
CN114518932A (en) Method, system, computing device and storage medium for scheduling function service
CN116166451B (en) Dynamic adjustment method, system and device for topic number and storage medium
CN111782323B (en) Bullet screen obtaining method, computing equipment and computer storage medium
CN111083063B (en) Method and device for dynamically adjusting down-pressure
CN110727389B (en) File cleaning method and system
CN105678514B (en) Data processing method and device and electronic equipment
CN116016654A (en) Message pushing method, device, equipment and medium
CN116827864A (en) Request quantity control method and terminal
CN113467921B (en) Task management method and device and electronic equipment
CN110990134B (en) Intelligent task scheduling method and device, computer equipment and storage medium
CN114938393B (en) Computer room data interaction method and system and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant