Idempotent calling methods, devices and electronic devices

By introducing a time window mechanism on the game server side, the problem of server performance waste caused by multiple idempotent calls was solved, the control of idempotent operations was simplified, and the server load was reduced.

CN116570911BActive Publication Date: 2025-11-14NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310305839.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-21
Publication Date
2025-11-14
Estimated Expiration
2043-03-21

AI Technical Summary

Technical Problem

On the game server side, multiple calls to time-consuming idempotent operations lead to a waste of server performance. Existing technologies control idempotent operations through parameters, which is complex and lengthy, increasing the complexity of judgment.

Method used

A time window mechanism is adopted. After receiving a call request, it is determined whether a time window exists. If it does not exist, a time window is created, and an idempotent call is executed after a specified delay time, and multiple call requests are processed in batches.

Benefits of technology

It simplifies idempotent call operations, avoids multiple calls in a short period of time, reduces server performance consumption, and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116570911B_ABST
    Figure CN116570911B_ABST
Patent Text Reader

Abstract

This invention provides an idempotent invocation method, apparatus, and electronic device. First, it receives a call request for a target idempotent invocation; then, it determines whether a time window corresponding to the target idempotent invocation exists; if no time window exists, it establishes a time window corresponding to the target idempotent invocation. This time window is used to: delay the target idempotent invocation according to a specified delay time; when the time window exists for the same duration as the specified delay time, it closes the time window and executes the function called by the target idempotent invocation. This method opens a time window corresponding to the target idempotent invocation upon the first receipt of the target idempotent invocation. Within this time window, subsequent received target idempotent invocations return directly. Then, when the time window reaches the specified delay time, the function called by the target idempotent invocation is invoked once. This method is simple to operate and avoids executing multiple idempotent invocations in a short period, reducing server performance consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to an idempotent calling method, apparatus, and electronic device. Background Technology

[0002] The game server contains multiple functional modules that call common interfaces, such as player attribute calculations and player information pushes. These interface calls are idempotent, meaning multiple calls return the same result. When a time-consuming idempotent operation is called multiple times within a short period, it wastes server resources. For example, in a player login process, because multiple system logics are involved, idempotent operations may be performed multiple times, resulting in the repeated pushing of the same player attribute data.

[0003] In related technologies, parameters are usually used to control whether a certain idempotent operation is performed in a certain call. However, this method requires a lengthy parameter passing process, and the parameter setting must be considered for each call. After new logic is added, it is also necessary to consider whether there is a need for refactoring, which increases the complexity of determining whether to perform an idempotent operation call. Summary of the Invention

[0004] The purpose of this invention is to provide an idempotent call method, apparatus, and electronic device, so as to reduce the operational complexity of controlling only one idempotent call in a short period of time while avoiding multiple idempotent calls in a short period of time.

[0005] In a first aspect, the present invention provides an idempotent invocation method, the method comprising: receiving an invocation request for a target idempotent invocation; determining whether a time window corresponding to the target idempotent invocation exists; if no time window exists, establishing a time window corresponding to the target idempotent invocation; wherein the time window is used to: delay the target idempotent invocation according to a specified delay time; when the time window exists for the same period as the specified delay time, closing the time window and executing the function called by the target idempotent invocation.

[0006] Secondly, the present invention provides an idempotent invocation apparatus, comprising: a request receiving module for receiving a call request for a target idempotent invocation; a window creation module for determining whether a time window corresponding to the target idempotent invocation exists; and if no time window exists, creating a time window corresponding to the target idempotent invocation; wherein the time window is used to: delay the target idempotent invocation according to a specified delay time; and a function call module for closing the time window and executing the function called by the target idempotent invocation when the time window exists for the same period as the specified delay time.

[0007] Thirdly, the present invention provides an electronic device comprising a processor and a memory, the memory storing machine-executable instructions executable by the processor, the processor executing the machine-executable instructions to implement the above-described idempotent call method.

[0008] Fourthly, the present invention provides a computer-readable storage medium storing computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the aforementioned idempotent invocation method.

[0009] The embodiments of the present invention bring the following beneficial effects:

