Lua script blocking optimization method and device, electronic equipment and readable medium

By loading lua scripts in Redis and adjusting the execution strategy based on its average execution time, the client reconnection and application interruption caused by lua script execution blocking is solved, and the performance and availability of the system are improved.

CN119829129AActive Publication Date: 2025-04-15CHINA TELECOM CLOUD TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411725903.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-28
Publication Date
2025-04-15
Estimated Expiration
2044-11-28

AI Technical Summary

Technical Problem

In high concurrency scenarios, Redis blocks due to execution of lua scripts, rejects other requests, and causes chain reactions, causing the client to reconnect continuously and the application interruption.

Method used

By loading the lua script into the cache, each time the lua script is executed, the average execution time is obtained. If the preset threshold is exceeded, the flag bit is set, and only the read instructions are executed, the instruction execution result is obtained, and the flag bit is canceled after the script is executed.

Benefits of technology

In the scenario where the execution time of lua scripts is too long, the sensitivity of the open instruction is adjusted by preset thresholds, which avoids the problem of continuous reconnection and application terminals, and improves the performance and resource reuse of Redis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829129A_ABST
    Figure CN119829129A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a lua script blocking optimization method and device, electronic equipment and a readable medium. The lua script blocking optimization method comprises the steps that a lua script is loaded to a cache; when the lua script is executed every time, the following steps are executed: obtaining the average execution time of the lua script; if the average execution time is greater than a preset threshold value, setting a flag bit; executing a read instruction in the lua script to obtain an instruction execution result; if it is determined that the lua script is executed according to the instruction execution result, the flag bit is canceled. According to the method, when the lua script is executed every time, if the average execution time of the lua script is larger than the preset threshold value, the lua script only executes the read instruction through the flag bit, the instruction execution result is obtained, in the scene that the execution time of the lua script is too long, the instruction opening sensitivity is adjusted through the preset threshold value, and the problems of continuous reconnection and terminal application are avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of middleware, and in particular to a method for optimizing Lua script blocking, a device for optimizing Lua script blocking, an electronic device and a computer-readable medium. Background Art

[0002] Redis is a single-threaded-multiplexed IO model. Executing Lua will block all cache information in the entire Redis instance, that is, other instructions cannot be responded to while Lua is executing. If the blocking execution time is too long, it will have a negative impact on Redis's performance and resource reuse.

[0003] Especially in high-concurrency scenarios, if Lua is not configured properly on the application side, Redis will reject other requests during the blocking period, which will cause a chain reaction, causing the client to constantly reconnect and the application to be interrupted. Summary of the invention

[0004] The embodiment of the present invention provides a Lua script blocking optimization method, device, electronic device and readable medium to solve the problem of continuous reconnection and application interruption during script execution blocking.

[0005] The embodiment of the present invention discloses a method for optimizing Lua script blocking, comprising:

[0006] Load the lua script into the cache;

[0007] Each time a Lua script is executed, the following steps are performed:

[0008] Get the average execution time of the Lua script;

[0009] If the average execution time is greater than the preset threshold, the flag is set;

[0010] Execute the read instruction in the Lua script to get the instruction execution result;

[0011] If the Lua script is determined to be completed according to the command execution result, the flag is canceled.

[0012] Optionally, before executing the read instruction in the Lua script and obtaining the instruction execution result, the following steps are also included:

[0013] Determine the type of each instruction in the Lua script, where the type is read or non-read;

[0014] A command of the read type is determined as a read command.

[0015] Optionally, execute the read instruction in the lua script to obtain the instruction execution result, including:

[0016] Get the slave node;

[0017] If the slave node is successfully obtained, the read instruction in the lua script is forwarded to the slave node, so that the slave node executes the read instruction, and the execution result of the slave node is determined as the instruction execution result.

[0018] Optionally, after obtaining the slave node, the following is also included:

[0019] If the acquisition from the node fails, the execution of the read instruction in the Lua script is terminated, and the instruction execution result of the script execution blocking is obtained, and the blocking description is busy.

[0020] Optionally, after determining the type of each instruction in the Lua script, it also includes:

[0021] Terminate the execution of non-read instructions in the Lua script, obtain the execution result of the instruction that blocked the script execution, and the blocking description is read-only.

[0022] Optionally, after determining that the Lua script is executed completely according to the instruction execution result, the method further includes:

[0023] Determine the execution time of the Lua script;

