[go: up one dir, main page]

CN119829129A - Lua script blocking optimization method and device, electronic equipment and readable medium - Google Patents

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

Info

Publication number
CN119829129A
CN119829129A CN202411725903.6A CN202411725903A CN119829129A CN 119829129 A CN119829129 A CN 119829129A CN 202411725903 A CN202411725903 A CN 202411725903A CN 119829129 A CN119829129 A CN 119829129A
Authority
CN
China
Prior art keywords
lua script
instruction
script
execution
read
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202411725903.6A
Other languages
Chinese (zh)
Inventor
陈国锐
毛刘刚
吴小文
石方波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Telecom Cloud Technology Co Ltd
Original Assignee
China Telecom Cloud Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Telecom Cloud Technology Co Ltd filed Critical China Telecom Cloud Technology Co Ltd
Priority to CN202411725903.6A priority Critical patent/CN119829129A/en
Publication of CN119829129A publication Critical patent/CN119829129A/en
Pending legal-status Critical Current

Links

Landscapes

  • Stored Programmes (AREA)

Abstract

本发明实施例提供了一种lua脚本阻塞的优化方法、装置、电子设备及可读介质,该方法将lua脚本加载至缓存;每次执行lua脚本时,均执行如下步骤:获取lua脚本的平均执行时间;若平均执行时间大于预设阈值,则设置标志位;执行lua脚本中的读指令,得到指令执行结果;若根据指令执行结果确定lua脚本本次执行完毕后,取消标志位。本方法在每次执行lua脚本时,若lua脚本的平均执行时间大于预设阈值,则通过标志位使得lua脚本仅执行读指令,得到指令执行结果,在lua脚本执行时间过长的场景中,通过预设阈值调整指令开放的灵敏度,避免了不断重连,应用终端的问题。

The embodiment of the present invention provides a method, device, electronic device and readable medium for optimizing Lua script blocking. The method 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, a flag is set; executing 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 canceled. When the method executes the Lua script each time, if the average execution time of the Lua script is greater than a preset threshold, the Lua script is only executed 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.

Description