[0010] This invention provides an idempotent invocation method, apparatus, and electronic device. First, it receives a call request for a target idempotent invocation; then, it determines whether a time window corresponding to the target idempotent invocation exists; if no time window exists, it establishes a time window corresponding to the target idempotent invocation. This time window is used to: delay the target idempotent invocation according to a specified delay time; when the time window exists for the same duration as the specified delay time, it closes the time window and executes the function called by the target idempotent invocation. In this method, upon first receiving a target idempotent invocation, a time window corresponding to the target idempotent invocation is opened. Within this time window, subsequent received target idempotent invocations return directly. Then, when the time window reaches the specified delay time, the function called by the target idempotent invocation is invoked once. This method is simple to operate and avoids executing multiple idempotent invocations in a short period, reducing server performance consumption.

[0011] Other features and advantages of the invention will be set forth in the following description, or some features and advantages may be inferred from the description or determined without doubt, or may be learned by practicing the techniques described above.

[0012] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0013] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0014] Figure 1 A flowchart of an idempotent call method provided in an embodiment of the present invention;

[0015] Figure 2 A flowchart of another idempotent calling method provided in an embodiment of the present invention;

[0016] Figure 3 This is a schematic diagram of the structure of an idempotent calling device provided in an embodiment of the present invention;

[0017] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0019] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0020] The game server contains multiple functional modules that call some common interfaces, such as player attribute calculation and player information push. The results of these interface calls are idempotent, meaning that multiple calls return the same result. For example, pushing player attributes will push the same data multiple times.

[0021] When a time-consuming idempotent operation is called multiple times in a short period of time, it will waste server performance. For example, in a player login process, because multiple system logics are attached, idempotent operations may be performed multiple times, thus repeatedly pushing the same player attribute data.

[0022] In related technologies, parameters are typically used to control whether a certain idempotent operation is performed in a given call, for example:

[0023] login_check:

[0024] check_and_send_sys_1(send_info=false);

[0025] check_and_send_sys_2(send_info=false);

[0026] check_and_send_sys_3(send_info=false);

[0027] check_and_send_sys_4(send_info=true);

[0028] The above method requires manually determining whether to specify an idempotent operation, that is, manually ensuring that `send_info` is only called once within a short period of time (where `send_info` is a boolean value indicating whether information needs to be sent inside the calling function). In the above program, `false` is passed for the first three calls, and `true` is passed for the fourth call, meaning that `send_info` is sent in the fourth call. However, this method requires a lengthy parameter passing process, and the parameter setting must be considered for each call. After adding new logic, it is also necessary to consider whether there is a need for refactoring, thus increasing the complexity of determining whether to execute an idempotent operation call.

[0029] To address the aforementioned issues, embodiments of the present invention provide an idempotent call method, apparatus, and electronic device. This technology can be applied to function call scenarios, particularly idempotent function call scenarios.

[0030] To facilitate understanding of the embodiments of the present invention, a method for idempotent invocation disclosed in the embodiments of the present invention will first be described in detail, such as... Figure 1 As shown, the method includes the following specific steps:

[0031] Step S102: Receive a call request for the target idempotent call.

[0032] In practical implementation, when a user logs in to an account or queries data, the same data may be called multiple times, resulting in multiple idempotent calls. Specifically, a user can request the data corresponding to an idempotent call through a call request. This call request can be sent by the user through a client or by a system logic within a certain processing flow. In practical applications, idempotent calls can be categorized into several types based on whether the called data is the same. Since the data called by the same type of idempotent call is identical, the target idempotent call mentioned above can be any one of the various types of idempotent calls.

[0033] Step S104: Determine if there is a time window corresponding to the target idempotent call; if there is no time window, establish a time window corresponding to the target idempotent call; wherein, the time window is used to: delay the target idempotent call according to the specified delay time.

[0034] In practical implementation, upon receiving a request for an idempotent call, the server first checks if a corresponding time window exists. If it does, no action is taken, and the server waits for the next request. If no time window exists, the server creates one. Essentially, upon receiving the first request for an idempotent call, the server opens the corresponding time window. After this window is opened, subsequent requests for the same idempotent call are returned directly.

[0035] In practical applications, the time window corresponding to the target idempotent call is used to delay the processing of the target idempotent call. This allows the target idempotent call to be processed only after the specified delay time has elapsed within the time window. The specified delay time can be set according to development needs; for example, the specified delay time can be 20 seconds or 1 minute.

[0036] Step S106: When the time window exists for the same period as the specified delay time, close the time window and execute the function called by the target idempotent call.

[0037] When the time window corresponding to the target idempotent call exists on the server for the same duration as the specified delay, the server deletes the time window, then initiates the actual call to the function invoked by the target idempotent call, executes the called function, and returns the result. This method uses a batching mechanism to ensure that the function invoked by the target idempotent call is called only once within the time window corresponding to the target idempotent call. That is, when the time window closes, the function invoked by the target idempotent call is called only once, and there is no logical coupling between multiple callers.