[0024] The average execution time of the updated Lua script is (average execution time of the Lua script * historical execution times of the Lua script + current execution time) / (historical execution times of the Lua script + 1).

[0025] Optionally, if it is determined that the script execution is blocked according to the instruction execution result, a disconnection and reconnection operation is triggered.

[0026] The embodiment of the present invention also discloses a Lua script blocking optimization device, comprising:

[0027] Loading module, used to load Lua script into cache;

[0028] The execution module is used to obtain the average execution time of the Lua script each time the Lua script is executed; if the average execution time is greater than a preset threshold, a flag is set; the read instruction in the Lua script is executed to obtain the instruction execution result; if it is determined according to the instruction execution result that the Lua script has been executed this time, the flag is canceled.

[0029] The embodiment of the present invention further discloses an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;

[0030] The memory is used to store computer programs;

[0031] The processor is used to implement the method described in the embodiment of the present invention when executing the program stored in the memory.

[0032] The embodiment of the present invention further discloses one or more computer-readable media on which instructions are stored. When executed by one or more processors, the processors are enabled to execute the method described in the embodiment of the present invention.

[0033] The embodiments of the present invention include the following advantages:

[0034] Load the Lua script into the cache; each time the Lua script is executed, the following steps are performed: Get the average execution time of the Lua script; If the average execution time is greater than the preset threshold, set the flag; Execute the read instruction in the Lua script to obtain the instruction execution result; If it is determined based on the instruction execution result that the Lua script has been executed this time, cancel the flag. Each time the Lua script is executed, if the average execution time of the Lua script is greater than the preset threshold, the Lua script is only executed to read the instruction and obtain the instruction execution result. In the scenario where the Lua script execution time is too long, the sensitivity of the instruction opening is adjusted by the preset threshold to avoid the problem of continuous reconnection and application terminal. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 It is a step flow chart of a Lua script blocking optimization method provided in an embodiment of the present invention;

[0036] Figure 2 It is a flowchart of a method for executing instructions when Lua script execution is blocked, provided in an embodiment of the present invention;

[0037] Figure 3 It is a flowchart of another method for executing instructions when Lua script execution is blocked provided in an embodiment of the present invention;

[0038] Figure 4 It is a step flow chart of another Lua script blocking optimization method provided in an embodiment of the present invention;

[0039] Figure 5 It is a structural block diagram of a Lua script blocking optimization device provided in an embodiment of the present invention;

[0040] Figure 6 is a block diagram of an electronic device provided in an embodiment of the present invention;

[0041] Figure 7 is a schematic diagram of a computer-readable medium provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0042] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0043] In the process of implementing the present invention, the inventors found that:

[0044] Redis (Remote Dictionary Server) is a high-performance, in-memory open source database that stores data in the form of key-value pairs and supports multiple data structures. Redis is often used for caching, session management, message queues and other applications. In Redis, Lua scripts are often used to perform a series of operations, such as reading and writing data, and performing complex logical operations. Redis Lua scripts parse Lua scripts into executable instructions so that the Redis server can execute these scripts.

[0045] Since Redis is a single-threaded-multiplexed IO model, executing Lua will block all cache information in the entire Redis instance, that is, other instructions cannot be responded to while Lua is executing. If the blocking execution time is too long, it will have a negative impact on Redis's performance and resource reuse.

[0046] Especially in high-concurrency scenarios, if Lua is not configured properly on the application side, Redis will reject other requests during the blocking period, which will cause a chain reaction, causing the client to constantly reconnect and the application to be interrupted.

[0047] For example, during the execution blocking period, the cache high availability module cannot respond normally when performing the ping operation, which will cause the high availability module to mistakenly believe that there is an abnormality in the redis service node, triggering the master-slave switching operation, which will have a negative impact on the business application.

[0048] The embodiment of the present invention provides a method, device, electronic device and readable medium for optimizing the blocking of a Lua script. The method loads a Lua script into a cache; each time a Lua script is executed, the following steps are performed: obtaining the average execution time of the Lua script; if the average execution time is greater than a preset threshold, a flag is set; a read instruction in the Lua script is executed to obtain an instruction execution result; if the Lua script is determined to be executed this time according to the instruction execution result, the flag is canceled. When the method of the present invention executes a Lua script each time, if the average execution time of the Lua script is greater than a preset threshold, the Lua script is made to execute only the read instruction through the flag to obtain the instruction execution result. In the scenario where the Lua script execution time is too long, the sensitivity of the instruction opening is adjusted through the preset threshold, thereby avoiding the problem of continuous reconnection and application terminal.