Lua script blocking optimization method and device, electronic equipment and readable medium
Technical Field
The present invention relates to the field of middleware technology, and in particular, to a method for optimizing lua script blocking, an apparatus for optimizing lua script blocking, an electronic device, and a computer readable medium.
Background
Redis is a single-threaded-multiplexing IO model, and executing lua blocks all cached information in the entire Redis instance, i.e., while executing lua, it cannot respond to other instruction operations. When the blocking is performed for too long, the performance and resource reuse of Redis will be negatively affected.
Particularly in a high concurrency scenario, if the application end is improperly set up lua, during the execution blocking period, the Redis refuses other requests, which can cause chain reaction, and cause the client end to continuously reconnect and the application to be interrupted.
Disclosure of Invention
The embodiment of the invention provides an optimization method, an optimization device, electronic equipment and a readable medium for lua script blocking, which are used for solving the problem of continuous reconnection and application interruption during script execution blocking.
The embodiment of the invention discloses an optimization method for lua script blocking, which comprises the following steps:
loading 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 value, setting a flag bit;
Executing a read instruction in the lua script to obtain an instruction execution result;
and if the lua script is determined to be executed according to the instruction execution result, the flag bit is canceled.
Optionally, executing the read instruction in the lua script, before obtaining the instruction execution result, further includes:
Determining the type of each instruction in the lua script, wherein the type is read or unread;
an instruction of the type read is determined to be a read instruction.
Optionally, executing the read instruction in the lua script to obtain an instruction execution result, including:
Obtaining a slave node;
If the slave node acquires the read instruction successfully, forwarding the read instruction in the lua script to the slave node so as to enable the slave node to execute the read instruction, and determining the execution result of the slave node as the instruction execution result.
Optionally, after the slave node is acquired, the method further includes:
If the acquisition from the node fails, the execution of the read instruction in the lua script is terminated, an instruction execution result of script execution blocking is obtained, and the blocking is described as busy.
Optionally, after determining the type of each instruction in the lua script, the method further includes:
and terminating the execution of the non-read instruction in the lua script to obtain an instruction execution result of script execution blocking, wherein the blocking is described as read-only.
Optionally, after determining that the lua script is executed this time according to the instruction execution result, the method further includes:
determining the current execution time of the lua script;
the average execution time of the updated lua script is (average execution time of the lua script x the historical execution times of the lua script + the present execution time)/(the historical execution times of the lua script + 1).
Optionally, if the script execution block is determined according to the instruction execution result, the disconnection reconnection operation is triggered.
The embodiment of the invention also discloses an optimizing device for lua script blocking, which comprises the following steps:
the loading module is used for loading the lua script to the cache;
the execution module is used for acquiring the average execution time of the lua script when the lua script is executed each time, setting a flag bit if the average execution time is greater than a preset threshold value, executing a read instruction in the lua script to obtain an instruction execution result, and canceling the flag bit if the lua script is determined to be executed according to the instruction execution result.
The embodiment of the invention also discloses electronic equipment, which comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
The memory is used for storing a computer program;
The processor is configured to implement the method according to the embodiment of the present invention when executing the program stored in the memory.
Embodiments of the invention also disclose one or more computer-readable media having instructions stored thereon, which when executed by one or more processors, cause the processors to perform the methods described in the embodiments of the invention.
The embodiment of the invention has the following advantages:
The method comprises the steps of loading the lua script into a cache, obtaining average execution time of the lua script when the lua script is executed each time, setting a flag bit if the average execution time is greater than a preset threshold value, executing a read instruction in the lua script to obtain an instruction execution result, and canceling the flag bit if the lua script is determined to be executed this time according to the instruction execution result. When the lua script is executed each time, if the average execution time of the lua script is greater than a preset threshold value, the lua script only executes the read instruction to obtain an instruction execution result, and in a scene with overlong execution time of the lua script, the open sensitivity of the instruction is adjusted through the preset threshold value, so that the problems of continuous reconnection and application of the terminal are avoided.
Drawings
FIG. 1 is a flow chart of the steps of a method for optimizing lua script blocking provided in an embodiment of the present invention;
FIG. 2 is a flowchart of method steps for instruction execution when a lua script is blocked, as provided in an embodiment of the present invention;
FIG. 3 is a flowchart of method steps for instruction execution when another lua script execution is blocked, as provided in an embodiment of the present invention;
FIG. 4 is a flow chart of the steps of another method for optimizing lua script blocking provided in an embodiment of the present invention;
FIG. 5 is a block diagram of an optimizing device for lua script blocking provided in an embodiment of the present invention;
FIG. 6 is a block diagram of an electronic device provided in an embodiment of the invention;
fig. 7 is a schematic diagram of a computer readable medium provided in an embodiment of the invention.
Detailed Description
In order that the above-recited objects, features and advantages of the present invention will become more readily apparent, a more particular description of the invention will be rendered by reference to the appended drawings and appended detailed description.
In carrying out the invention, the inventors found that:
Redis (Remote Dictionary Server)) is a high-performance, memory-storage open source database that stores data in key-value pairs and supports a variety of data structures. Redis is commonly used for cache, session management, message queuing, and other named applications. In Redis, lua scripts are typically used to perform a series of operations, such as reading and writing data, as well as complex logic operations. The Redis lua script is then an instruction that parses the lua script into executable instructions so that the Redis server can execute the scripts.
Since Redis is a single-threaded-multiplexing IO model, executing lua blocks all cached information in the entire instance of Redis, i.e., while executing lua, it cannot respond to other instruction operations. When the blocking is performed for too long, the performance and resource reuse of Redis will be negatively affected.
Particularly in a high concurrency scenario, if the application end is improperly set up lua, during the execution blocking period, the Redis refuses other requests, which can cause chain reaction, and cause the client end to continuously reconnect and the application to be interrupted.
If the cache high availability module detects that the ping operation cannot be responded normally during the blocking execution, the high availability module misdeems that the redis service node is abnormal, and the master-slave switching operation is triggered, so that the service application is negatively affected.
The embodiment of the invention provides an optimization method, an optimization device, electronic equipment and a readable medium for blocking an lua script, wherein the method loads the lua script into a cache, and each time the lua script is executed, the method comprises the steps of obtaining average execution time of the lua script, setting a zone bit if the average execution time is greater than a preset threshold value, executing a read instruction in the lua script to obtain an instruction execution result, and canceling the zone bit if the execution result of the lua script is determined to be finished according to the instruction execution result. When the lua script is executed each time, if the average execution time of the lua script is larger than the preset threshold value, the method enables the lua script to only execute the read instruction through the zone bit to obtain the instruction execution result, and in a scene with overlong execution time of the lua script, the open sensitivity of the instruction is adjusted through the preset threshold value, so that the problems of continuous reconnection and application of the terminal are avoided.
Referring to fig. 1, a step flow chart of an optimizing method of lua script blocking provided in an embodiment of the present invention may specifically include the following steps:
101, loading the lua script into a cache.
After the lua script is loaded into the cache, a SHA-1 hash value is generated for the lua script as a key, and the content of the lua script is used as a value. And in the subsequent execution, the corresponding value can be found through the key, and then the lua script in the value is executed.
102, Each time the lua script is executed, the following steps 201 to 204 are performed:
the average execution time of the lua script is obtained 201.
The average execution time of the lua script is updated after each execution of the lua script, and the current average execution time is directly acquired in this step.
202, If the average execution time is greater than a preset threshold, setting a flag bit.
When the average time consumption of the script is smaller than a preset threshold, the execution time is controllable, the whole service is not blocked, and intervention processing is not needed.
When the average time consumption exceeds a threshold value, the risk that the overall availability is reduced due to the existence of a blocking surface in the execution of the script is indicated, and a read request forwarding flow is triggered to improve the availability.
The threshold value can be configured through a configuration item, such as parameter 1, parameter 2 and parameter 3, which are newly added in the configuration item.
When the lua script is executed, the parameter 1 indicates whether to use the optimization method of lua script blocking provided by the embodiment to process, the parameter 2 indicates whether to set a flag bit, and the parameter 3 indicates a threshold value.
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-disable no NULL, where parameter 1 is script-analysis-disable, parameter 2 is no, and parameter 3 is NULL (i.e., NULL). The optimization method indicating that the lua script is not blocked by the lua script provided by the present embodiment is executed.
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, where parameter 1 is script-analysis-enable, parameter 2 is no, and parameter 3 is 10. The lua script is executed by adopting the optimization method for blocking the lua script provided by the embodiment, and the threshold is 10 milliseconds, and the flag bit is not set at this time.
If in step 202 it is determined that the average execution time is greater than 10 milliseconds, then parameter 2 of the configuration item is modified to yes, and the flag bit is set. The newly added content in the configuration item after modification is changed into script-analysis-enable yes 10, wherein 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. The lua script is executed by adopting the optimization method for blocking the lua script provided by the embodiment, and a flag bit is set, wherein the threshold value is 10 milliseconds.
Since the flag bit is set when step 102 is performed, it indicates that the lua script is being executed as long as the flag bit is set.
203, Executing the read instruction in the lua script to obtain an instruction execution result. And terminating the execution of the non-read instruction in the lua script to obtain an instruction execution result of script execution blocking, wherein the blocking is described as read-only.
The read instructions in the lua script are processed in step 203 and are not executed for other instructions, so the read instructions in the lua script are determined before step 203 is executed.
The procedure for determining the read instruction in the lua script is as follows:
1. the type of each instruction in the lua script is determined, wherein the type is read or unread.
2. An instruction of the type read is determined to be a read instruction.
If instructions in the lua script are classified, read instructions are classified as one type, and non-read instructions (e.g., write instructions) are classified as one type.
In step 203, only the read instruction is executed, and the non-read instruction is not executed.
The execution of the read instruction in step 203 is:
1.a slave node is acquired.
2. If the slave node acquires the read instruction successfully, forwarding the read instruction in the lua script to the slave node so as to enable the slave node to execute the read instruction, and determining the execution result of the slave node as the instruction execution result.
3. If the acquisition from the node fails, the execution of the read instruction in the lua script is terminated, an instruction execution result of script execution blocking is obtained, and the blocking is described as busy.
For example, the instruction execution results in busy script execution blocking.
That is, if all the instructions in the lua script are read instructions when executing step 203, all the read instructions are executed by the slave node, and the execution result of the read instructions is taken as the instruction execution result obtained by executing the read instructions in the lua script in step 203.
If all the instructions in the lua script are non-read instructions, terminating executing all the non-read instructions to obtain an instruction execution result of script execution blocking, and the blocking is described as read-only.
For example, the instruction execution results in read-only, script execution blocking.
If part of the instructions in the lua script are read instructions and part of the instructions are non-read instructions, as shown in fig. 2, the read instructions in the lua script are executed by the slave nodes to obtain an instruction execution result, the non-read instructions in the lua script are terminated to obtain an instruction execution result of script execution blocking, and the blocking instruction is read only.
And the slave node executes the read instruction in the lua script to acquire the slave node, and forwards the read instruction in the lua script to the slave node so as to enable the slave node to execute the read instruction, and the execution result of the slave node is determined to be the instruction execution result.
In a specific implementation, in order to ensure that the execution of step 203 is in the execution blocking period, before executing step 203, it may be further confirmed whether the lua script blocking occurs again, that is, that the average execution time is greater than the preset threshold again, and the flag bit is set.
If the average execution time is greater than the preset threshold and the flag bit is set, it is confirmed that the lua script is blocked, step 203 is executed, otherwise, it is considered that no lua script is blocked, step 203 is not executed any more, and the execution scheme of the existing lua script (i.e. the local execution instruction) is converted, as shown in fig. 3.
In step 203, only read instructions are allowed to execute, achieving a response read-only request effect by forwarding to the slave node. For write instructions, a hint error is quickly returned. Because the write request is still refused/blocked, the read-only request theory has no problem of consistency of master-slave data except the data related to the script, and the data accuracy can be trusted.
204, If the lua script is determined to be executed according to the instruction execution result, the flag bit is canceled.
And if the parameter 2 of the configuration item is modified to be no, the cancellation of the flag bit is realized. The newly added content in the configuration item after modification is changed into a script-analysis-enable no 10, wherein the parameter 1 is the script-analysis-enable, the parameter 2 is no, and the parameter 3 is 10. The lua script is executed by adopting the optimization method for blocking the lua script provided by the embodiment, and the threshold is 10 milliseconds, and the flag bit is not set (i.e. the flag bit is cancelled).
The cancellation flag bit is the lua script is executed at the present time.
In addition, after determining that the execution of the lua script is finished according to the instruction execution result, the average execution time of the lua script is updated, and the updating process is as follows:
1. and determining the current execution time of the lua script.
If the current execution is the ith execution of the lua script, the ith execution time T i of the lua script is determined.
2. The average execution time of the updated lua script is (average execution time of the lua script x the historical execution times of the lua script + the present execution time)/(the historical execution times of the lua script + 1).
The historical execution times of the lua script do not contain the current execution time after the current execution is finished, namely the historical execution times of the lua script are i-1.
That is, the average execution time of all i-1 times of execution and the i-th execution time of the lua script after i-1 times of execution before the lua script are obtained, and the average execution time of all i times of execution after i times of execution before the lua script is the updated average execution time of the lua script.
If the average execution time of the lua script isThe update procedure is:
In addition, if the script execution block is determined according to the instruction execution result, the application side can perform mechanisms such as retry, etc., so as to avoid overtime caused by long-time waiting of the application, and further trigger disconnection reconnection operation.
The method for optimizing the lua script blocking can be used for solving the problems of overlong execution time of a complex lua script, releasing a service detection request, releasing a read-through instruction, improving the overall service availability, simultaneously counting and recording the average execution time of the lua script, adjusting the instruction opening sensitivity according to a preset threshold, improving the service availability in the blocking stage, avoiding various problems caused by service blocking, such as high availability judgment errors caused by service blocking, and applying overtime reconnection.
The optimization method for lua script blocking provided by the embodiment can realize more accurate judgment of the high-availability module and avoid error master-slave switching. In the existing lua script execution scheme, if the lua script execution time is long, the ping request is blocked and not responded in the time, so that a high-availability module can consider that the service is not available, and then the master-slave switching logic is triggered. The optimization method for lua script blocking provided by the embodiment can ensure that ping can still respond normally in the execution process of the lua script, and avoid judgment errors.
According to the lua script blocking optimization method provided by the embodiment, a function configuration switch is additionally arranged, the average script execution time is counted, and the instruction opening sensitivity is adjusted according to the configuration threshold, so that the adaptation is more flexible.
The optimizing method for lua script blocking provided in this embodiment releases a read-only instruction during the execution of the lua script blocking, and transfers the read-only instruction to the slave node for execution. And the busy error can be returned quickly through the instruction execution result, so that the high-availability logic is prevented from being triggered due to long-time waiting of the application end.
The optimization method for the lua script blocking provided by the embodiment can realize compatibility with the existing lua script execution scheme. As shown in fig. 4.
After execution of the lua script, the lua script is loaded into the cache, via step 101.
Then, it is determined whether the parameter 1 is script-analysis-enable.
If parameter 1 is not script-analysis-enable (e.g., is script-analysis-disable), the lua script is executed using an existing lua script execution scheme.
If parameter 1 is script-analysis-enable, then the lua script is executed (i.e., executed using the optimization method of lua script blocking provided in this embodiment) via step 102.
The average execution time of the lua script is obtained as per step 201.
Through step 202, when the average execution time is greater than a preset threshold, a flag bit is set.
The read instruction in the lua script is executed, resulting in an instruction execution result, via step 203. And terminating the execution of the non-read instruction in the lua script to obtain an instruction execution result of script execution blocking, wherein the blocking is described as read-only.
Through step 204, after determining that the lua script is executed this time according to the instruction execution result, the flag bit is cancelled.
Regardless of the manner in which the lua script is executed, the average execution time of the lua script is updated after each execution of the lua script is completed.
It should be noted that, for simplicity of description, the method embodiments are shown as a series of acts, but it should be understood by those skilled in the art that the embodiments are not limited by the order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred embodiments, and that the acts are not necessarily required by the embodiments of the invention.
The embodiment provides an optimization method for blocking a lua script, which loads the lua script into a cache, and executes the steps of obtaining average execution time of the lua script each time the lua script is executed, setting a flag bit if the average execution time is greater than a preset threshold value, executing a read instruction in the lua script to obtain an instruction execution result, and canceling the flag bit after the execution of the lua script is confirmed according to the instruction execution result.
When the lua script is executed each time, if the average execution time of the lua script is greater than a preset threshold value, the lua script only executes the read instruction through the flag bit to obtain an instruction execution result, and in a scene with overlong execution time of the lua script, the open sensitivity of the instruction is adjusted through the preset threshold value, so that the problems of continuous reconnection and application of a terminal are avoided.
Referring to fig. 5, a block diagram of an optimizing device for lua script blocking according to an embodiment of the present invention is shown, which may specifically include the following modules:
a loading module 501, configured to load the lua script into the cache.
The execution module 502 is configured to execute the following steps each time the lua script is executed:
The average execution time of the lua script is obtained.
If the average execution time is greater than the preset threshold value, setting a flag bit.
And executing the read instruction in the lua script to obtain an instruction execution result.
And if the lua script is determined to be executed according to the instruction execution result, the flag bit is canceled.
The method comprises the steps of executing a read instruction in the lua script, and determining the type of each instruction in the lua script before obtaining an instruction execution result, wherein the type is read or unread.
An instruction of the type read is determined to be a read instruction.
Executing the read instruction in the lua script to obtain an instruction execution result, wherein the method comprises the following steps:
A slave node is acquired.
If the slave node acquires the read instruction successfully, forwarding the read instruction in the lua script to the slave node so as to enable the slave node to execute the read instruction, and determining the execution result of the slave node as the instruction execution result.
Wherein after obtaining the slave node, further comprising:
If the acquisition from the node fails, the execution of the read instruction in the lua script is terminated, an instruction execution result of script execution blocking is obtained, and the blocking is described as busy.
Wherein, after determining the type of each instruction in the lua script, the method further comprises:
and terminating the execution of the non-read instruction in the lua script to obtain an instruction execution result of script execution blocking, wherein the blocking is described as read-only.
After determining that the lua script is executed this time according to the instruction execution result, the method further comprises:
And determining the current execution time of the lua script.
The average execution time of the updated lua script is (average execution time of the lua script x the historical execution times of the lua script + the present execution time)/(the historical execution times of the lua script + 1).
And if the script execution block is determined according to the instruction execution result, triggering the disconnection reconnection operation.
For the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments for relevant points.
According to the device provided by the embodiment, when the lua script is executed each time, if the average execution time of the lua script is greater than the preset threshold, the lua script only executes the read instruction through the flag bit to obtain the instruction execution result, and in a scene with overlong execution time of the lua script, the open sensitivity of the instruction is adjusted through the preset threshold, so that the problems of continuous reconnection and application terminals are avoided.
In addition, the embodiment of the invention also provides an electronic device, as shown in fig. 6, which comprises 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 complete communication with each other through the communication bus 604,
A memory 603 for storing a computer program;
the processor 601 is configured to execute the program stored in the memory 603, and implement the following steps:
the lua script is loaded into the cache.
Each time the lua script is executed, the following steps are performed:
The average execution time of the lua script is obtained.
If the average execution time is greater than the preset threshold value, setting a flag bit.
And executing the read instruction in the lua script to obtain an instruction execution result.
And if the lua script is determined to be executed according to the instruction execution result, the flag bit is canceled.
Optionally, executing the read instruction in the lua script, before obtaining the instruction execution result, further includes:
the type of each instruction in the lua script is determined, wherein the type is read or unread.
An instruction of the type read is determined to be a read instruction.
Optionally, executing the read instruction in the lua script to obtain an instruction execution result, including:
A slave node is acquired.
If the slave node acquires the read instruction successfully, forwarding the read instruction in the lua script to the slave node so as to enable the slave node to execute the read instruction, and determining the execution result of the slave node as the instruction execution result.
Optionally, after the slave node is acquired, the method further includes:
If the acquisition from the node fails, the execution of the read instruction in the lua script is terminated, an instruction execution result of script execution blocking is obtained, and the blocking is described as busy.
Optionally, after determining the type of each instruction in the lua script, the method further includes:
and terminating the execution of the non-read instruction in the lua script to obtain an instruction execution result of script execution blocking, wherein the blocking is described as read-only.
Optionally, after determining that the lua script is executed this time according to the instruction execution result, the method further includes:
And determining the current execution time of the lua script.
The average execution time of the updated lua script is (average execution time of the lua script x the historical execution times of the lua script + the present execution time)/(the historical execution times of the lua script + 1).
Optionally, if the script execution block is determined according to the instruction execution result, the disconnection reconnection operation is triggered.
The communication bus mentioned by the above terminal may be a peripheral component interconnect standard (PERIPHERAL COMPONENT INTERCONNECT, abbreviated as PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, abbreviated as EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the terminal and other devices.
The memory may include random access memory (Random Access Memory, RAM) or may include non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central Processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), a digital signal processor (DIGITAL SIGNAL Processing, DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable gate array (FPGA) or other Programmable logic device, discrete gate or transistor logic device, or discrete hardware components.
According to the electronic device provided by the embodiment, when the lua script is executed each time, if the average execution time of the lua script is greater than the preset threshold, the lua script only executes the read instruction through the flag bit to obtain the instruction execution result, and in a scene with overlong execution time of the lua script, the open sensitivity of the instruction is adjusted through the preset threshold, so that the problems of continuous reconnection and application terminals are avoided.
In yet another embodiment provided by the present invention, as shown in fig. 7, there is further provided a computer readable storage medium 701 having instructions stored therein, which when run on a computer, cause the computer to perform the method of optimizing lua script blocking described in the above embodiment.
In a further embodiment of the present invention, a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of optimizing lua script blocking described in the above embodiments is also provided.
Specifically, the method comprises the following steps:
the lua script is loaded into the cache.
Each time the lua script is executed, the following steps are performed:
The average execution time of the lua script is obtained.
If the average execution time is greater than the preset threshold value, setting a flag bit.
And executing the read instruction in the lua script to obtain an instruction execution result.
And if the lua script is determined to be executed according to the instruction execution result, the flag bit is canceled.
Optionally, executing the read instruction in the lua script, before obtaining the instruction execution result, further includes:
the type of each instruction in the lua script is determined, wherein the type is read or unread.
An instruction of the type read is determined to be a read instruction.
Optionally, executing the read instruction in the lua script to obtain an instruction execution result, including:
A slave node is acquired.
If the slave node acquires the read instruction successfully, forwarding the read instruction in the lua script to the slave node so as to enable the slave node to execute the read instruction, and determining the execution result of the slave node as the instruction execution result.
Optionally, after the slave node is acquired, the method further includes:
If the acquisition from the node fails, the execution of the read instruction in the lua script is terminated, an instruction execution result of script execution blocking is obtained, and the blocking is described as busy.
Optionally, after determining the type of each instruction in the lua script, the method further includes:
and terminating the execution of the non-read instruction in the lua script to obtain an instruction execution result of script execution blocking, wherein the blocking is described as read-only.
Optionally, after determining that the lua script is executed this time according to the instruction execution result, the method further includes:
And determining the current execution time of the lua script.
The average execution time of the updated lua script is (average execution time of the lua script x the historical execution times of the lua script + the present execution time)/(the historical execution times of the lua script + 1).
Optionally, if the script execution block is determined according to the instruction execution result, the disconnection reconnection operation is triggered.
When the lua script is executed each time, if the average execution time of the lua script is greater than the preset threshold, the lua script only executes the read instruction through the flag bit to obtain an instruction execution result, and in a scene with overlong execution time of the lua script, the open sensitivity of the instruction is adjusted through the preset threshold, so that the problems of continuous reconnection and application of the terminal are avoided.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may 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 loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, 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 may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy disk, hard disk, tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk Solid STATE DISK (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises an element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the 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 (10)

1.一种lua脚本阻塞的优化方法,其特征在于,包括:1. A Lua script blocking optimization method, characterized by comprising: 将lua脚本加载至缓存;Load the lua script into the cache; 每次执行所述lua脚本时,均执行如下步骤:Each time the lua script is executed, the following steps are performed: 获取所述lua脚本的平均执行时间;Get the average execution time of the lua script; 若所述平均执行时间大于预设阈值,则设置标志位;If the average execution time is greater than a preset threshold, a flag is set; 执行所述lua脚本中的读指令,得到指令执行结果;Execute the read instruction in the lua script to obtain the instruction execution result; 若根据所述指令执行结果确定所述lua脚本本次执行完毕后,取消所述标志位。If it is determined according to the instruction execution result that the Lua script has been executed this time, the flag is cancelled. 2.根据权利要求1所述的方法,其特征在于,所述执行所述lua脚本中的读指令,得到指令执行结果之前,还包括: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, it also includes: 确定所述lua脚本中各指令的类型,其中,类型为读或非读;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.根据权利要求2所述的方法,其特征在于,所述执行所述lua脚本中的读指令,得到指令执行结果,包括:3. The method according to claim 2, characterized in that the executing the read instruction in the lua script to obtain the instruction execution result comprises: 获取从节点;Get the slave node; 若从节点获取成功,则将所述lua脚本中的读指令转发至所述从节点,以使所述从节点执行读指令,将从节点的执行结果确定为指令执行结果。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.根据权利要求3所述的方法,其特征在于,所述获取从节点之后,还包括:4. The method according to claim 3, characterized in that after obtaining the slave node, it also includes: 若从节点获取失败,则终止执行所述lua脚本中的读指令,得到脚本执行阻塞的指令执行结果,且阻塞说明为繁忙。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.根据权利要求2所述的方法,其特征在于,所述确定所述lua脚本中各指令的类型之后,还包括:5. The method according to claim 2, characterized in that after determining the type of each instruction in the Lua script, it also includes: 终止执行所述lua脚本中的非读指令,得到脚本执行阻塞的指令执行结果,且阻塞说明为只读。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.根据权利要求1所述的方法,其特征在于,所述根据所述指令执行结果确定所述lua脚本本次执行完毕之后,还包括: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, it also includes: 确定所述lua脚本的本次执行时间;Determine the current execution time of the lua script; 更新所述lua脚本的平均执行时间为(所述lua脚本的平均执行时间*所述lua脚本的历史执行次数+本次执行时间)/(所述lua脚本的历史执行次数+1)。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.根据权利要求1所述的方法,其特征在于,所述根据所述指令执行结果确定脚本执行阻塞,则触发断开重连操作。7. The method according to claim 1 is characterized in that, when it is determined that the script execution is blocked according to the instruction execution result, a disconnection and reconnection operation is triggered. 8.一种lua脚本阻塞的优化装置,其特征在于,包括:8. A Lua script blocking optimization device, characterized by comprising: 加载模块,用于将lua脚本加载至缓存;Loading module, used to load Lua script into cache; 执行模块,用于每次执行所述lua脚本时,获取所述lua脚本的平均执行时间;若所述平均执行时间大于预设阈值,则设置标志位;执行所述lua脚本中的读指令,得到指令执行结果;若根据所述指令执行结果确定所述lua脚本本次执行完毕后,取消所述标志位。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; 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.一种电子设备,其特征在于,包括处理器、通信接口、存储器和通信总线,其中,所述处理器、所述通信接口以及所述存储器通过所述通信总线完成相互间的通信;9. 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 through the communication bus; 所述存储器,用于存放计算机程序;The memory is used to store computer programs; 所述处理器,用于执行存储器上所存放的程序时,实现如权利要求1-7任一项所述的方法。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.一种计算机可读介质,其上存储有指令,当由一个或多个处理器执行时,使得所述处理器执行如权利要求1-7任一项所述的方法。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.
CN202411725903.6A 2024-11-28 2024-11-28 Lua script blocking optimization method and device, electronic equipment and readable medium Pending CN119829129A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202411725903.6A CN119829129A (en) 2024-11-28 2024-11-28 Lua script blocking optimization method and device, electronic equipment and readable medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202411725903.6A CN119829129A (en) 2024-11-28 2024-11-28 Lua script blocking optimization method and device, electronic equipment and readable medium

Publications (1)

Publication Number Publication Date
CN119829129A true CN119829129A (en) 2025-04-15

Family

ID=95298505

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202411725903.6A Pending CN119829129A (en) 2024-11-28 2024-11-28 Lua script blocking optimization method and device, electronic equipment and readable medium

Country Status (1)

Country Link
CN (1) CN119829129A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120266024A1 (en) * 2011-04-15 2012-10-18 The Boeing Company Protocol software component and test apparatus
CN117332008A (en) * 2023-10-12 2024-01-02 中移互联网有限公司 A cache bidirectional synchronization implementation method, device and equipment suitable for reading and writing
CN117851513A (en) * 2023-12-14 2024-04-09 天翼云科技有限公司 A lock-free distributed data high-concurrency processing framework system based on Redis
CN118368296A (en) * 2024-06-20 2024-07-19 杭州宇信数字科技有限公司 Cross-data-center application data real-time synchronization method, device and system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120266024A1 (en) * 2011-04-15 2012-10-18 The Boeing Company Protocol software component and test apparatus
CN117332008A (en) * 2023-10-12 2024-01-02 中移互联网有限公司 A cache bidirectional synchronization implementation method, device and equipment suitable for reading and writing
CN117851513A (en) * 2023-12-14 2024-04-09 天翼云科技有限公司 A lock-free distributed data high-concurrency processing framework system based on Redis
CN118368296A (en) * 2024-06-20 2024-07-19 杭州宇信数字科技有限公司 Cross-data-center application data real-time synchronization method, device and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
I139-35: "Web应用防火墙中流量处理模块的设计与实现", 《中国优秀硕士学位论文全文数据库 信息科技辑》, 15 July 2019 (2019-07-15), pages 139 - 35 *

Similar Documents

Publication Publication Date Title
WO2021180025A1 (en) Message processing method and apparatus, electronic device and medium
CN112650576B (en) Resource scheduling method, device, equipment, storage medium and computer program product
US9253265B2 (en) Hot pluggable extensions for access management system
CN111538651A (en) Interface testing method, device, server and storage medium
US20230030856A1 (en) Distributed table storage processing method, device and system
US9514176B2 (en) Database update notification method
US8458511B2 (en) Fault isolation using code paths
WO2020029588A1 (en) Data reading method, device, system, and distributed system
CN111385255B (en) Asynchronous call implementation method, device, server and server cluster
WO2020232892A1 (en) Method and apparatus for key management for blockchain, device, and storage medium
CN110955539A (en) Process quitting method and device, electronic equipment and machine-readable storage medium
CN108418859B (en) Method and apparatus for writing data
CN111159160A (en) A version rollback method, device, electronic device and storage medium
CN110083509B (en) Method and device for arranging log data
CN119829129A (en) Lua script blocking optimization method and device, electronic equipment and readable medium
CN117472627A (en) Task repetition management system, method and device, electronic equipment and storage medium
CN117971310A (en) Redis distributed current limiting method and system based on java
CN112711466B (en) Hanging affair inspection method and device, electronic equipment and storage medium
CN115686933A (en) Server-free workflow function exception retry method and device
CN114356211A (en) A storage space processing method, device, electronic device and storage medium
CN113886473A (en) A method and device for providing service data
CN114896082A (en) Message processing method, apparatus, electronic device and storage medium
US9619306B2 (en) Information processing device, control method thereof, and recording medium
CN111639089B (en) Transaction processing method, transaction processing device, electronic equipment and computer readable storage medium
CN111159786B (en) Metadata protection method, device, electronic device and storage medium

Legal Events

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