[0038] This invention provides an idempotent invocation method. First, it receives a request for a target idempotent invocation. Then, it determines whether a time window corresponding to the target idempotent invocation exists. If no time window exists, it establishes one, which is used to: delay the target idempotent invocation based on a specified delay time; and when the time window's duration matches the specified delay time, it closes the time window and executes the function called by the target idempotent invocation. In this method, upon first receiving a target idempotent invocation, a time window corresponding to the target idempotent invocation is opened. Within this time window, subsequent received target idempotent invocations return directly. Then, when the time window reaches the specified delay time, the function called by the target idempotent invocation is invoked once. This method is simple to operate and avoids executing multiple idempotent invocations within a short period, reducing server performance consumption.

[0039] This invention also provides another idempotent call method, which is implemented based on the above embodiments. This method focuses on describing the specific process of establishing a time window corresponding to the target idempotent call if no time window exists (implemented through steps S206-S208 below), and the specific process of closing the time window and executing the function called by the target idempotent call when the time window exists for the same duration as the specified delay time (implemented through steps S212-S216 below). Figure 2 As shown, the method includes the following specific steps:

[0040] Step S202: Receive a call request for the target idempotent call.

[0041] In practical applications, before receiving a call request for a target idempotent call, it is necessary to determine the call identification code corresponding to the target idempotent call based on the function name and parameters of the function called by the target idempotent call. The call identification code is used to establish the time window corresponding to the target idempotent call. Specifically, developers need to pre-build the call identification code corresponding to each type of idempotent call through a program, thereby establishing the corresponding time window for the idempotent call using the call identification code.

[0042] In practical implementation, the function name and parameters of the function called by the target idempotent call can be encoded into a string, and this string can be used as the call identifier corresponding to the target idempotent call. For example, the module name, the function name of the function called by the target idempotent call, and the function parameters (including parameter types and values) can be encoded into a string, and this string can be used as the call ID corresponding to the target idempotent call (this call ID is equivalent to the call identifier mentioned above). The code for generating this call ID is shown below:

[0043]

[0044] In this context, `string cFile` represents the module file; `mixed arrParam` represents the call parameters, which include the function name and function parameters; in `sprintf`, `%s_%s|%O"`, `cID`, `type(k)`, and `k` represent the module name, function name, parameter type, and parameter value, respectively. Encoding these parameters and outputting them yields the call identifier `cID`, which is used to identify all information of an idempotent call.

[0045] Step S204: Determine if there is a time window corresponding to the target idempotent call; if not, proceed to step S206; otherwise, proceed to S210.

[0046] When a call request for a target idempotent call is received, the server first checks whether a time window corresponding to the target call function exists. If it does not exist, the server opens the time window corresponding to the target idempotent call using the call identifier corresponding to the target idempotent call. If it exists, the server returns directly and waits to receive the next call request for the target idempotent call and waits for the specified delay time to be reached.

[0047] Step S206: Register the target timer; wherein the target timer is used to set a specified delay time.

[0048] The aforementioned target timer primarily times the duration of the time window on the server; that is, the target timer sets the duration of the time window on the server to a specified delay. In practice, the specified delay time for each idempotent call's corresponding time window can be the same or different, depending on the development requirements.

[0049] Step S208: Using the target timer, a preset recall function is called back and a time window for the call identification code corresponding to the target idempotent call is opened to establish the time window corresponding to the target idempotent call; wherein, the recall function is used to: find the function called by the target idempotent call when the target timer reaches the specified delay time; execute step S212.

[0050] In practical implementation, the specific function used for the recall can be determined based on the programming language used. Specifically, when the server receives a call request corresponding to the target idempotent call, it will use the following code to determine if a time window for the target idempotent call exists, and if no time window exists, it will create a time window:

[0051]

[0052]

[0053] Here, mpCallCache[cID] represents the time window corresponding to the target idempotent call, which can also be called the time window corresponding to the call identifier of the target idempotent call; cID represents the call identifier corresponding to the target idempotent call; register_timer represents the target timer; __FILE__ represents the module; real_call represents the recall function; and iDelay represents the specified delay time. CMN_TIMER represents one way to implement the time window. This method first registers a timer, which calls back the real_call function in the __FILE__ module. The timer is triggered after the iDelay time. After triggering, real_call is called with cID as the parameter to find the function called by the idempotent call through the real-call function, and then the called function is specified to obtain the call data.