[0049] Reference Figure 1, shows a flow chart of the steps of a Lua script blocking optimization method provided in an embodiment of the present invention, which may specifically include the following steps:

[0050] 101, load the Lua script into the cache.

[0051] After the lua script is loaded into the cache, a SHA-1 hash value will be generated for the lua script as the key, and the lua script content will be used as the value. During subsequent execution, the corresponding value can be found through the key, and the lua script in the value can be executed.

[0052] 102, each time the Lua script is executed, the following steps 201 to 204 are executed:

[0053] 201, get the average execution time of the Lua script.

[0054] The average execution time of the Lua script is updated after each execution of the Lua script. This step directly obtains the current average execution time.

[0055] 202, if the average execution time is greater than a preset threshold, a flag is set.

[0056] When the average script execution time is less than the preset threshold, it means that the execution time is controllable and will not cause overall service congestion, so no intervention is required.

[0057] When the average time exceeds the threshold, it means that there is a risk of blocking the script execution, resulting in reduced overall availability. The read request forwarding process should be triggered to improve availability.

[0058] Among them, the threshold can be configured through the configuration item, such as adding the following content in the configuration item: parameter 1 parameter 2 parameter 3.

[0059] Parameter 1 indicates whether to use the optimization method for blocking Lua scripts provided in this embodiment to process when the Lua script is executed, parameter 2 indicates whether to set a flag, and parameter 3 indicates a threshold.

[0060] For example, before executing the optimization method for blocking Lua scripts provided in this embodiment, if the newly added content in the configuration item is script-analysis-disable no NULL, where parameter 1 is script-analysis-disable, parameter 2 is no, and parameter 3 is NULL (i.e., a null value), it means that the Lua script is not executed using the optimization method for blocking Lua scripts provided in this embodiment.

[0061] For example, before executing the Lua script blocking optimization method provided in this embodiment, if the newly added content in the configuration item is script-analysis-enable no 10, wherein parameter 1 is script-analysis-enable, parameter 2 is no, and parameter 3 is 10. This indicates that the Lua script is executed using the Lua script blocking optimization method provided in this embodiment, and the threshold is 10 milliseconds, and the flag bit is not set at this time.

[0062] If in step 202, it is determined that the average execution time is greater than 10 milliseconds, then modify parameter 2 of the configuration item to yes to implement the setting of the flag. After the modification, the newly added content in the configuration item becomes script-analysis-enable yes 10, where parameter 1 is script-analysis-enable, parameter 2 is no, and parameter 3 is 10. Wherein, parameter 1 is script-analysis-enable, parameter 2 is yes, and parameter 3 is 10. It indicates that the Lua script is executed using the optimization method for Lua script blocking provided in this embodiment, and the flag is set, and the threshold is 10 milliseconds.

[0063] Since the flag is set when executing step 102, as long as the flag is set, it indicates that the Lua script is being executed.

[0064] 203, execute the read instruction in the Lua script to obtain the instruction execution result. Terminate the execution of the non-read instruction in the Lua script to obtain the instruction execution result of the script execution blocking, and the blocking description is read-only.

[0065] In step 203 , the read instruction in the Lua script is processed, and other instructions are not executed. Therefore, before executing step 203 , the read instruction in the Lua script is determined.

[0066] The determination process of the read instruction in the lua script is as follows:

[0067] 1. Determine the type of each instruction in the Lua script, where the type is read or non-read.

[0068] 2. Determine the read type instruction as a read instruction.

[0069] For example, the instructions in the Lua script are classified into one category, and the read instructions are classified into one category, and the non-read instructions (such as write instructions) are classified into another category.

[0070] In step 203, only read instructions are executed, and non-read instructions are not executed.

[0071] The execution process of the read instruction in step 203 is:

[0072] 1. Get the slave node.

[0073] 2. If the slave node is successfully obtained, the read instruction in the lua script is forwarded to the slave node, so that the slave node executes the read instruction, and the execution result of the slave node is determined as the instruction execution result.

[0074] 3. If the acquisition from the node fails, the read instruction in the Lua script is terminated, and the instruction execution result of the script execution blocking is obtained, and the blocking description is busy.

[0075] For example, the command execution result is: busy, script execution is blocked.

