Method, device, computer equipment and storage medium for adjusting interface timeout
By dynamically adjusting the timeout of the interface, the problem that the unified timeout time setting cannot meet special business scenarios is solved, and the interface service optimization and rapid resource release are achieved.
Patent Information
- Application Number
- CN202111432549.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-29
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2041-11-29
AI Technical Summary
In the prior art, the unified interface timeout time setting cannot meet the needs of special business scenarios. For example, when uploading or downloading large files, the unified extended timeout time cannot achieve the effect of timeout circuit breaking, resulting in resource occupation and service blockage.
By receiving access requests, the timeout time of all interfaces is obtained, the access request is sent to the server, and the time-consuming data is recorded. The target interface is determined, its average request time spent in the preset time period is calculated, and the timeout time of the target interface is adjusted according to the second time and average time spent of the initial interface group.
It realizes dynamic adjustment of interface timeout time, avoids the problem of long-term occupation of request links caused by unified timeout time setting, quickly releases resources, and optimizes interface services.
Smart Images

Figure CN114048059B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a method, device, computer equipment and storage medium for adjusting the timeout period of an interface. Background Art
[0002] With the development of Internet technology and the improvement of Internet service capabilities, various system applications have flourished, and there are various data interactions between many systems. The amount of data access faced by many application services has also increased dramatically. Application services usually access data through interfaces, and the entire microservice system usually has a unified interface timeout setting. However, this unified default timeout setting cannot meet the requirements of some special business scenarios, such as uploading or downloading large files. If the timeout is uniformly extended, the timeout fuse effect cannot be achieved, which will cause resource occupation and service congestion. Summary of the invention
[0003] The purpose of the embodiments of the present application is to propose a method, device, computer equipment and storage medium for adjusting the timeout period of an interface, so as to solve the technical problem of unified interface timeout period setting in the related art.
[0004] In order to solve the above technical problems, the embodiment of the present application provides a method for adjusting the timeout period of an interface, which adopts the following technical solution:
[0005] Receive an access request, obtain all interfaces corresponding to the access request, and read first timeout times of all the interfaces;
[0006] According to the first timeout period, the access request is sent to the server through the interface, and the time-consuming data corresponding to the interface is pushed to the data storage end for storage and recording;
[0007] Determine a target interface, and obtain time consumption data of the target interface within a preset time period as target time consumption data;
[0008] Based on the target time consumption data, calculate the average request time consumption of the target interface in the preset time period;
[0009] Determine an initial interface group where the target interface is located, and send the average request time to the initial interface group;
[0010] The first timeout time of the target interface is adjusted according to the second timeout time of the initial interface group and the average request duration.
[0011] Furthermore, the step of determining the target interface and obtaining the time consumption data of the target interface within a preset time period as the target time consumption data includes:
[0012] According to the preset timing mechanism, when the set time is reached, the scheduled task corresponding to the set time is obtained as the target scheduled task;
[0013] Determining a target interface according to execution parameters of the target scheduled task;
[0014] Based on the target interface, the time consumption data within the preset time period is acquired from the data storage end as the target time consumption data.
[0015] Furthermore, the step of determining the initial interface group where the target interface is located and sending the average request time to the initial interface group includes:
[0016] Acquire interface parameters of the target interface, and obtain an initial interface group where the target interface is located according to the interface parameters;
[0017] The interface parameters and the average request time are encapsulated into a message queue, and the average request time is sent to the corresponding initial interface group through the message queue.
[0018] Further, the step of adjusting the first timeout time of the target interface according to the second timeout time of the initial interface group and the average request time comprises:
[0019] Compare the second timeout time with the average request duration;
[0020] When the average request time is not within the second timeout range, the corresponding target interface group is queried according to the average request time;
[0021] The target interface is adjusted from the initial interface group to the target interface group.
[0022] Further, after the step of when the average request duration is not within the second timeout range, the method further includes:
[0023] Determine whether an abnormality occurs in the associated party corresponding to the target scheduled task;
[0024] When an abnormality occurs in the associated party, it is determined whether to adjust the target interface to the target interface group according to the priority of the target scheduled task.
[0025] Furthermore, after the step of sending the access request to the server through the interface, the method further includes:
[0026] Access content corresponding to the access request is obtained through the call link of the server.
[0027] Furthermore, after the step of receiving the access request and acquiring all interfaces corresponding to the access request, the method further includes:
[0028] Determine whether to perform a queuing operation or a releasing operation on the access request according to the current current limiting status of all the interfaces, and when releasing the access request, store the interface response time of the access request as time-consuming data in a response time queue.
[0029] In order to solve the above technical problems, the embodiment of the present application further provides a device for adjusting the timeout period of an interface, which adopts the following technical solution:
[0030] A first acquisition module, configured to receive an access request, acquire all interfaces corresponding to the access request, and read a first timeout period of all the interfaces;
[0031] A first sending module, configured to send the access request to the server through the interface according to the first timeout period, and push the time-consuming data corresponding to the interface to the data storage end for storage and recording;
[0032] A second acquisition module is used to determine a target interface and acquire time consumption data of the target interface within a preset time period as target time consumption data;
[0033] A calculation module, used for calculating the average request time consumption of the target interface in the preset time period based on the target time consumption data;
[0034] A second sending module, used for determining an initial interface group where the target interface is located, and sending the average request time to the initial interface group;
[0035] An adjustment module is used to adjust the first timeout time of the target interface according to the second timeout time of the initial interface group and the average request time.
[0036] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0037] The computer device comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the above-mentioned method for adjusting the timeout period of the interface when executing the computer-readable instructions.
[0038] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0039] The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the method for adjusting the timeout period of the interface as described above are implemented.
[0040] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0041] The present application receives an access request, obtains all interfaces corresponding to the access request, and reads the first timeout period of all interfaces. According to the first timeout period, the access request is sent to the server through the interface, and the time consumption data corresponding to the interface is pushed to the data storage end for storage and record, the target interface is determined, and the time consumption data of the target interface within a preset time period is obtained as the target time consumption data. Based on the target time consumption data, the average request consumption of the target interface in the preset time period is calculated, the initial interface group where the target interface is located is determined, and the average request consumption is sent to the initial interface group, and the first timeout period of the target interface is adjusted according to the second timeout period and the average request consumption of the initial interface group; the present application calculates the average request consumption of the target interface within the preset time period, and adjusts the timeout period of the target interface according to the average request consumption, so as to realize dynamic adjustment of the interface timeout period, avoid the problem of long-term occupation of the request link caused by uniformly setting the timeout period, and can further quickly release resources and optimize interface services. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0043] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;
[0044] Figure 2 A flowchart of an embodiment of a method for adjusting the timeout period of an interface according to the present application;
[0045] Figure 3 is a structural diagram of an embodiment of a device for adjusting the timeout period of an interface according to the present application;
[0046] Figure 4 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0047] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0048] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0049] 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 accompanying drawings.
[0050] This application provides a method for adjusting the timeout period of an interface, which can be applied to Figure 1 In the system architecture 100 shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0051] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0052] Terminal devices 101, 102, 103 can be various electronic devices with display screens and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 (Moving Picture Experts Group Audio Layer IV) players, laptop computers, desktop computers, etc.
[0053] The server 105 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal devices 101 , 102 , and 103 .
[0054] It should be noted that the interface timeout adjustment method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the interface timeout adjustment device is generally set in the server / terminal device.
[0055] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0056] Continue to refer Figure 2 , shows a flowchart of an embodiment of a method for adjusting the timeout period of an interface according to the present application, comprising the following steps:
[0057] Step S201: receive an access request, obtain all interfaces corresponding to the access request, and read the first timeout period of all interfaces.
[0058] The interface is a user access interface, through which users access the service corresponding to the interface. Each service has a corresponding interface, and each interface is set with an interface timeout. If the call time of a service interface exceeds the interface timeout, the timeout fuse will be blown, and the interface call of the service will be blown to release resources and avoid service congestion.
[0059] An access request is a service request initiated by a user terminal to a server through an interface, wherein the access request may be a URL (Uniform Resource Locator) request or other request including an address for accessing a specified resource, which is not limited here.
[0060] The service accessed by the user can be determined based on the access request, and then the interface for service call can be obtained. Since the timeout of the interface is pre-configured and stored in a key-value pair, that is, the interface corresponds to the timeout one by one.
[0061] In this embodiment, the first timeout time of the interface configuration can be directly read. The first timeout time can be used as the timeout time of the user terminal. The user terminal makes an access request to the server. If a timeout occurs (i.e., the interface response time of the access request exceeds the first timeout time), the user terminal can actively disconnect the link to release the interface resources.
[0062] It should be understood that a service may correspond to multiple interfaces. The first timeout period of the interface can be set according to the business, access frequency and interface response time. For example, for big data query services, the query time of such services is relatively long, and there are usually some reports and computing scenarios. Therefore, the first timeout period can be set to be longer than that of general business services, such as 3s. For homepage messages, banners, and information-related services, the timeout period of such services is relatively short. If the access request is not blown for a long time, it will lead to resource occupation. Therefore, the first timeout period can be set to be relatively short, such as 1s.
[0063] It should be noted that in this embodiment, the interface is placed in the interface group, and its timeout fuse time is the timeout time of the interface group. Fusing is essentially an overload protection mechanism. If a target service is slow to call or has a large number of timeouts, the call of the target service will be fused, that is, for subsequent call requests for the target service, the call failure will be directly returned to quickly release resources. If the target service situation improves, the call will be resumed.
[0064] Step S202: according to the first timeout period, an access request is sent to the server through the interface, and time-consuming data corresponding to the interface is pushed to the data storage end for storage and recording.
[0065] In this embodiment, the access request is sent to the server through the interface, and the server obtains the corresponding service through a third party and returns it to the user terminal. The access request is disconnected or the access request is successful according to the interface response time and the first timeout time. Regardless of whether the access request is disconnected or successful, the interface time consumption data corresponding to the access request will be asynchronously pushed to the data storage end, and the data storage end will record the actual time consumption of each interface.
[0066] Among them, the data storage end can use ES (ElasticSearch, data analysis engine) to store interface time-consuming data, separate and index the interface time-consuming data to obtain the time-consuming data to be queried, and query the time-consuming data to be queried according to the interface time-consuming data query request to obtain the target time-consuming data.
[0067] Asynchronous push refers to a reporting operation that is performed without affecting the access request and the main process. The reported information includes but is not limited to the interface request path, time-consuming data (i.e., the interface response time of the access request), the requesting user terminal IP and other information.
[0068] Step S203, determining a target interface, and obtaining time consumption data of the target interface within a preset time period as target time consumption data.
[0069] Specifically, according to the preset timing mechanism, when the set time is reached, the scheduled task corresponding to the set time is obtained as the target scheduled task, the target interface is determined according to the execution parameters of the target scheduled task, and the time-consuming data within the preset time period is obtained from the data storage end based on the target interface as the target time-consuming data.
[0070] In this embodiment, a scheduled task is pre-set, and the execution time of the scheduled task can be obtained according to the execution parameters of the scheduled task, wherein the execution parameters include but are not limited to task content, execution time, execution interface, etc. The timing mechanism includes a timer, and the timer is used to set the execution time of the scheduled task. When the set time of the timer (the execution time of the scheduled task set by the timer) is reached, the scheduled task corresponding to the execution time is obtained as the target scheduled task.
[0071] When configuring a scheduled task, the calling interface of the scheduled task can be determined according to the specific business of the scheduled task. The interface parameters of the interface to be called can be configured into the execution parameters of the scheduled task. After obtaining the target scheduled task, all target interfaces required to execute the target scheduled task can be obtained according to the execution parameters of the target scheduled task.
[0072] The preset time period may be the time period between the current scheduled task execution time and the next scheduled task execution time. For the first scheduled task, the preset time period may be a period of time before the first scheduled task starts, for example, 1 hour before the first scheduled task starts.
[0073] Before the scheduled task is executed or during the execution interval, there will be other access requests to call the interface. The interface time consumption data before the scheduled task is executed or during the execution interval will be sent to the data storage end for storage and recording. The time consumption data within the preset time period can be obtained from the data storage end according to the target interface.
[0074] This embodiment can improve the efficiency of obtaining time-consuming data.
[0075] It should be emphasized that in order to further ensure the privacy and security of the time-consuming data, the above time-consuming data can also be stored in a node of a blockchain.
[0076] The blockchain referred to in this application is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0077] Step S204, based on the target time consumption data, calculate the average request time consumption of the target interface in a preset time period.
[0078] Specifically, the time consumption data of the target interface within the preset time period is queried from the data storage end according to the target interface, and the average request time consumption of each target interface is calculated. For example, the preset time period is 1h, and the time consumption data of a certain target interface within the preset time period are 2.0s, 2.5s, 2.3s and 2.6s respectively, then the average time consumption data of the target interface = (2.0+2.5+2.3+2.6) / 4 = 2.35s.
[0079] Step S205, determining the initial interface group where the target interface is located, and sending the average request time to the initial interface group.
[0080] Specifically, the interface parameters of the target interface are obtained, the initial interface group where the target interface is located is obtained according to the interface parameters, the interface parameters and the average request time are encapsulated into a message queue, and the average request time is sent to the corresponding initial interface group through the message queue.
[0081] In this embodiment, the initial interface group where the target interface is located can be obtained according to the interface parameters of the target interface, wherein the interface parameters include interface identifiers, interface group parameters, etc. An interface group is a set of interfaces divided according to preset rules, and the preset rules include but are not limited to according to business, access frequency, interface response time, etc.
[0082] For example, a scheduled task corresponds to an application service, and the interface of an application service may be in different interface groups. For example, the target scheduled task is a big data query task, and the interfaces of the big data report are A, B, and C. The average request time of interface A is 4s, the average request time of interface B is 3s, and the average request time of interface C is 1s. In this scheduled task, there are interface groups: 1s interface group (I1), 3s interface group (I3) and 4s interface group (I4), that is, the interfaces are divided according to the interface response time.
[0083] In this embodiment, the interface parameters and the average request time are encapsulated into a message queue (MQ), and the average request time is sent to the corresponding initial interface group in the form of the message queue to notify the initial interface group where the target interface is located.
[0084] Among them, the message queue is a "first-in, first-out" data structure in the basic data structure, which means putting the data (message) to be transmitted in the queue and using the queue mechanism to realize message transmission - the producer (data storage end) generates a message and puts the message into the queue, which is then processed by the consumer (interface group). The consumer (interface group) can pull messages from the specified queue, or subscribe to the corresponding queue, and the MQ server will push messages to it.
[0085] This embodiment sends the average request time in the form of a message queue, which can improve the efficiency and accuracy of message sending.
[0086] Step S206, adjusting the first timeout time of the target interface according to the second timeout time and the average request duration of the initial interface group.
[0087] In this embodiment, the second timeout period is the interface group timeout period. The interface group timeout period can be adjusted within a period of time, or it can be pre-set when the interface allocation definition is initialized. It should be understood that the interface group timeout period will not be greater than the preset timeout period of the application service. For example, the interface group timeout period is 3 seconds, and the average time required to respond to a service access request for the interface list in the interface group is 2-3 seconds.
[0088] The first timeout period of the target interface is adjusted, specifically, the target interface is adjusted from the initial interface group to the target interface group.
[0089] The present application calculates the average request duration of the target interface within a preset time period, and adjusts the timeout period of the target interface according to the average request duration. This can achieve dynamic adjustment of the interface timeout period, avoid the problem of long-term occupation of the request link due to unified timeout setting, and further quickly release resources and optimize interface services.
[0090] In some optional implementations of this embodiment, the step of adjusting the first timeout time of the target interface according to the second timeout time of the initial interface group and the average request time includes:
[0091] The second timeout time and the average request time are compared. When the average request time is not within the second timeout time range, the corresponding target interface group is queried according to the average request time, and the target interface is adjusted from the initial interface group to the target interface group.
[0092] In this embodiment, the second timeout time of the initial interface group where the target interface is located is compared with the average request time of the target interface within a preset time period. When the average request time is not within the second timeout time range of the initial interface group, and it is found that the average request time of the target interface falls into another interface group, then the interface group is the target interface group, and the target interface is adjusted from the initial interface group to the target interface group.
[0093] For example, the initial interface group where interface A is located is I4, and the timeout range of interface group I4 is 3s<T I4 ≤4s, the average request duration in the preset time period is 2.8s, which falls within the timeout range of interface group I3 (2s<T I3 ≤3s), at this time, adjust interface A from interface group I4 to interface group I3, and the timeout fuse time of interface A is the timeout time corresponding to interface group I3, and delete the interface A path stored in the original interface group I4. For another example, the initial interface group where interface B is located is I2 (the second timeout time range: 1s<T I3 ≤2s), the average request duration in the preset time period is 2.8s, which falls within the timeout range of interface group I3 (2s<T I3 ≤3s), at this time, adjust the B interface from interface group I2 to interface group I3, the B interface timeout fuse time is the timeout time corresponding to interface group I3, and delete the B interface path stored in the original interface group I2.
[0094] It should be noted that the interface timeout period can be adjusted upward manually and downward automatically.
[0095] This embodiment adjusts the first timeout time of the target interface according to the comparison result between the second timeout time of the initial interface group where the target interface is located and the average request time consumption in the preset time period of the target interface, so as to realize dynamic adjustment of the interface timeout time and optimize the interface service.
[0096] In some optional implementations, after the step of when the average request duration is not within the second timeout range, the method further includes:
[0097] Determine whether an associated party corresponding to the target scheduled task has an abnormality. When an associated party has an abnormality, determine whether to adjust the target interface to the target interface group according to the priority of the target scheduled task.
[0098] Among them, the associated party is a third-party platform that the server obtains the service based on the access request or scheduled task. After the average request time of the target interface falls into the timeout range of other interface groups, check whether the associated party has an abnormality. If the timeout time is extended due to the abnormality of the associated party, determine whether to adjust the timeout time of the target interface according to the priority of the target scheduled task. If the priority is within the preset level, it means that the target scheduled task business needs to be kept normal and cannot be disconnected, then the target interface will be adjusted to the target interface group. For example, assuming that the average request time of interface A starts with 2.8 seconds, and the average request time of the scheduled task in the preset time period becomes 3.5 seconds. After confirmation, it is found that the associated party service has an abnormality, but the business is the core link and cannot be disconnected. The timeout time of interface A is manually adjusted to 4s, that is, interface A is adjusted from I3 to I4.
[0099] It should be understood that the interface timeout adjustment due to the abnormality of the associated party is short-term. After the associated party returns to normal, the interface timeout callback can be completed, that is, the scheduled task calculates the average request time of interface A within the preset time period and returns to the original 2.8 seconds. Then the timeout of this interface is readjusted to 3s to prevent the subsequent large-scale requests of 3s from occupying resources and causing application request blocking.
[0100] In addition, if the priority of the target scheduled task is not within the preset level, the interface adjustment may not be performed, and the corresponding target scheduled task may be executed after the average request time of the interface returns to normal.
[0101] This embodiment determines whether to adjust the timeout period of the target interface according to the priority of the target scheduled task, thereby avoiding interruption of important services and ensuring normal services.
[0102] In some optional implementations, after the step of sending the access request to the server through the interface, the method further includes:
[0103] Obtain the access content corresponding to the access request through the call link on the server side.
[0104] After the access request is successfully sent to the server, the access content corresponding to the access request is obtained through the call link of the server and returned to the user terminal, so that the user obtains the corresponding requested service.
[0105] In some optional implementations of this embodiment, after the step of receiving the access request and acquiring all interfaces corresponding to the access request, the following step is further included:
[0106] The access request is queued or released according to the current flow limiting status of all interfaces. When releasing the access request, the interface response time of the access request is stored as time-consuming data in the response time queue.
[0107] Specifically, for each access request, check whether all interfaces corresponding to the access request need current limiting. If current limiting is required, check whether the access request is in the ready queue. If it is in the ready queue, release the access request. When the server returns a response, store the interface response time of this access request in the response time queue, and end this access. If it is not in the ready queue, judge the current current limiting status of all interfaces. If the status is "current limiting is on", put 1 / 2 of the interfaces into the ready queue and the remaining 1 / 2 interfaces into the waiting queue. If the status is "current limiting is already on", put all interfaces into the waiting queue, and wait for the interfaces in the waiting queue to resume release, and then release their corresponding access requests.
[0108] This embodiment can realize automatic control of interface traffic and avoid service congestion.
[0109] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0110] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0111] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0112] Further references Figure 3 , as a response to the above Figure 2 The present application provides an embodiment of a device for adjusting the timeout period of an interface. Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0113] like Figure 4 As shown, the interface timeout adjustment device 300 described in this embodiment includes: a first acquisition module 301, a first sending module 302, a second acquisition module 303, a calculation module 304, a second sending module 305 and an adjustment module 306. Among them:
[0114] The first acquisition module 301 is used to receive an access request, acquire all interfaces corresponding to the access request, and read the first timeout period of all the interfaces;
[0115] The first sending module 302 is used to send the access request to the server through the interface according to the first timeout period, and push the time-consuming data corresponding to the interface to the data storage end for storage and recording;
[0116] The second acquisition module 303 is used to determine the target interface and acquire the time consumption data of the target interface within a preset time period as the target time consumption data;
[0117] The calculation module 304 is used to calculate the average request time consumption of the target interface in the preset time period based on the target time consumption data;
[0118] The second sending module 305 is used to determine the initial interface group where the target interface is located, and send the average request time to the initial interface group;
[0119] The adjustment module 306 is used to adjust the first timeout time of the target interface according to the second timeout time of the initial interface group and the average request duration.
[0120] It should be emphasized that in order to further ensure the privacy and security of the time-consuming data, the above time-consuming data can also be stored in a node of a blockchain.
[0121] The timeout adjustment device of the above-mentioned interface can realize dynamic adjustment of the interface timeout by calculating the average request time of the target interface within a preset time period, and adjusting the timeout of the target interface according to the average request time, thereby avoiding the problem of long-term occupation of the request link caused by uniformly setting the timeout time, and can further quickly release resources and optimize interface services.
[0122] In this embodiment, the second acquisition module 303 is further used for:
[0123] According to the preset timing mechanism, when the set time is reached, the scheduled task corresponding to the set time is obtained as the target scheduled task;
[0124] Determining a target interface according to execution parameters of the target scheduled task;
[0125] Based on the target interface, the time consumption data within the preset time period is acquired from the data storage end as the target time consumption data.
[0126] This embodiment can improve the efficiency of obtaining time-consuming data.
[0127] In this embodiment, the second sending module 305 is further used for:
[0128] Acquire interface parameters of the target interface, and obtain an initial interface group where the target interface is located according to the interface parameters;
[0129] The interface parameters and the average request time are encapsulated into a message queue, and the average request time is sent to the corresponding initial interface group through the message queue.
[0130] This embodiment sends the average request time in the form of a message queue, which can improve the efficiency and accuracy of message sending.
[0131] In this embodiment, the adjustment module 306 includes a comparison unit, a query unit and an adjustment unit, wherein:
[0132] The comparison unit is used to compare the second timeout time and the average request duration;
[0133] The query unit is used for querying the corresponding target interface group according to the average request time when the average request time is not within the second timeout range;
[0134] The adjusting unit is used for adjusting the target interface from the initial interface group to the target interface group.
[0135] This embodiment can realize dynamic adjustment of the interface timeout period and optimize the interface service.
[0136] In some optional implementations of this embodiment, the adjustment module 306 also includes a determination unit for determining whether an abnormality occurs in the associated party corresponding to the target timing task; when an abnormality occurs in the associated party, determining whether to adjust the target interface to the target interface group based on the priority of the target timing task.
[0137] This embodiment can avoid interruption of important services and ensure normal services.
[0138] In this embodiment, the interface timeout adjustment device 300 further includes a third acquisition module, which is used to acquire access content corresponding to the access request through the call link of the server.
[0139] In some optional implementations of the present embodiment, the interface timeout adjustment device 300 also includes a confirmation module, which is used to determine whether to perform a queuing operation or a releasing operation on the access request according to the current current limiting status of all the interfaces, and when releasing the access request, stores the interface response time of the access request as time-consuming data in the response time queue.
[0140] This embodiment can realize automatic control of interface traffic and avoid service congestion.
[0141] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0142] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 4 with components 41-43, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0143] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0144] The memory 41 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 41 can be an internal storage unit of the computer device 4, such as a hard disk or memory of the computer device 4. In other embodiments, the memory 41 can also be an external storage device of the computer device 4, such as a plug-in hard disk equipped on the computer device 4, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 41 can also include both the internal storage unit of the computer device 4 and its external storage device. In this embodiment, the memory 41 is generally used to store the operating system and various application software installed on the computer device 4, such as computer-readable instructions of the timeout adjustment method of the interface, etc. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or are to be output.
[0145] The processor 42 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 42 is generally used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to run computer-readable instructions or process data stored in the memory 41, such as computer-readable instructions for running the timeout adjustment method of the interface.
[0146] The network interface 43 may include a wireless network interface or a wired network interface. The network interface 43 is generally used to establish a communication connection between the computer device 4 and other electronic devices.
[0147] This embodiment implements the steps of the timeout adjustment method of the interface in the above embodiment when the processor executes computer-readable instructions stored in the memory. By calculating the average request time of the target interface within a preset time period and adjusting the timeout of the target interface according to the average request time, dynamic adjustment of the interface timeout can be achieved, avoiding the problem of long-term occupation of the request link due to unified setting of the timeout time, and further quickly releasing resources and optimizing interface services.
[0148] The present application also provides another implementation mode, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor so that the at least one processor executes the steps of the interface timeout adjustment method as described above, by calculating the average request time of the target interface within a preset time period, and adjusting the timeout of the target interface according to the average request time, dynamic adjustment of the interface timeout can be achieved, avoiding the problem of long-term occupation of the request link caused by uniformly setting the timeout time, and can further quickly release resources and optimize interface services.
[0149] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods 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, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0150] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A method for adjusting the timeout period of an interface, characterized in that: The steps include: Receive an access request, obtain all interfaces corresponding to the access request, and read first timeout times of all the interfaces; According to the first timeout period, the access request is sent to the server through the interface, and the time-consuming data corresponding to the interface is pushed to the data storage end for storage and recording; Determine a target interface, and obtain time consumption data of the target interface within a preset time period as target time consumption data; Based on the target time consumption data, calculate the average request time consumption of the target interface in the preset time period; Determine an initial interface group where the target interface is located, and send the average request time to the initial interface group; Adjusting the first timeout time of the target interface according to the second timeout time of the initial interface group and the average request time; The step of adjusting the first timeout time of the target interface according to the second timeout time of the initial interface group and the average request time comprises: Compare the second timeout time with the average request duration; When the average request time is not within the second timeout range, the corresponding target interface group is queried according to the average request time; Adjusting the target interface from the initial interface group to the target interface group; Among them, the second timeout time of the initial interface group where the target interface is located is compared with the average request time of the target interface within the preset time period. When the average request time is not within the second timeout time range of the initial interface group, it is queried that the average request time of the target interface falls into another interface group, and the interface group that falls into is the target interface group, and the target interface is adjusted from the initial interface group to the target interface group.
2. The method for adjusting the interface timeout according to claim 1, characterized in that: The step of determining the target interface and obtaining the time consumption data of the target interface within a preset time period as the target time consumption data includes: According to the preset timing mechanism, when the set time is reached, the scheduled task corresponding to the set time is obtained as the target scheduled task; Determining a target interface according to execution parameters of the target scheduled task; Based on the target interface, the time consumption data within the preset time period is acquired from the data storage end as the target time consumption data.
3. The method for adjusting the interface timeout according to claim 1, characterized in that: The step of determining the initial interface group where the target interface is located and sending the average request time to the initial interface group comprises: Acquire interface parameters of the target interface, and obtain an initial interface group where the target interface is located according to the interface parameters; The interface parameters and the average request time are encapsulated into a message queue, and the average request time is sent to the corresponding initial interface group through the message queue.
4. The method for adjusting the interface timeout according to claim 1, characterized in that: After the step of when the average request duration is not within the second timeout range, the method further includes: Determine whether there is any abnormality in the associated party corresponding to the target scheduled task; When an abnormality occurs in the associated party, it is determined whether to adjust the target interface to the target interface group according to the priority of the target scheduled task.
5. The method for adjusting the interface timeout according to claim 1, characterized in that: After the step of sending the access request to the server through the interface, the method further includes: Access content corresponding to the access request is obtained through the call link of the server.
6. The method for adjusting the interface timeout according to claim 1, characterized in that: After the step of receiving the access request and acquiring all interfaces corresponding to the access request, the method further includes: Determine whether to perform a queuing operation or a releasing operation on the access request according to the current current limiting status of all the interfaces, and when releasing the access request, store the interface response time of the access request as time-consuming data in a response time queue.
7. A device for adjusting the timeout period of an interface, characterized in that: include: A first acquisition module, configured to receive an access request, acquire all interfaces corresponding to the access request, and read a first timeout period of all the interfaces; A first sending module, configured to send the access request to the server through the interface according to the first timeout period, and push the time-consuming data corresponding to the interface to the data storage end for storage and recording; A second acquisition module is used to determine a target interface and acquire time consumption data of the target interface within a preset time period as target time consumption data; A calculation module, used for calculating the average request time consumption of the target interface in the preset time period based on the target time consumption data; A second sending module, used for determining an initial interface group where the target interface is located, and sending the average request time to the initial interface group; An adjustment module, configured to adjust the first timeout time of the target interface according to the second timeout time of the initial interface group and the average request time; The adjustment module includes a comparison unit, a query unit and an adjustment unit, wherein: The comparison unit is used to compare the second timeout time and the average request duration; The query unit is used for querying the corresponding target interface group according to the average request time when the average request time is not within the second timeout range; The adjusting unit is used for adjusting the target interface from the initial interface group to the target interface group; Among them, the second timeout time of the initial interface group where the target interface is located is compared with the average request time of the target interface within the preset time period. When the average request time is not within the second timeout time range of the initial interface group, it is queried that the average request time of the target interface falls into another interface group, and the interface group that falls into is the target interface group, and the target interface is adjusted from the initial interface group to the target interface group.
8. A computer device, comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the method for adjusting the timeout period of an interface as claimed in any one of claims 1 to 6 when executing the computer-readable instructions.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the method for adjusting the timeout period of an interface according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Data processing method for interface timeout management
CN110879758A
Queue timeout processing method in request task processing and storage medium
CN111858086A