[0054] In step S210, the process returns directly without any further processing.

[0055] In the actual implementation, it is necessary to first determine whether the current call corresponds to an existing time window. If it does, then exit directly.

[0056] Step S212: If the time of the time window is the same as the specified delay time, check if the time window corresponding to the target idempotent call exists; if it exists, execute step S214; otherwise, execute step S216.

[0057] Step S214: Close the aforementioned time window, invoke the function called by the target idempotent call through the recall function, execute the function, and obtain the execution result.

[0058] Step S216: Return directly.

[0059] In practical implementation, the function invoked by the target idempotent call is the function corresponding to the call identifier of the target idempotent call. In other words, the corresponding function can be found through the function name in the call identifier, and the function is executed by calling the function parameters in the identifier to obtain the execution result. Specifically, this can be achieved by the following program: when the time function corresponding to the target idempotent call ends, the function invoked by the target idempotent call is called:

[0060]

[0061] Specifically, at the end of the time window (i.e., when the time window reaches the specified delay time), the recall function `real_call` actually calls the function corresponding to the call identifier `cID` of the target idempotent call (i.e., the function called by the target idempotent call). Specifically, at the end of the time window, the server attempts to check if the time window corresponding to the target idempotent call exists; if it does not exist, it returns directly (if it does not exist, it indicates a vulnerability in the program, which the programmer needs to fix); if it exists, the time window is deleted from the server using `map_delete(mpCallCache,cID)`, and then the actual call is initiated using `call_other(arrWrap[0],arrWrap[1..<1])`, which is the call to the function called by the target idempotent call.

[0062] In practical applications, calculating all player attributes is a time-consuming operation, and this calculation is triggered multiple times during the login process. After applying this invention, the number of player attribute calculations is reduced to once within a specified delay time, thereby reducing server-side performance overhead.

[0063] The aforementioned idempotent call method uses a batching mechanism, which calls a specific idempotent call only once within a specified time window, and there is no logical coupling between multiple callers. This reduces the performance overhead of the server for idempotent calls, improves the server's performance, and also ensures the processing speed of other tasks on the server.

[0064] In addition to the above-described method embodiments, this invention also provides an idempotent calling device, such as... Figure 3 As shown, the device includes:

[0065] The request receiving module 30 is used to receive call requests for the target idempotent call.

[0066] The window creation module 31 is used to determine whether there is a time window corresponding to the target idempotent call; if there is no time window, a time window corresponding to the target idempotent call is created; wherein, the time window is used to: delay the target idempotent call according to the specified delay time.

[0067] Function call module 32 is used to close the time window and execute the function called by the target idempotent call when the time window exists for the same period as the specified delay time.

[0068] The aforementioned idempotent invocation mechanism first receives a request for a target idempotent invocation; then it determines whether a time window corresponding to the target idempotent invocation exists; if no time window exists, it establishes a time window for the target idempotent invocation. This time window is used to: delay the target idempotent invocation based on a specified delay time; when the time window exists for the same duration as the specified delay time, the time window is closed, and the function called by the target idempotent invocation is executed. In this method, upon first receiving a target idempotent invocation, a time window corresponding to the target idempotent invocation is opened. Within this time window, subsequent received target idempotent invocations return directly. Then, when the time window reaches the specified delay time, the function called by the target idempotent invocation is invoked once. This method is simple to operate and avoids executing multiple idempotent invocations in a short period of time, reducing server performance consumption.

[0069] Specifically, the aforementioned window creation module 31 is also used to: if there is a time window corresponding to the target idempotent call, return directly without any processing.

[0070] In a specific implementation, the above device further includes an identification code determination module, which is used to: determine the call identification code corresponding to the target idempotent call based on the function name and function parameters of the function called by the target idempotent call before receiving the call request for the target idempotent call; wherein, the call identification code is used to establish the time window corresponding to the target idempotent call.

[0071] Furthermore, the aforementioned identification code determination module is also used to: encode the function name and function parameters of the function called by the target idempotent call to obtain a string, and determine the string as the call identification code corresponding to the target idempotent call.

[0072] In practical applications, the aforementioned window creation module 31 is also used to: register a target timer if no time window exists; wherein the target timer is used to set a specified delay time; using the target timer, a preset recall function is called back and a time window for the call identification code corresponding to the target idempotent call is opened to establish the time window corresponding to the target idempotent call; wherein the recall function is used to: find the function called by the target idempotent call when the target timer reaches the specified delay time.