[0076] That is, when executing step 203 , if all the instructions in the Lua script are read instructions, all the read instructions will be executed by the slave node, and the execution result of the read instruction will be used as the instruction execution result obtained by executing the read instruction in the Lua script in step 203 .

[0077] If all the instructions in the Lua script are non-read instructions, the execution of all non-read instructions is terminated, and the execution result of the instruction that blocked the script execution is obtained, and the blocking description is read-only.

[0078] For example, the command execution result is: read-only, script execution is blocked.

[0079] If some instructions in the Lua script are read instructions and some are non-read instructions, then Figure 2 As shown, by executing the read instruction in the Lua script from the node, the instruction execution result is obtained, the execution of the non-read instruction in the Lua script is terminated, and the instruction execution result of the script execution blocking is obtained, and the blocking description is read-only.

[0080] The slave node is obtained by executing the read instruction process in the Lua script from the slave node, and the read instruction in the Lua script is forwarded to the slave node, so that the slave node executes the read instruction, and the execution result of the slave node is determined as the instruction execution result.

[0081] In the specific implementation, in order to ensure that step 203 is executed in the execution blocking period, before executing step 203, it is also possible to confirm again whether Lua script blocking occurs, that is, to confirm again that the average execution time is greater than the preset threshold and the flag is set.

[0082] If the average execution time is greater than the preset threshold and the flag is set, it is confirmed that the Lua script is blocked and step 203 is executed. Otherwise, it is considered that the Lua script is not blocked and step 203 is no longer executed. Instead, the existing Lua script instruction execution scheme is executed (i.e., local execution instructions are executed), such as Figure 3 shown.

[0083] In step 203, only read instructions are allowed to be executed, and the read-only request is responded to by forwarding to the slave node. For write instructions, an error prompt is quickly returned. Since the write request is still rejected / blocked, except for the data involved in the script, there is no master-slave data consistency problem in theory for read-only requests, and the data accuracy can be trusted.

[0084] 204. If it is determined according to the command execution result that the Lua script has been executed this time, the flag is cancelled.

[0085] If parameter 2 of the configuration item is modified to no, the flag is canceled. After modification, the new content in the configuration item becomes script-analysis-enable no 10, where parameter 1 is script-analysis-enable, parameter 2 is no, and parameter 3 is 10. This indicates that the Lua script is executed using the optimization method for Lua script blocking provided in this embodiment, and the threshold is 10 milliseconds. At this time, the flag is not set (i.e., the flag is canceled).

[0086] Cancel the flag bit to complete the execution of the Lua script.

[0087] In addition, after the Lua script is completed according to the command execution result, the average execution time of the Lua script will be updated. The update process is:

[0088] 1. Determine the execution time of the lua script.

[0089] If this is the i-th execution of the Lua script, then the i-th execution time T of the Lua script will be determined i .

[0090] 2. Update the average execution time of the Lua script to (average execution time of the Lua script * historical execution times of the Lua script + current execution time) / (historical execution times of the Lua script + 1).

[0091] The historical execution times of the Lua script do not include the current completed execution, that is, the historical execution times of the Lua script is i-1.

[0092] That is to say, based on the average execution time of all i-1 executions after the previous i-1 executions of the Lua script and the i-th execution time of the Lua script, the average execution time of all i executions after the previous i executions of the Lua script is obtained, and the average execution time of all i executions is the average execution time of the updated Lua script.

[0093] If the average execution time of the Lua script is Then the update process is:

[0094] In addition, if the script execution is determined to be blocked based on the instruction execution result, the application side can implement mechanisms such as retries to prevent the application from waiting for a long time and timing out, thereby triggering a disconnection and reconnection operation.

[0095] The Lua script blocking optimization method provided in this embodiment can be used for scenarios where the execution time of complex Lua scripts is too long. During the Lua script blocking stage, service detection requests and read instructions are allowed to improve the overall service availability. At the same time, the average execution time of the Lua script is counted and recorded, and the instruction opening sensitivity is adjusted according to the preset threshold. The service availability is improved during the blocking stage and various problems caused by service blocking can be avoided. For example, high availability judgment errors caused by service blocking and application timeout reconnection problems can be avoided.

