Request response method, system, computer system and readable storage medium
By starting delayed tasks and merging external interface calls in the intelligent response system, the problem of large concurrency of external interface calls is solved, effective management of network and external system resources is achieved, and resource consumption is reduced.
Patent Information
- Application Number
- CN202010234430.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-27
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2040-03-27
AI Technical Summary
In the intelligent response system, the concurrency of external interface calls is large, resulting in excessive consumption of network resources and system resources of external systems.
By starting the delayed task, the request is stored in the task queue, and when the delayed task reaches the time limit, it responds to the request in the task queue and triggers the external interface call, thus realizing the merging of external interface calls.
It reduces the system resource consumption of network resources and external systems, slows down the response pressure of external interfaces, and improves resource utilization.
Smart Images

Figure CN111753065B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and more specifically, to a request response method, a request response system, a computer system, and a computer-readable storage medium. Background Art
[0002] A common application scenario of the intelligent response system is to provide online responses to customers as an intelligent customer service. In the intelligent customer service scenario, the session management decision, the judgment of the response decision tree, the assembly of the answer, etc. in the intelligent response system generally need to be implemented by calling various external business interfaces. For example: in order to give effective responses under different order statuses, it is necessary to query the user's order status. At this time, the common external interfaces called include: user information query interface, order query interface, logistics query interface, etc.
[0003] In the process of implementing the concept of the present disclosure, the inventors found that there are at least the following problems in the related art: the number of concurrent external interface calls is large, resulting in large consumption of network resources and system resources of the external system. Summary of the invention
[0004] In view of this, the present disclosure provides a request response method, a request response system, a computer system and a computer-readable storage medium.
[0005] One aspect of the present disclosure provides a request response method, including: obtaining one or more requests for requesting to call an external interface; starting a delayed task and storing the one or more requests in a task queue; after the delayed task reaches a delay time, responding to one or more requests in the task queue to trigger an external interface call; and receiving a return result from the external interface.
[0006] Another aspect of the present disclosure provides a request response system, including: an acquisition module, used to obtain one or more requests for requesting to call an external interface; a start module, used to start a delayed task and store the one or more requests in a task queue; a response module, used to respond to one or more requests in the task queue after the delayed task reaches the delay time, triggering an external interface call; and a receiving module, used to receive the return result from the external interface.
[0007] Another aspect of the present disclosure provides a computer system, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the above-mentioned method.
[0008] Another aspect of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, which are used to implement the above method when executed.
[0009] Another aspect of the present disclosure provides a computer program, wherein the computer program includes computer executable instructions, and the instructions are used to implement the above method when executed.
[0010] Through the embodiments of the present disclosure, after obtaining one or more requests for requesting to call an external interface, the one or more requests are stored in a task queue by starting a delayed task; after the delayed task reaches the delay time, one or more requests in the task queue are responded to, triggering the external interface call; and receiving the return result from the external interface. Since one or more requests are stored in a task queue, and after the delayed task reaches the delay time, the request is responded to, triggering the external interface call, it is possible to control the external interface call and achieve the merging of the external interface calls, so it at least partially overcomes the technical problem in the related art that the number of concurrent external interface calls is large, resulting in large consumption of network resources and system resources of the external system, and achieves the technical effect of reducing the consumption of network resources and system resources of the external system. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The above and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:
[0012] Figure 1 An exemplary system architecture to which the request response method and system according to an embodiment of the present disclosure can be applied is schematically shown;
[0013] Figure 2 A diagram schematically showing the relationship between the main process of the intelligent response system calling different business components according to an embodiment of the present disclosure;
[0014] Figure 3 A flowchart of a request response method according to an embodiment of the present disclosure is schematically shown;
[0015] Figure 4 A schematic diagram schematically shows a request response method applied in an intelligent answering system according to an embodiment of the present disclosure;
[0016] Figure 5 A flowchart of storing one or more requests in a task queue according to an embodiment of the present disclosure is schematically shown;
[0017] Figure 6 A flowchart schematically illustrates a flow chart of accumulating requests for calling the same external interface into the same task queue according to an embodiment of the present disclosure;
[0018] Figure 7 A schematic diagram schematically shows how to allocate requests to sub-queues of the same task queue according to an embodiment of the present disclosure;
[0019] Figure 8 A block diagram schematically shows a request response system according to an embodiment of the present disclosure; and
[0020] Fig. 9 A block diagram of a computer system suitable for implementing the method described above according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0021] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.
[0022] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.
[0023] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification, and should not be interpreted in an idealized or overly rigid manner.
[0024] In the case of using expressions such as "at least one of A, B, and C, etc.", it should generally be interpreted in accordance with the meaning of the expression generally understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.). In the case of using expressions such as "at least one of A, B, or C, etc.", it should generally be interpreted in accordance with the meaning of the expression generally understood by those skilled in the art (for example, "a system having at least one of A, B, or C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0025] The present disclosure provides a request response method and system, the method comprising: obtaining one or more requests for requesting to call an external interface; starting a delayed task and storing one or more requests in a task queue; after the delayed task reaches a delay time, responding to one or more requests in the task queue to trigger an external interface call; and receiving a return result from the external interface.
[0026] Figure 1 The exemplary system architecture to which the request response method and system according to the embodiment of the present disclosure can be applied is schematically shown. It should be noted that: Figure 1 What is shown is merely an example of a system architecture to which the embodiments of the present disclosure can be applied, in order to help those skilled in the art understand the technical content of the present disclosure, but it does not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios.
[0027] like Figure 1 As shown, the system architecture 100 according to this embodiment 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 and / or wireless communication links, etc.
[0028] The user can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications can be installed on the terminal devices 101, 102, 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients and / or social platform software, etc. (only as examples), wherein the shopping applications, web browser applications, search applications, instant messaging tools, email clients and / or social platform software, etc. may include an intelligent response system.
[0029] The terminal devices 101 , 102 , and 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0030] The server 105 may be a server that provides various services, including one or more external interfaces. The server 105 may be, for example, a background management server that provides support for websites browsed by users using the terminal devices 101, 102, and 103 (for example only). The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.
[0031] It should be noted that the request response method provided in the embodiment of the present disclosure can generally be executed by the server 105. Accordingly, the request response system provided in the embodiment of the present disclosure can generally be set in the server 105. The request response method provided in the embodiment of the present disclosure can also be executed by a server or server cluster that is different from the server 105 and can communicate with the terminal device 101, 102, 103 and / or the server 105. Accordingly, the request response system provided in the embodiment of the present disclosure can also be set in a server or server cluster that is different from the server 105 and can communicate with the terminal device 101, 102, 103 and / or the server 105. Alternatively, the request response method provided in the embodiment of the present disclosure can also be executed by the terminal device 101, 102, or 103, or it can also be executed by other terminal devices different from the terminal device 101, 102, or 103. Accordingly, the request response system provided in the embodiment of the present disclosure can also be set in the terminal device 101, 102, or 103, or it can be set in other terminal devices different from the terminal device 101, 102, or 103.
[0032] 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.
[0033] In the embodiments of the present disclosure, business logic is encapsulated in the form of business components, so that the main process of the intelligent response system is decoupled from the business, the external business interface call is made configurable, and the external business interface is encapsulated. The intelligent response system includes a response decision tree and multiple business components.
[0034] A business component is an application that can provide support for configuration of business judgment capabilities and answer assembly support to the main process after encapsulating the business logic of external business interface calls and interface results.
[0035] Figure 2 The diagram schematically shows the relationship between the main process of the intelligent response system calling different business components according to an embodiment of the present disclosure.
[0036] like Figure 2 As shown, the intelligent response system 210 includes a response decision tree (i.e., the main process) and components, and the external system 220 includes an order information external interface and a logistics information external interface. Components may include, for example, an order status component, an order type component, a logistics status component, and a delivery personnel query component. It should be noted that Figure 2 Although it is shown that the component can directly call the external interface to obtain data, in another embodiment, the component can first call the internal interface, and then the internal interface calls the external interface to obtain data.
[0037] Taking the user's request to query order information as an example, the main process needs to determine whether the order status is being delivered, so it needs to determine whether the order status is equal to "delivery". At this time, the order status component can call the order information external interface, and "order status component return == delivery" can be configured in the main process response decision tree. If the main process assembly answer needs to add the latest logistics information, the logistics information component can call the logistics information external interface, and the logistics information component returns "the order has arrived at the delivery site (XX Street)". In addition, in order to respond to user requests more comprehensively and completely, the order type component can also call the order information external interface to obtain the order type, and the delivery personnel query component can also call the logistics information external interface to obtain the delivery personnel information.
[0038] It should be noted that Figure 2 Although only order status components and logistics information components are shown, the business components involved in the embodiments of the present disclosure are not limited thereto, and may also include other business components such as user information components, merchant information components, and inventory information components. Figure 2 Although only the order status external interface and the logistics information external interface are shown, the external interfaces involved in the embodiments of the present disclosure are not limited thereto, and may also include other external interfaces such as a user information external interface, a merchant information external interface, and an inventory information external interface. Other external interfaces such as the order status external interface, the logistics information external interface, the user information external interface, the merchant information external interface, and the inventory information external interface may be provided by an external system.
[0039] The external system 220 can not only provide services for the intelligent response system 210, but also provide services for other businesses. In order to increase the stability of the external system 220 and enable the intelligent response system 210 to respond correctly, it is necessary to fairly and reasonably allocate the resources of each caller.
[0040] However, under the current technical implementation, the number of concurrent external interface calls is large, and the QPS (Query per second, abbreviated as QPS, query rate per second) of a single external interface is generally several times the QPS of the main process.
[0041] In the process of implementing the present disclosure, the inventors found that many different business components, in order to meet their respective business needs, generate component results after performing specific business processing on the call results of the same external interface, so under the same request, different components may initiate repeated calls to the same interface. For example, for an order information query request, the order status component and the order type component may both request to call the order information external interface respectively; the logistics status component and the delivery personnel query component may both request to call the logistics information external interface respectively, resulting in different components may initiate repeated calls to the same interface under the same request.
[0042] In addition, components are generally called by the response decision tree, and each application on the response decision tree is executed asynchronously. For example, the response decision tree includes intent recognition applications, status information query applications, answer management applications, answer assembly applications, etc. Each application calls the component in a serial manner. Under the same request, the same component may also initiate repeated calls to the same interface. If there are multiple user requests, each application may concurrently initiate repeated calls to the same component, resulting in the same component also initiating more repeated calls to the same interface. However, within the same request, most external interfaces may return the same results.
[0043] It can be seen that for one or more user requests, the number of repeated calls to the same external interface is large, but the repeated requests will still be sent to the external system, causing a large waste of network resources and system resources of the external system. In the intelligent customer service scenario, the number of concurrent external interface calls is large, which consumes a lot of network resources and system resources of the external system.
[0044] In order to increase the stability of the external system, enable the intelligent response system to respond correctly, realize fair and reasonable resource allocation for each caller, and reduce the waste of network resources and system resources, it is necessary to control the interface call request volume of the intelligent response system. Of course, it should be noted that the embodiments of the present disclosure are not limited to controlling the interface call request volume of the intelligent response system, and the interface call request volume for other scenarios can also be controlled. For example, the interface call request volume of the search engine can also be controlled. Therefore, the request response method provided by the present disclosure can be applied to other scenarios such as intelligent response systems and search engines.
[0045] Figure 3 The flowchart of the request response method according to the embodiment of the present disclosure is schematically shown.
[0046] like Figure 3 As shown, the method includes operations S310 to S340.
[0047] In operation S310, one or more requests for calling an external interface are obtained.
[0048] According to an embodiment of the present disclosure, for example, user A may continuously input multiple requests through an electronic device, for example, order query request, logistics delivery information request, insurance request, etc. Of course, the requests involved in the present disclosure are not limited to the above types.
[0049] According to an embodiment of the present disclosure, for example, the obtained one or more requests may be inputted by a plurality of users respectively, for example, one or more requests may be inputted by user A, user B and user C respectively.
[0050] In operation S320, the delayed task is started, and one or more requests are stored in the task queue.
[0051] In operation S330, after the delayed task reaches the delay time, one or more requests in the task queue are responded to, triggering an external interface call.
[0052] According to an embodiment of the present disclosure, the delay duration is not limited, for example, it can be 100 milliseconds, 200 milliseconds, 500 milliseconds, etc.
[0053] According to an embodiment of the present disclosure, when responding to one or more requests in a task queue, requests with the same request parameters may be merged and deduplicated. For example, requests with the same order ID as request parameters may be merged into one request, and then an external interface call is triggered to respond to the request. Due to a delay for a period of time, user requests for the same request parameters may be obtained. By merging and deduplicating requests with the same request parameters, the number of requests responded to by the external interface is relatively reduced, thereby alleviating the response pressure of the external interface. It should be noted that the delay time should not be too long, and can be determined based on the average response time of the request to prevent the actual response time of the request from being too long, affecting the user experience.
[0054] In operation S340, a return result from the external interface is received.
[0055] According to an embodiment of the present disclosure, after the delayed task triggers the external interface call, the external interface is waited for to return a result. The returned result can be sent back to the corresponding thread according to the mapping relationship between the request and the return, and the thread is awakened, thereby completing the interaction process.
[0056] Through the embodiments of the present disclosure, after obtaining one or more requests for requesting to call an external interface, the one or more requests are stored in a task queue by starting a delayed task; after the delayed task reaches the delay time, one or more requests in the task queue are responded to, triggering the external interface call; and receiving the return result from the external interface. Since one or more requests are stored in a task queue, and after the delayed task reaches the delay time, the request is responded to, triggering the external interface call, it is possible to control the external interface call and achieve the merging of the external interface calls, so it at least partially overcomes the technical problem in the related art that the number of concurrent external interface calls is large, resulting in large consumption of network resources and system resources of the external system, and achieves the technical effect of reducing the consumption of network resources and system resources of the external system.
[0057] Reference below Figures 4 to 7 , combined with specific embodiments Figure 2 The method shown is further explained.
[0058] Figure 4 The following is a schematic diagram of applying a request response method in an intelligent answering system according to an embodiment of the present disclosure.
[0059] like Figure 4 As shown, user A, user B, and user C can input one or more requests respectively, which are processed by different response decision trees. For example, the requests generated by user A and user B due to consultation are processed by response decision tree 1, and the request generated by user C due to consultation is processed by response decision tree 2. Then, response decision tree 1 and response decision tree 2 can call corresponding components respectively, such as component X, component Y, and component Z. Internal interfaces 1 to 3 are called through components X, component Y, and component Z, and external interfaces are called by internal interfaces 1 to 3.
[0060] According to an embodiment of the present disclosure, after a delayed task reaches a delay duration, one or more requests in the task queue are responded to, and triggering an external interface call includes: after the delayed task reaches a delay duration, a batch external interface call can be triggered to implement batch processing of requests in the task queue.
[0061] For example, after one or more requests are transmitted through internal interfaces 1 to 3, the delayed task scheduler can be used to start the delayed task. After the delayed task is started, the request can be stored in the task queue and the current request thread can be suspended. After the delayed task expires, an external batch processing interface call is initiated. Relying on the batch processing capability provided by the external interface, the request response efficiency is improved.
[0062] Figure 5 The flowchart of storing one or more requests in a task queue according to an embodiment of the present disclosure is schematically shown.
[0063] like Figure 5 As shown, starting the delayed task and storing one or more requests in the task queue includes operations S510 to S520.
[0064] In operation S510, an external interface corresponding to each request is determined.
[0065] According to an embodiment of the present disclosure, the external interface corresponding to the request can be determined according to the parameters included in each request.
[0066] In operation S520 , requests for calling the same external interface are accumulated in the same task queue, wherein different task queues are for different external interfaces.
[0067] like Figure 4 As shown, requests 1 to 6 request to call external interface 1, and requests 1 to 6 can be stored in the queue of external interface 1; requests 7 to 12 request to call external interface 2, and requests 7 to 12 can be stored in the queue of external interface 2; requests 13 to 18 request to call external interface 3, and requests 13 to 18 can be stored in the queue of external interface 3. It should be noted that the same request can also be used to request to call multiple external interfaces. In this case, the same request for calling multiple external interfaces can also be allocated to multiple external interface queues to wait for responses.
[0068] According to an embodiment of the present disclosure, after determining the external interface corresponding to each request, a delay task corresponding to the external interface corresponding to each request may be created; and the delay duration of the delay task corresponding to the external interface may be determined.
[0069] For example, Figure 4 As shown, delay task 1 can correspond to external interface 1, and is responsible for processing requests in the queue of external interface 1; delay task 2 can correspond to external interface 2, and is responsible for processing requests in the queue of external interface 2; delay task 3 can correspond to external interface 3, and is responsible for processing requests in the queue of external interface 3.
[0070] According to an embodiment of the present disclosure, the delay duration of the delay task corresponding to the external interface may be preset and fixed, or may be dynamically adjusted.
[0071] According to an embodiment of the present disclosure, the delay duration of the delay task corresponding to the external interface can be dynamically adjusted according to the actual request volume of the external interface and the request volume threshold of the external interface.
[0072] According to an embodiment of the present disclosure, for example, the delay duration can be set to 10ms by default, and then the delay duration can be dynamically adjusted based on the request volume threshold of the external interface. Taking the request volume threshold of the external interface as the query volume per second QPS as an example, the calculation method for dynamically adjusting the delay duration of the delay task corresponding to the external interface can be: delay duration = (actual QPS of the external interface / 1000ms) × (actual QPS of the external interface / request volume threshold QPS of the external interface).
[0073] For example, the intelligent response system calls the order status external interface with a QPS of 1000, and the request volume threshold QPS of the external interface is 500, then the delay duration = (1000 / 1000ms) × (1000 / 500) = 2ms.
[0074] Of course, the calculation method of the delay duration is not limited to the above method. It only needs to be able to dynamically adjust the delay duration of the delay task corresponding to the external interface according to the actual request volume of the external interface and the request volume threshold of the external interface.
[0075] Figure 6 The flowchart schematically shows a flow chart of accumulating requests for calling the same external interface into the same task queue according to an embodiment of the present disclosure.
[0076] According to an embodiment of the present disclosure, different external interfaces may correspond to different task queues. Each task queue may include sub-queues of different processing levels, and each sub-queue is provided with a corresponding threshold range. Sub-queues of different processing levels may include, for example, a fast queue, a general queue, and a slow queue.
[0077] like Figure 6 As shown, accumulating requests for calling the same external interface into the same task queue includes operations S610 to S620.
[0078] In operation S610, a weight for each request for calling the same external interface is determined.
[0079] According to an embodiment of the present disclosure, the weight of each request can be determined based on the average response time of the external interface, the average response time of the feature called by each request, and the total number of calls of the feature. According to an embodiment of the present disclosure, the weight of each request can be the weight affected by the call time of one or more features called by it.
[0080] According to an embodiment of the present disclosure, the average response time of the external interface=TotalAverageResponseTime().
[0081] For example, the average response time of querying the order interface by order number = the sum of all query interface times within 5 minutes / the number of all requests within 5 minutes. For example, the sum of all query interface times within 5 minutes is 200ms+200ms+400ms, the number of all requests within 5 minutes is 3, and the average response time = 266.67ms.
[0082] According to an embodiment of the present disclosure, the feature called by each request = hash (request input parameter), that is, the hash value of the input parameter is calculated.
[0083] For example, to query order details by order number, call the input request feature = hash(input order number + user account id).
[0084] According to an embodiment of the present disclosure, the average response time of a single feature=AverageResponseTime(single call request feature).
[0085] For example, the average call duration of order number 1234 of the order interface queried by order number = the sum of the durations of querying order 1234 within 5 minutes / the number of 1234 orders queried within 5 minutes. For example, the average call duration is calculated to be 200ms.
[0086] According to an embodiment of the present disclosure, the total number of calls of a single feature=TotalCallTimes (single call request feature).
[0087] For example, the total number of calls within 72 hours for order number 1234 of the order interface queried by order number = 200 times.
[0088] According to an embodiment of the present disclosure, the weight of each request=(AverageResponseTime(single call request feature)-TotalAverageResponseTime())*lg(TotalCallTimes(single call request feature)).
[0089] For example, in combination with the above example, the weight of the call impact of order number 1234 of the order query interface by order number is calculated = (200ms-266.67ms)*lg(200 times)=-66.67*2.3=-153.34.
[0090] In operation S620 , the requests are allocated to sub-queues of the same task queue according to the weight of each request and the threshold range corresponding to each sub-queue.
[0091] According to the embodiments of the present disclosure, when some external interfaces are called, different parameters have different response speeds. If all parameters are called in batches regardless of speed, the overall call time will be longer, affecting performance. Therefore, three levels of queues can be provided for each external interface task queue: fast queue, slow queue, and general queue. Requests can enter the general queue by default. This ensures that slow requests are called together with slow requests, and fast requests are called together with fast requests, reducing the impact of accumulated flow on response time.
[0092] Figure 7 The diagram schematically shows a schematic diagram of allocating requests to sub-queues of the same task queue according to an embodiment of the present disclosure.
[0093] According to an embodiment of the present disclosure, after different requests for calling the same external interface are allocated to different sub-queues, the requests in the sub-queues may be dynamically adjusted. Figure 7 As shown, different sub-queues of the same task queue include a slow queue, a general queue, and a fast queue.
[0094] According to the embodiments of the present disclosure, for example, for the slow queue, the general queue, and the fast queue, each queue has its own threshold range. When the weight of the request is greater than the upper threshold, the request call can be downgraded to the lower queue (if there is no lower queue, it will not move), if the weight is less than the lower threshold, the call is upgraded to the upper queue (if there is no upper queue, it will not move), otherwise it will enter and remain in the current queue.
[0095] For example, the definition of the rise and fall thresholds of each queue of the order query interface by order number is shown in Table 1.
[0096] Table 1
[0097]
[0098] According to an embodiment of the present disclosure, by dynamically adjusting the sub-queue into which the request enters, the impact of accumulating requests in the task queue on the response time can be reduced; based on the calculated weight of the request that affects the call time, when the weight exceeds the threshold range of the current queue, this type of request can be downgraded or upgraded and divided into different sub-queues.
[0099] According to an embodiment of the present disclosure, before starting a delayed task and storing one or more requests in a task queue, the request type of each of the one or more requests obtained may be determined. For example, the request type may include a query type and a write type, etc.
[0100] For a query request whose request type is a query type, it can be determined whether the cache includes the query results of the query request; if it is determined that the cache includes the query results of the query request, the query results of the query request are returned in response to the query request; if it is determined that the cache does not include the query results of the query request, a delayed task is started to store one or more requests in a task queue.
[0101] like Figure 4 As shown, for a query request of a query type, it can be determined whether the Redis cache includes the query result of the query request. If not, the delayed task scheduler can be used to start the delayed task and store one or more requests in the task queue.
[0102] Through the embodiments of the present disclosure, after obtaining a request, the result is obtained from the Redis cache first (for example, obtaining the order details cache based on the order ID), and the result is returned if the result is obtained successfully. For example, for repeated queries with the same query interface and the same input parameters, such as multiple requests for order details queries initiated for the same order ID, the order details may be pre-cached in the Redis cache. By obtaining the result from the Redis cache first, the number of requests in the task queue can be reduced, saving network resources.
[0103] According to an embodiment of the present disclosure, when it is determined that the cache does not include the query result of the query request, before executing the operation of starting the delayed task and storing one or more requests in the task queue, an attempt can be made to obtain a distributed lock for triggering an external interface call; when the distributed lock is obtained, the operation of starting the delayed task and storing one or more requests in the task queue is executed; when the distributed lock is not obtained, a circular waiting strategy is executed to determine again whether the cache includes the query result of the query request.
[0104] According to an embodiment of the present disclosure, if the current request can obtain a distributed lock for triggering an external interface call, it means that other requests have not yet obtained the distributed lock. If the current request cannot obtain a distributed lock, it means that other requests have already obtained the distributed lock. The failure to obtain a distributed lock indicates that a request including the same parameters has already obtained a distributed lock and has been stored in the task queue waiting for a response, or a response result may be being returned at this time. If the current request continues to be stored in the task queue at this time, the number of requests in the task queue will increase, and the response time of subsequent requests will be extended; if the current request is not stored in the task queue at this time, but a circular waiting strategy is executed to determine again whether the cache includes the query result of the query request (because after the request including the same parameters is responded to, the returned response result will be stored in the cache), the number of requests in the task queue can be reduced, and the response time of subsequent requests can be reduced. By caching the results, when a subsequent request is obtained, it can be read directly from the cache, thereby improving the parallelism of the system and reducing the delay caused by the accumulation of current.
[0105] According to an embodiment of the present disclosure, a loop waiting strategy may include a single waiting time, for example, 10 milliseconds. When the current request does not acquire a distributed lock, a loop waiting strategy is executed, that is, after waiting for 1 waiting time (10 milliseconds), it is determined again whether the cache includes the query result of the query request. If the cache still does not include the query result of the query request after waiting for 1 waiting time (10 milliseconds), one or more waiting times can be dynamically extended. The number of dynamic extensions can be adjusted according to the waiting success rate.
[0106] For example, if the success rate of successfully obtaining query results from the cache is greater than 10% within 1 minute, one waiting period can be dynamically extended; or, if the success rate of successfully obtaining query results from the cache is greater than 30% within 1 minute, two waiting periods can be dynamically extended; if the success rate of successfully obtaining query results from the cache is greater than 50% within 1 minute, three waiting periods can be dynamically extended, and so on.
[0107] According to an embodiment of the present disclosure, if there is still no query result after executing the waiting strategy for a certain period of time, the previous distributed lock can be dynamically released and the currently first obtained request can be locked. When the distributed lock is obtained, the start delay task is executed and the currently first obtained request is stored in the task queue.
[0108] Through the embodiments of the present disclosure, the technical problem of a large number of repeated calls to the same external interface can be solved, so that repeated requests are reduced or not sent to the external system, saving network resources and system resources of the external system.
[0109] According to an embodiment of the present disclosure, for write requests of write type, the write requests can be stored in a cache; after waiting for a preset period of time, the write requests with the same write parameters in the cache are deduplicated; and the write requests obtained after deduplication are stored in a task queue.
[0110] According to an embodiment of the present disclosure, after obtaining a write request, the input parameters of the write request can be cached first, and a preset time period can be waited, for example, 100 milliseconds. During the waiting process, any interface write request with the same input parameters can be directly discarded. After the preset waiting time period is over, the write request obtained after deduplication is stored in the task queue.
[0111] Through the embodiments of the present disclosure, if the same input parameter is written repeatedly, the repeated writes in a short period of time can be merged and deduplicated, for example, only written once, thereby reducing repeated writes to external interfaces, reducing network resource waste, and improving system resource utilization.
[0112] Through the embodiments of the present disclosure, while ensuring that the response time is within the normal range, the external interface call volume is reduced to below the target QPS (reduced to below 50%), and the network bandwidth usage is reduced by more than 20%, which is a significant improvement.
[0113] Figure 8 A block diagram of a request response system according to an embodiment of the present disclosure is schematically shown.
[0114] like Figure 8 As shown, the request response system 800 includes: an acquisition module 810 , a start module 820 , a response module 830 and a receiving module 840 .
[0115] The acquisition module 810 is used to obtain one or more requests for calling an external interface.
[0116] The starting module 820 is used to start the delayed task and store the one or more requests in the task queue.
[0117] The response module 830 is used to respond to one or more requests in the above-mentioned task queue after the above-mentioned delayed task reaches the delay time, triggering the external interface call.
[0118] The receiving module 840 is used to receive the return result from the above external interface.
[0119] Through the embodiments of the present disclosure, after obtaining one or more requests for requesting to call an external interface, the one or more requests are stored in a task queue by starting a delayed task; after the delayed task reaches the delay time, one or more requests in the task queue are responded to, triggering the external interface call; and receiving the return result from the external interface. Since one or more requests are stored in a task queue, and after the delayed task reaches the delay time, the request is responded to, triggering the external interface call, it is possible to control the external interface call and achieve the merging of the external interface calls, so it at least partially overcomes the technical problem in the related art that the number of concurrent external interface calls is large, resulting in large consumption of network resources and system resources of the external system, and achieves the technical effect of reducing the consumption of network resources and system resources of the external system.
[0120] According to an embodiment of the present disclosure, the startup module 820 is used to: determine the external interface corresponding to each request, and store the requests for calling the same external interface into the same task queue, wherein different task queues are for different external interfaces.
[0121] According to an embodiment of the present disclosure, the request response system 800 further includes: a creation module and a first determination module.
[0122] The creation module is used to create a delayed task corresponding to the external interface corresponding to each of the above requests.
[0123] The first determining module is used to determine the delay duration of the delay task corresponding to the external interface.
[0124] According to an embodiment of the present disclosure, determining the delay duration of the delay task corresponding to the above-mentioned external interface includes: dynamically adjusting the delay duration of the delay task corresponding to the above-mentioned external interface according to the actual request amount of the above-mentioned external interface and the request amount threshold of the above-mentioned external interface.
[0125] According to an embodiment of the present disclosure, each of the above-mentioned different task queues includes sub-queues of different processing levels, each sub-queue is set with a corresponding threshold range, and accumulating requests for requesting to call the same external interface into the same task queue includes: determining the weight of each request for requesting to call the same external interface. And according to the weight of each request and the threshold range corresponding to each sub-queue, each request is allocated to the sub-queue of the same task queue.
[0126] According to an embodiment of the present disclosure, determining the weight of each request for requesting to call the same external interface includes: determining the weight of each request based on the average response time of the same external interface, the average response time of the feature called by each request, and the total number of calls of the feature.
[0127] According to an embodiment of the present disclosure, after the above-mentioned delayed task reaches the delay duration, one or more requests in the above-mentioned task queue are responded to, and triggering the external interface call includes: after the above-mentioned delayed task reaches the delay duration, triggering the batch external interface call to realize batch processing of the requests in the above-mentioned task queue.
[0128] According to an embodiment of the present disclosure, the request response system 800 further includes: a second determination module, a third determination module and a return module.
[0129] The second determination module is used to determine the request type of each of the one or more requests before starting the delayed task and storing the one or more requests in the task queue.
[0130] The third determination module is used to determine, for a query request whose request type is a query type, whether the cache includes a query result of the query request.
[0131] The returning module is used to return the query result of the query request in response to the query request when it is determined that the cache includes the query result of the query request.
[0132] The startup module 820 is used to execute the operation of starting the delayed task and storing the one or more requests in the task queue when it is determined that the query result of the query request is not included in the cache.
[0133] According to an embodiment of the present disclosure, the above-mentioned acquisition module 810 is used to execute the operation of starting a delayed task and trying to acquire a distributed lock used to trigger an external interface call before storing the above-mentioned one or more requests in the task queue when it is determined that the query result of the above-mentioned query request is not included in the cache.
[0134] According to an embodiment of the present disclosure, the startup module 820 is used to execute the operation of starting the delayed task and storing the one or more requests in the task queue when the distributed lock is acquired.
[0135] According to an embodiment of the present disclosure, the third determination module is used to execute a circular waiting strategy when the distributed lock is not acquired, and to determine again whether the cache includes the query result of the query request.
[0136] According to an embodiment of the present disclosure, the request response system 800 further includes: a storage module and a deduplication module.
[0137] The storage module is used for storing the write request of the write type into the cache.
[0138] The deduplication module is used to deduplicate write requests with the same write parameters in the above cache after waiting for a preset period of time.
[0139] The startup module 820 is used to store the write request obtained after deduplication into the task queue.
[0140] According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits, or at least part of the functions of any one of them can be implemented in one module. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be split into multiple modules for implementation. According to the embodiments of the present invention, any one or more of the modules, submodules, units, and subunits can be at least partially implemented as hardware circuits, such as field programmable gate arrays (FPGAs), programmable logic arrays (PLAs), systems on chips, systems on substrates, systems on packages, application specific integrated circuits (ASICs), or can be implemented by hardware or firmware in any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware, and firmware, or in any appropriate combination of any of them. Alternatively, according to the embodiments of the present invention, one or more of the modules, submodules, units, and subunits can be at least partially implemented as computer program modules, and when the computer program modules are run, the corresponding functions can be performed.
[0141] For example, any multiple of the acquisition module 810, the startup module 820, the response module 830, and the receiving module 840 can be combined in one module / unit / sub-unit for implementation, or any one of the modules / units / sub-units can be split into multiple modules / units / sub-units. Alternatively, at least part of the functions of one or more modules / units / sub-units in these modules / units / sub-units can be combined with at least part of the functions of other modules / units / sub-units and implemented in one module / unit / sub-unit. According to an embodiment of the present disclosure, at least one of the acquisition module 810, the startup module 820, the response module 830, and the receiving module 840 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or by any one of the three implementation methods of software, hardware, and firmware, or by a suitable combination of any of them. Alternatively, at least one of the acquisition module 810 , the start module 820 , the response module 830 , and the receiving module 840 may be at least partially implemented as a computer program module, and when the computer program module is executed, a corresponding function may be performed.
[0142] It should be noted that the request response system part in the embodiment of the present disclosure corresponds to the request response method part in the embodiment of the present disclosure. The description of the request response system part specifically refers to the request response method part, which will not be repeated here.
[0143] Fig. 9 A block diagram of a computer system suitable for implementing the method described above according to an embodiment of the present disclosure is schematically shown. Fig. 9 The computer system shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0144] like Fig. 9 As shown, the computer system 900 according to the embodiment of the present disclosure includes a processor 901, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 902 or the program loaded from the storage part 908 to the random access memory (RAM) 903. The processor 901 may include, for example, a general-purpose microprocessor (such as a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (for example, an application-specific integrated circuit (ASIC)), etc. The processor 901 may also include an onboard memory for caching purposes. The processor 901 may include a single processing unit or multiple processing units for performing different actions of the method flow according to the embodiment of the present disclosure.
[0145] In RAM 903, various programs and data required for the operation of system 900 are stored. Processor 901, ROM 902 and RAM 903 are connected to each other through bus 904. Processor 901 performs various operations of the method flow according to the embodiment of the present disclosure by executing the program in ROM 902 and / or RAM 903. It should be noted that the program can also be stored in one or more memories other than ROM 902 and RAM 903. Processor 901 can also perform various operations of the method flow according to the embodiment of the present disclosure by executing the program stored in the one or more memories.
[0146] According to an embodiment of the present disclosure, the system 900 may further include an input / output (I / O) interface 905, which is also connected to the bus 904. The system 900 may further include one or more of the following components connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.
[0147] According to an embodiment of the present disclosure, the method flow according to an embodiment of the present disclosure can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the processor 901, the above-mentioned functions defined in the system of the embodiment of the present disclosure are executed. According to an embodiment of the present disclosure, the system, equipment, device, module, unit, etc. described above can be implemented by a computer program module.
[0148] The present disclosure also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present disclosure is implemented.
[0149] According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium. For example, it may include, but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, apparatus, or device.
[0150] For example, according to an embodiment of the present disclosure, the computer-readable storage medium may include the ROM 902 and / or the RAM 903 described above and / or one or more memories other than the ROM 902 and the RAM 903 .
[0151] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box may also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions. It can be understood by those skilled in the art that the features recorded in the various embodiments and / or claims of the present disclosure can be combined and / or combined in a variety of ways, even if such a combination or combination is not explicitly recorded in the present disclosure. In particular, without departing from the spirit and teaching of the present disclosure, the features described in the various embodiments and / or claims of the present disclosure may be combined and / or combined in a variety of ways. All of these combinations and / or combinations fall within the scope of the present disclosure.
[0152] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. The scope of the present disclosure is defined by the attached claims and their equivalents. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.
Claims
1. A request response method, comprising: Obtain one or more requests for calling an external interface; Starting a delayed task and storing the one or more requests in a task queue; After the delayed task reaches the delay time, respond to one or more requests in the task queue and trigger an external interface call; Receiving a return result from the external interface; The starting of the delayed task and storing the one or more requests in the task queue includes: Determine the external interface corresponding to each request; accumulating requests for calling the same external interface into the same task queue, wherein different task queues are for different external interfaces; each of the different task queues includes sub-queues at different processing levels; The step of accumulating the requests for calling the same external interface into the same task queue includes: Determine the weight of each request according to the average response time of the same external interface, the average response time of the feature called by each request, and the total number of calls of the feature; According to the weight of each request, each request is allocated to a subqueue of the same task queue.
2. The method according to claim 1, further comprising: Creating a delayed task corresponding to the external interface corresponding to each of the requests; as well as Determine the delay duration of the delay task corresponding to the external interface.
3. The method according to claim 2, wherein: The step of determining the delay duration of the delay task corresponding to the external interface comprises: The delay duration of the delay task corresponding to the external interface is dynamically adjusted according to the actual request amount of the external interface and the request amount threshold of the external interface.
4. The method according to claim 1, wherein: Each sub-queue is set with a corresponding threshold range; The step of accumulating the requests for calling the same external interface into the same task queue also includes: According to the weight of each request and the threshold range corresponding to each sub-queue, each request is allocated to a sub-queue of the same task queue.
5. The method according to claim 1, wherein: After the delayed task reaches the delay time, responding to one or more requests in the task queue and triggering the external interface call includes: After the delayed task reaches the delay time, the batch processing external interface call is triggered to implement batch processing of the requests in the task queue.
6. The method according to claim 1, further comprising: Before starting the delayed task and storing the one or more requests in the task queue, determining a request type for each of the one or more requests; For a query request whose request type is a query type, determining whether the cache includes a query result of the query request; In the case of determining that the cache includes the query result of the query request, returning the query result of the query request in response to the query request; When it is determined that the cache does not include the query result of the query request, an operation of starting a delayed task and storing the one or more requests in a task queue is executed.
7. The method according to claim 6, further comprising: When it is determined that the cache does not include the query result of the query request, before executing the operation of starting the delayed task and storing the one or more requests in the task queue, Try to acquire the distributed lock used to trigger external interface calls; When the distributed lock is acquired, executing the operation of starting the delayed task and storing the one or more requests in the task queue; In the case where the distributed lock is not acquired, a circular waiting strategy is executed to determine again whether the cache includes the query result of the query request.
8. The method according to claim 6, further comprising: For a write request whose request type is a write type, storing the write request in the cache; After waiting for a preset time, deduplication processing is performed on write requests with the same write parameters in the cache; as well as The write request obtained after deduplication is stored in the task queue.
9. A request response system, comprising: An acquisition module, used for obtaining one or more requests for calling an external interface; A starting module, used for starting the delayed task and storing the one or more requests in a task queue; A response module, used to respond to one or more requests in the task queue and trigger an external interface call after the delayed task reaches the delay time; A receiving module, used for receiving a return result from the external interface; The starting of the delayed task and storing the one or more requests in the task queue includes: Determine the external interface corresponding to each request; accumulating requests for calling the same external interface into the same task queue, wherein different task queues are for different external interfaces; each of the different task queues includes sub-queues at different processing levels; The step of accumulating the requests for calling the same external interface into the same task queue includes: Determine the weight of each request according to the average response time of the same external interface, the average response time of the feature called by each request, and the total number of calls of the feature; According to the weight of each request, each request is allocated to a subqueue of the same task queue.
10. A computer system comprising: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 8.
11. A computer-readable storage medium having executable instructions stored thereon, which, when executed by a processor, enables the processor to implement the method according to any one of claims 1 to 8.