[0073] Furthermore, the function call module 32 described above is also used to: query whether the time window exists when the time of the time window is the same as the specified delay time; if the time window exists, close the time window, call the function called by the target idempotent call through the recall function, execute the function, and obtain the execution result. If the time window does not exist, return directly.

[0074] The idempotent calling device provided in this embodiment of the invention has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment.

[0075] This invention also provides an electronic device, such as... Figure 4 As shown, the electronic device includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, which executes the machine-executable instructions to implement the idempotent call method described above.

[0076] Specifically, the above-mentioned idempotent invocation method includes: receiving a call request for a target idempotent invocation; determining whether a time window corresponding to the target idempotent invocation exists; if no time window exists, establishing a time window corresponding to the target idempotent invocation; wherein the time window is used to: delay the target idempotent invocation according to a specified delay time; when the time window exists for the same period as the specified delay time, closing the time window and executing the function called by the target idempotent invocation.

[0077] In the above idempotent invocation method, when the target idempotent invocation is received for the first time, a time window corresponding to the target idempotent invocation is opened. Within this time window, subsequent target idempotent invocations are returned directly. Then, when the time window reaches the specified delay time, the function called by the target idempotent invocation is invoked once. This method is simple to operate and can avoid executing multiple idempotent invocations in a short period of time, thus reducing the performance consumption of the server.

[0078] In an optional embodiment, the method further includes: if there is a time window corresponding to the target idempotent call, then return directly without any processing.

[0079] In an optional embodiment, before the step of receiving the call request for the target idempotent call, the method further includes: determining the call identification code corresponding to the target idempotent call based on the function name and function parameters of the function called by the target idempotent call; wherein the call identification code is used to establish a time window corresponding to the target idempotent call.

[0080] In an optional embodiment, the step of determining the call identification code corresponding to the target idempotent call based on the function name and function parameters of the function called by the target idempotent call includes: encoding the function name and function parameters of the function called by the target idempotent call to obtain a string, and determining the string as the call identification code corresponding to the target idempotent call.

[0081] In an optional embodiment, if no time window exists, the step of establishing a time window corresponding to the target idempotent call includes: if no time window exists, registering a target timer; wherein the target timer is used to set a specified delay time; using the target timer, calling back a preset recall function and opening a time window for the call identification code corresponding to the target idempotent call to establish a time window corresponding to the target idempotent call; wherein the recall function is used to: when the target timer reaches the specified delay time, find the function called by the target idempotent call.

[0082] In an optional embodiment, the steps of closing the time window and executing the function called by the target idempotent call when the time window exists is the same as the specified delay time include: querying whether the time window exists when the time window exists is the same as the specified delay time; if the time window exists, closing the time window, calling the function called by the target idempotent call through the recall function, executing the function, and obtaining the execution result; if the time window does not exist, returning directly.

[0083] Furthermore, Figure 4 The electronic device shown also includes a bus 102 and a communication interface 103, with the processor 101, the communication interface 103 and the memory 100 connected via the bus 102.

[0084] The memory 100 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 103 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network. The bus 102 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 4 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.

[0085] Processor 101 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 101 or by instructions in software form. Processor 101 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 100, and processor 101 reads information from memory 100 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.

[0086] This invention also provides a computer-readable storage medium storing computer-executable instructions. When these computer-executable instructions are invoked and executed by a processor, they cause the processor to implement the aforementioned idempotent invocation method. For specific implementation details, please refer to the method embodiments, which will not be repeated here.

[0087] Specifically, the above-mentioned idempotent invocation method includes: receiving a call request for a target idempotent invocation; determining whether a time window corresponding to the target idempotent invocation exists; if no time window exists, establishing a time window corresponding to the target idempotent invocation; wherein the time window is used to: delay the target idempotent invocation according to a specified delay time; when the time window exists for the same period as the specified delay time, closing the time window and executing the function called by the target idempotent invocation.

[0088] In the above idempotent invocation method, when the target idempotent invocation is received for the first time, a time window corresponding to the target idempotent invocation is opened. Within this time window, subsequent target idempotent invocations are returned directly. Then, when the time window reaches the specified delay time, the function called by the target idempotent invocation is invoked once. This method is simple to operate and can avoid executing multiple idempotent invocations in a short period of time, thus reducing the performance consumption of the server.