[0096] The optimization method for blocking Lua scripts provided in this embodiment can make the judgment of high-availability modules more accurate and avoid incorrect master-slave switching. In the existing Lua script execution scheme, if the Lua script execution time is very long, the ping request will also be blocked and unresponsive during this period, which may cause the high-availability module to think that the service is unavailable, and then trigger the master-slave switching logic. The optimization method for blocking Lua scripts provided in this embodiment can ensure that ping can still respond normally during the execution of the Lua script, avoiding misjudgment.

[0097] The optimization method for Lua script blocking provided in this embodiment adds a new function configuration switch, counts the average script execution time, and adjusts the instruction opening sensitivity according to the configuration threshold, making the adaptation more flexible.

[0098] The optimization method for Lua script blocking provided in this embodiment allows read-only instructions to be passed during the Lua script execution blocking period, and transfers them to the slave node for execution and processing. In addition, a busy error can be quickly returned through the instruction execution result, avoiding the application end from waiting for a long time and triggering high-availability logic.

[0099] The optimization method for Lua script blocking provided in this embodiment can achieve compatibility with the existing Lua script execution solution. Figure 4 shown.

[0100] After the Lua script is executed, the Lua script is loaded into the cache through step 101.

[0101] Then determine whether parameter 1 is script-analysis-enable.

[0102] If parameter 1 is not script-analysis-enable (such as script-analysis-disable), the existing Lua script execution solution is used to execute the Lua script.

[0103] If parameter 1 is script-analysis-enable, the Lua script is executed through step 102 (ie, the Lua script is executed using the Lua script blocking optimization method provided in this embodiment).

[0104] For example, in step 201 , the average execution time of the Lua script is obtained.

[0105] Through step 202, when the average execution time is greater than a preset threshold, a flag is set.

[0106] Through step 203, the read instruction in the Lua script is executed to obtain the instruction execution result. The non-read instruction in the Lua script is terminated to obtain the instruction execution result of the script execution blocking, and the blocking description is read-only.

[0107] Through step 204, after it is determined according to the instruction execution result that the Lua script has been executed this time, the flag is cancelled.

[0108] Regardless of the method used to execute the Lua script, the average execution time of the Lua script will be updated after each execution of the Lua script.

[0109] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

[0110] This embodiment provides an optimization method for Lua script blocking, which loads the Lua script into a cache; each time the Lua script is executed, the following steps are performed: obtaining the average execution time of the Lua script; if the average execution time is greater than a preset threshold, setting a flag; executing a read instruction in the Lua script to obtain an instruction execution result; if it is determined according to the instruction execution result that the Lua script has been executed this time, canceling the flag.

[0111] This method uses a flag to make the Lua script execute only read instructions to obtain the instruction execution result each time the Lua script is executed. In the scenario where the Lua script execution time is too long, the sensitivity of the instruction opening is adjusted by the preset threshold to avoid the problem of continuous reconnection and application terminal.

[0112] Reference Figure 5 , shows a structural block diagram of a Lua script blocking optimization device provided in an embodiment of the present invention, which may specifically include the following modules:

[0113] The loading module 501 is used to load the Lua script into the cache.

[0114] The execution module 502 is used to execute the following steps each time the Lua script is executed:

[0115] Get the average execution time of the Lua script.

[0116] If the average execution time is greater than the preset threshold, the flag is set.

[0117] Execute the read instruction in the Lua script to get the instruction execution result.

[0118] If the Lua script is determined to be completed according to the command execution result, the flag is canceled.

[0119] Wherein, before executing the read instruction in the Lua script and obtaining the instruction execution result, the method further includes: determining the type of each instruction in the Lua script, wherein the type is read or non-read.

[0120] A command of the read type is determined as a read command.

[0121] Among them, the read instruction in the lua script is executed to obtain the instruction execution result, including:

[0122] Get the slave node.

[0123] If the slave node is successfully obtained, the read instruction in the lua script is forwarded to the slave node, so that the slave node executes the read instruction, and the execution result of the slave node is determined as the instruction execution result.

[0124] After obtaining the slave node, the following steps are also included:

[0125] If the acquisition from the node fails, the execution of the read instruction in the Lua script is terminated, and the instruction execution result of the script execution blocking is obtained, and the blocking description is busy.

[0126] Among them, after determining the type of each instruction in the Lua script, it also includes:

[0127] Terminate the execution of non-read instructions in the Lua script, obtain the execution result of the instruction that blocked the script execution, and the blocking description is read-only.

[0128] Among them, after determining that the Lua script is executed this time according to the instruction execution result, it also includes:

[0129] Determine the current execution time of the Lua script.

[0130] The average execution time of the updated Lua script is (average execution time of the Lua script * historical execution times of the Lua script + current execution time) / (historical execution times of the Lua script + 1).

[0131] If the script execution is blocked according to the instruction execution result, a disconnection and reconnection operation is triggered.

[0132] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0133] The device provided in this embodiment, when executing a Lua script each time, if the average execution time of the Lua script is greater than a preset threshold, the Lua script is enabled to execute only read instructions through a flag to obtain the instruction execution result. In the scenario where the Lua script execution time is too long, the sensitivity of the instruction opening is adjusted through the preset threshold to avoid the problem of continuous reconnection and application terminal.

[0134] In addition, an embodiment of the present invention further provides an electronic device, such as Figure 6 As shown, it includes a processor 601, a communication interface 602, a memory 603 and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604.

[0135] Memory 603, used for storing computer programs;

[0136] The processor 601 is used to execute the program stored in the memory 603 to implement the following steps:

[0137] Load the lua script into the cache.

[0138] Each time a Lua script is executed, the following steps are performed:

[0139] Get the average execution time of the Lua script.

[0140] If the average execution time is greater than the preset threshold, the flag is set.

[0141] Execute the read instruction in the Lua script to get the instruction execution result.

[0142] If the Lua script is determined to be completed according to the command execution result, the flag is canceled.

[0143] Optionally, before executing the read instruction in the Lua script and obtaining the instruction execution result, the following steps are also included:

[0144] Determine the type of each instruction in the Lua script, where the type is read or non-read.

[0145] A command of the read type is determined as a read command.

[0146] Optionally, execute the read instruction in the lua script to obtain the instruction execution result, including:

[0147] Get the slave node.

[0148] If the slave node is successfully obtained, the read instruction in the lua script is forwarded to the slave node, so that the slave node executes the read instruction, and the execution result of the slave node is determined as the instruction execution result.

[0149] Optionally, after obtaining the slave node, the following is also included:

[0150] If the acquisition from the node fails, the execution of the read instruction in the Lua script is terminated, and the instruction execution result of the script execution blocking is obtained, and the blocking description is busy.

[0151] Optionally, after determining the type of each instruction in the Lua script, it also includes:

[0152] Terminate the execution of non-read instructions in the Lua script, obtain the execution result of the instruction that blocked the script execution, and the blocking description is read-only.

[0153] Optionally, after determining that the Lua script is executed completely according to the instruction execution result, the method further includes:

[0154] Determine the current execution time of the Lua script.

[0155] The average execution time of the updated Lua script is (average execution time of the Lua script * historical execution times of the Lua script + current execution time) / (historical execution times of the Lua script + 1).

[0156] Optionally, if it is determined that the script execution is blocked according to the instruction execution result, a disconnection and reconnection operation is triggered.

[0157] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0158] The communication interface is used for communication between the above terminal and other devices.

[0159] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0160] The above-mentioned processor 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, discrete hardware components.

[0161] The electronic device provided in this embodiment, when executing a Lua script each time, if the average execution time of the Lua script is greater than a preset threshold, the Lua script is caused to execute only read instructions through a flag to obtain the instruction execution result. In the scenario where the Lua script execution time is too long, the sensitivity of the instruction opening is adjusted through the preset threshold to avoid the problem of continuous reconnection and application terminal.

[0162] like Figure 7 As shown, in another embodiment provided by the present invention, a computer-readable storage medium 701 is also provided, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes the optimization method for Lua script blocking described in the above embodiment.

[0163] In another embodiment provided by the present invention, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute the Lua script blocking optimization method described in the above embodiment.

[0164] Specifically, the method is:

[0165] Load the lua script into the cache.

[0166] Each time a Lua script is executed, the following steps are performed:

[0167] Get the average execution time of the Lua script.

[0168] If the average execution time is greater than the preset threshold, the flag is set.

[0169] Execute the read instruction in the Lua script to get the instruction execution result.

[0170] If the Lua script is determined to be completed according to the command execution result, the flag is canceled.

[0171] Optionally, before executing the read instruction in the Lua script and obtaining the instruction execution result, the following steps are also included:

[0172] Determine the type of each instruction in the Lua script, where the type is read or non-read.

[0173] A command of the read type is determined as a read command.