[0089] In an optional embodiment, the method further includes: if there is a time window corresponding to the target idempotent call, then return directly without any processing.

[0090] In an optional embodiment, before the step of receiving the call request for the target idempotent call, the method further includes: determining the call identification code corresponding to the target idempotent call based on the function name and function parameters of the function called by the target idempotent call; wherein the call identification code is used to establish a time window corresponding to the target idempotent call.

[0091] In an optional embodiment, the step of determining the call identification code corresponding to the target idempotent call based on the function name and function parameters of the function called by the target idempotent call includes: encoding the function name and function parameters of the function called by the target idempotent call to obtain a string, and determining the string as the call identification code corresponding to the target idempotent call.

[0092] In an optional embodiment, if no time window exists, the step of establishing a time window corresponding to the target idempotent call includes: if no time window exists, registering a target timer; wherein the target timer is used to set a specified delay time; using the target timer, calling back a preset recall function and opening a time window for the call identification code corresponding to the target idempotent call to establish a time window corresponding to the target idempotent call; wherein the recall function is used to: when the target timer reaches the specified delay time, find the function called by the target idempotent call.

[0093] In an optional embodiment, the steps of closing the time window and executing the function called by the target idempotent call when the time window exists is the same as the specified delay time include: querying whether the time window exists when the time window exists is the same as the specified delay time; if the time window exists, closing the time window, calling the function called by the target idempotent call through the recall function, executing the function, and obtaining the execution result; if the time window does not exist, returning directly.

[0094] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal device, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0095] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0096] Finally, it should be noted that the above-described embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. An idempotent calling method, characterized in that, The method includes: Receive invocation requests for an idempotent invocation of the target; Determine whether a time window exists corresponding to the target idempotent call; if the time window does not exist, establish a time window corresponding to the target idempotent call; wherein, the time window is used to: delay the target idempotent call according to a specified delay time; When the time window exists for the same duration as the specified delay time, the time window is closed, and the function called by the target idempotent call is executed.

2. The method according to claim 1, characterized in that, The method further includes: If a time window corresponding to the target idempotent call exists, return directly without any further processing.

3. The method according to claim 1, characterized in that, Before the step of receiving the invocation request for the target idempotent invocation, the method further includes: Based on the function name and function parameters of the function called by the target idempotent call, a call identification code corresponding to the target idempotent call is determined; wherein, the call identification code is used to establish a time window corresponding to the target idempotent call.

4. The method according to claim 3, characterized in that, The step of determining the call identification code corresponding to the target idempotent call based on the function name and function parameters of the function called by the target idempotent call includes: The function name and function parameters of the function called by the target idempotent call are encoded to obtain a string, and the string is determined as the call identification code corresponding to the target idempotent call.

5. The method according to claim 3, characterized in that, The step of establishing a time window corresponding to the target idempotent call if the time window does not exist includes: If the time window does not exist, register a target timer; wherein the target timer is used to set the specified delay time; Using the target timer, a preset recall function is called back and a time window for the call identification code corresponding to the target idempotent call is opened to establish the time window corresponding to the target idempotent call; wherein, the recall function is used to: when the target timer reaches the specified delay time, find the function called by the target idempotent call.

6. The method according to claim 5, characterized in that, The step of closing the time window and executing the function called by the target idempotent call when the time window exists for the same period as the specified delay time includes: If the time window exists for the same duration as the specified delay time, check if the time window exists. If the time window exists, close the time window, call the function called by the target idempotent call through the recall function, execute the function, and obtain the execution result.

7. The method according to claim 6, characterized in that, The method further includes: If the specified time window does not exist, return directly.

8. An idempotent calling device, characterized in that, The device includes: The request receiving module is used to receive call requests for the target idempotent call; A window creation module is used to determine whether a time window corresponding to the target idempotent call exists; if the time window does not exist, a time window corresponding to the target idempotent call is created; wherein, the time window is used to: delay the target idempotent call according to a specified delay time; The function call module is used to close the time window and execute the function called by the target idempotent call when the time window exists for the same period as the specified delay time.

9. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the idempotent call method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions that, when invoked and executed by a processor, cause the processor to implement the idempotent invocation method of any one of claims 1 to 7.

Citation Information

Patent Citations

  • Optimization method for idempotent operation in asynchronous frame

    CN107436767A

  • Exponentiation processing method, device and equipment and storage medium

    CN111625301A