[0174] Optionally, execute the read instruction in the lua script to obtain the instruction execution result, including:

[0175] Get the slave node.

[0176] If the slave node is successfully obtained, the read instruction in the lua script is forwarded to the slave node, so that the slave node executes the read instruction, and the execution result of the slave node is determined as the instruction execution result.

[0177] Optionally, after obtaining the slave node, the following is also included:

[0178] If the acquisition from the node fails, the execution of the read instruction in the Lua script is terminated, and the instruction execution result of the script execution blocking is obtained, and the blocking description is busy.

[0179] Optionally, after determining the type of each instruction in the Lua script, it also includes:

[0180] Terminate the execution of non-read instructions in the Lua script, obtain the execution result of the instruction that blocked the script execution, and the blocking description is read-only.

[0181] Optionally, after determining that the Lua script is executed completely according to the instruction execution result, the method further includes:

[0182] Determine the current execution time of the Lua script.

[0183] The average execution time of the updated Lua script is (average execution time of the Lua script * historical execution times of the Lua script + current execution time) / (historical execution times of the Lua script + 1).

[0184] Optionally, if it is determined that the script execution is blocked according to the instruction execution result, a disconnection and reconnection operation is triggered.

[0185] The computer-readable storage medium provided in this embodiment executes a Lua script each time. If the average execution time of the Lua script is greater than a preset threshold, the Lua script is enabled to execute only read instructions through a flag to obtain the instruction execution result. In a scenario where the Lua script execution time is too long, the sensitivity of the instruction opening is adjusted through the preset threshold to avoid continuous reconnection and application terminal problems.

[0186] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.

[0187] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0188] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0189] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims

1. A Lua script blocking optimization method, characterized in that: include: Load the lua script into the cache; Each time the lua script is executed, the following steps are performed: Get the average execution time of the lua script; If the average execution time is greater than a preset threshold, a flag is set; Execute the read instruction in the lua script to obtain the instruction execution result; If it is determined according to the instruction execution result that the Lua script has been executed this time, the flag is cancelled.

2. The method according to claim 1, characterized in that Before executing the read instruction in the lua script and obtaining the instruction execution result, the method further includes: Determine the type of each instruction in the lua script, wherein the type is read or non-read; A command of the read type is determined as a read command.

3. The method according to claim 2, characterized in that The step of executing the read instruction in the lua script to obtain the instruction execution result includes: Get the slave node; If the slave node is successfully acquired, the read instruction in the lua script is forwarded to the slave node, so that the slave node executes the read instruction, and the execution result of the slave node is determined as the instruction execution result.

4. The method according to claim 3, characterized in that: After obtaining the slave node, the method further includes: If the acquisition from the node fails, the execution of the read instruction in the lua script is terminated, and the instruction execution result of the script execution blocking is obtained, and the blocking description is busy.

5. The method according to claim 2, characterized in that: After determining the type of each instruction in the lua script, the method further includes: The execution of the non-read instructions in the lua script is terminated, and the instruction execution result of the script execution blocking is obtained, and the blocking description is read-only.

6. The method according to claim 1, characterized in that After determining that the Lua script has been executed this time according to the instruction execution result, the method further includes: Determine the current execution time of the lua script; The average execution time of the updated Lua script is (the average execution time of the Lua script*the historical execution times of the Lua script+this execution time) / (the historical execution times of the Lua script+1).

7. The method according to claim 1, characterized in that The script execution is determined to be blocked according to the instruction execution result, and then a disconnection and reconnection operation is triggered.

8. A Lua script blocking optimization device, characterized in that: include: Loading module, used to load Lua script into cache; An execution module, used for obtaining the average execution time of the Lua script each time the Lua script is executed; If the average execution time is greater than a preset threshold, a flag is set; a read instruction in the lua script is executed to obtain an instruction execution result; if it is determined according to the instruction execution result that the lua script has been executed this time, the flag is cancelled.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor is used to implement the method according to any one of claims 1 to 7 when executing the program stored in the memory.

10. A computer-readable medium having instructions stored thereon, which, when executed by one or more processors, cause the processors to perform the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Cache bidirectional synchronization implementation method, device and equipment suitable for read-write

    CN117332008A

  • Redis-based lock-free distributed data high-concurrency processing framework system

    CN117851513A

  • Cross-data-center application data real-time synchronization method, device and system

    CN118368296A

  • Protocol software component and test apparatus

    US20120266024A1