CN117130911A - Infinite recursion detection method, apparatus, device and storage medium for cloud function - Google Patents

Infinite recursion detection method, apparatus, device and storage medium for cloud function Download PDF

Info

Publication number
CN117130911A
CN117130911A CN202310994769.9A CN202310994769A CN117130911A CN 117130911 A CN117130911 A CN 117130911A CN 202310994769 A CN202310994769 A CN 202310994769A CN 117130911 A CN117130911 A CN 117130911A
Authority
CN
China
Prior art keywords
cloud function
cloud
recursion
function
infinite
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
CN202310994769.9A
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 Technology Innovation Center
China Telecom Corp Ltd
Original Assignee
China Telecom Technology Innovation Center
China Telecom Corp 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 Technology Innovation Center, China Telecom Corp Ltd filed Critical China Telecom Technology Innovation Center
Priority to CN202310994769.9A priority Critical patent/CN117130911A/en
Publication of CN117130911A publication Critical patent/CN117130911A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3636Software debugging by tracing the execution of the program
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application relates to an infinite recursion detection method, an infinite recursion detection device, infinite recursion detection equipment and a storage medium of a cloud function. The method comprises the following steps: before a first cloud function uploaded by a user is operated, recursion detection is carried out on codes of the first cloud function so as to determine whether infinite recursion exists in the first cloud function; and if the first cloud function is determined to have no infinite recursion through the recursion detection, allowing the first cloud function to operate, monitoring the resource use condition of the first cloud function in the process of operating the first cloud function, and limiting the resource use of the first cloud function under the condition that the resource used by the first cloud function is monitored to meet the resource consumption abnormal condition. By adopting the method, infinite recursion of the cloud function can be avoided.

Description

Infinite recursion detection method, apparatus, device and storage medium for cloud function
Technical Field
The present application relates to the field of cloud computing technologies, and in particular, to a method, an apparatus, a device, and a storage medium for infinite recursion detection of a cloud function.
Background
With the development of cloud computing technology, the advantages of rapid deployment, elasticity, light weight, low cost and high resource utilization rate of the cloud function make the cloud function a main mode of cloud computing application. The user only needs to write codes according to specifications and define triggering events, and does not need to care about how the codes run and stretch, because the specific running environment and the elastic stretch of the cloud functions are maintained by a cloud service provider, and the cloud service provider charges according to the resource usage amount when the cloud functions run.
However, due to the characteristics of extremely easy expansion and billing according to the usage amount of resources, if the cloud function has infinite recursion, huge bills are extremely easy to be caused due to the characteristics of light weight and infinite expansion, and unexpected burden is brought to users, so how to avoid infinite recursion of the cloud function becomes a problem to be solved.
Disclosure of Invention
The embodiment of the application provides an infinite recursion detection method, device, equipment and storage medium for cloud functions, which can realize the avoidance of infinite recursion of the cloud functions.
In a first aspect, the present application provides a method for infinite recursion detection of a cloud function, the method comprising: before running a first cloud function uploaded by a user, recursively detecting codes of the first cloud function to determine whether infinite recursion exists in the first cloud function; and if the first cloud function does not have infinite recursion through recursion detection, allowing the first cloud function to operate, monitoring the resource use condition of the first cloud function in the process of operating the first cloud function, and limiting the resource use of the first cloud function under the condition that the resource used by the first cloud function is monitored to meet the resource consumption abnormal condition.
In one embodiment, recursively detecting code of a first cloud function to determine whether the first cloud function has infinite recursion includes: detecting call parameters of each function included in the first cloud function based on codes of the first cloud function to obtain a first recursion detection result; detecting whether other cloud functions called by the first cloud function call back the first cloud function or not under the condition that the first recursion detection result is that the first cloud function does not have infinite recursion, and obtaining a second recursion detection result; and determining whether the first cloud function has infinite recursion according to the second recursion detection result.
In one embodiment, the calling parameters include a number of calling stack layers, and detecting the calling parameters of each function included in the first cloud function to obtain a first recursion detection result includes: detecting whether the number of call stack layers of each function included in the first cloud function exceeds a preset layer number threshold; if the number of layers exceeds a preset layer threshold, determining that the first recursion detection result is that infinite recursion exists in the first cloud function; and if the number of layers does not exceed the preset layer threshold value, determining that the first recursion detection result is that the first cloud function does not have infinite recursion.
In one embodiment, detecting whether other cloud functions called by the first cloud function call back the first cloud function to obtain a second recursion detection result includes: acquiring a cloud function call chain of a first cloud function, wherein a first cloud function in the cloud function call chain is called by the first cloud function, and a non-first cloud function in the cloud function call chain is called by a previous cloud function; and determining whether each cloud function in the cloud function call chain calls back the first cloud function so as to obtain a second recursion detection result.
In one embodiment, determining whether the first cloud function has an infinite recurrence based on the second recurrence detection result includes: outputting prompt information to a user under the condition that the second recursion detection result is that other cloud functions called by the first cloud function call back the first cloud function, and determining whether the first cloud function has infinite recursion according to the instruction information fed back by the user based on the prompt information; and under the condition that the second recursion detection result is that other cloud functions called by the first cloud function do not have callback to the first cloud function, determining that the first cloud function does not have infinite recursion.
In one embodiment, the method further comprises: matching the monitored resource use condition of the first cloud function with a preset rule base; if the first cloud function is successfully matched with a certain rule in the preset rule base, determining that the resources used by the first cloud function meet the resource consumption abnormal condition.
In one embodiment, limiting the resource usage of the first cloud function includes: and limiting the concurrency number of the first cloud function.
In one embodiment, limiting the concurrency of the first cloud function includes: maintaining the current concurrency number of the first cloud function unchanged; or reducing the concurrency number of the first cloud function to a preset concurrency number threshold.
In a second aspect, the present application also provides an infinite recursion detection apparatus for a cloud function, the apparatus comprising: the detection module is used for carrying out recursion detection on codes of the first cloud function before the first cloud function uploaded by the user is operated so as to determine whether the first cloud function has infinite recursion or not; and the monitoring module is used for allowing the first cloud function to run if the first cloud function does not have infinite recursion through recursion detection, monitoring the resource use condition of the first cloud function in the process of running the first cloud function, and limiting the resource use of the first cloud function under the condition that the resource used by the first cloud function is monitored to meet the condition of excessive resource consumption.
In one embodiment, the detection module is specifically configured to detect, based on a code of the first cloud function, a call parameter of each function included in the first cloud function, to obtain a first recursive detection result; detecting whether other cloud functions called by the first cloud function call back the first cloud function or not under the condition that the first recursion detection result is that the first cloud function does not have infinite recursion, and obtaining a second recursion detection result; and determining whether the first cloud function has infinite recursion according to the second recursion detection result.
In one embodiment, the call parameter includes a call stack layer number, and the detection module is specifically configured to detect whether the call stack layer number of each function included in the first cloud function exceeds a preset layer number threshold; if the number of layers exceeds a preset layer threshold, determining that the first recursion detection result is that infinite recursion exists in the first cloud function; and if the number of layers does not exceed the preset layer threshold value, determining that the first recursion detection result is that the first cloud function does not have infinite recursion.
In one embodiment, the detection module is specifically configured to obtain a cloud function call chain of a first cloud function, where a first cloud function in the cloud function call chain is called by the first cloud function, and a non-first cloud function in the cloud function call chain is called by a previous cloud function; and determining whether each cloud function in the cloud function call chain calls back the first cloud function so as to obtain a second recursion detection result.
In one embodiment, the detection module is specifically configured to output prompt information to a user when the second recursion detection result indicates that the other cloud functions called by the first cloud function call back the first cloud function, and determine whether the first cloud function has infinite recursion according to the instruction information fed back by the user based on the prompt information; and under the condition that the second recursion detection result is that other cloud functions called by the first cloud function do not have callback to the first cloud function, determining that the first cloud function does not have infinite recursion.
In one embodiment, the monitoring module includes a matching unit, configured to match the monitored resource usage of the first cloud function with a preset rule base; if the first cloud function is successfully matched with a certain rule in the preset rule base, determining that the resources used by the first cloud function meet the resource consumption abnormal condition.
In one embodiment, the monitoring module is specifically configured to limit the concurrency number of the first cloud function.
In one embodiment, the monitoring module is specifically configured to maintain a current concurrency number of the first cloud function unchanged; or reducing the concurrency number of the first cloud function to a preset concurrency number threshold.
In a third aspect, the present application also provides a computer device. The computer device comprises a memory storing a computer program and a processor implementing the steps of the method according to any of the first aspects above when the processor executes the computer program.
In a fourth aspect, the present application also provides a computer-readable storage medium. The computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method of any of the first aspects above.
In a fifth aspect, the present application also provides a computer program product. The computer program product comprising a computer program which, when executed by a processor, implements the steps of the method according to any of the first aspects above.
According to the infinite recursion detection method, the infinite recursion detection device, the equipment and the storage medium for the cloud functions, before the first cloud function uploaded by a user is operated, the code of the first cloud function is recursion detected to determine whether the first cloud function has infinite recursion, if the first cloud function is determined to have no infinite recursion through the recursion detection, the operation of the first cloud function is allowed, in the process of operating the first cloud function, the resource use condition of the first cloud function is monitored, and under the condition that the resource used by the first cloud function is monitored to meet the condition of resource consumption, the resource use of the first cloud function is limited, so that the code of the first cloud function is recursion detected before the operation of the first cloud function, and when the first cloud function is operated, the resource use condition of the first cloud function is monitored, and the infinite recursion of the cloud function is avoided through double means.
Drawings
FIG. 1 is a flow diagram of a method of infinite recursion detection of a cloud function in one embodiment;
FIG. 2 is a flow diagram of recursive detection of code of a first cloud function in one embodiment;
FIG. 3 is a flow diagram of monitoring resource usage of a first cloud function according to one embodiment;
FIG. 4 is a block diagram of an infinite recursion detection device of a cloud function in one embodiment;
FIG. 5 is a block diagram of an infinite recursion detection system of cloud functions in one embodiment;
FIG. 6 is an internal block diagram of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
With the development of cloud computing technology, the advantages of rapid deployment, elasticity, light weight, low cost and high resource utilization rate of the cloud function make the cloud function a main mode of cloud computing application. The cloud function can be directly released and used on the cloud only by writing codes according to specifications and defining trigger events by a user without concerning how the codes run and stretch. Cloud functions are typically stateless and event-driven cloud services, with specific operating environments and elastic scaling maintained by cloud service providers. The cloud function charges according to the used resources, and is mainly used for real-time processing of files and data.
Because the cloud function is extremely easy to expand and charge according to the usage amount, if the cloud function has infinite recursion, huge bills are extremely easy to be caused due to the characteristics of light weight and infinite expansion, and unexpected burden is brought to users.
Cloud service providers currently do not have restrictions specifically for recursive calls to cloud functions, only emphasis is placed on avoiding recursive calls in cloud functions in the usage specification for the user. Some cloud service providers provide a button that can immediately drop cloud functions to 0 in parallel, but there is no automatic or proactive alert to users that their cloud functions may be infinitely recursive, nor is there an automated mechanism to limit recursive abuse of cloud functions, thus making it extremely easy for users to unexpectedly bill for heavy charges due to code problems.
Based on the above problems, it is necessary to propose an effective technical means for solving the problems. The following describes the technical scheme of the present application and how the technical scheme of the present application solves the above technical problems in detail with specific embodiments. The following embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
In one embodiment, as shown in fig. 1, a flow chart of a method for infinite recursion detection of a cloud function is provided, and the method is applied to a server for explanation, and includes the following steps:
step 101, before running the first cloud function uploaded by the user, recursively detecting codes of the first cloud function to determine whether the first cloud function has infinite recursion.
Where infinite recursion refers to the case where a function recursion invokes itself, failing to reach the recursion base.
Optionally, before running the first cloud function uploaded by the user, precompiling codes of the first cloud function, detecting call parameters of all functions included in the first cloud function, if the call parameters exceed a preset parameter threshold, determining that infinite recursion exists in the first cloud function, and if the call parameters do not exceed the preset parameter threshold, determining that infinite recursion does not exist in the first cloud function.
In another optional embodiment, before the first cloud function uploaded by the user is run, it is detected whether other cloud functions called by the first cloud function call back the first cloud function, if so, it is determined that there is infinite recursion of the first cloud function, and if not, it is determined that there is no infinite recursion of the first cloud function.
In yet another alternative embodiment, before the first cloud function uploaded by the user is executed, pre-compiling codes of the first cloud function, detecting call parameters of each function included in the first cloud function, and detecting whether other cloud functions called by the first cloud function call back the first cloud function according to the call parameters under the condition that the first cloud function is determined to have no infinite recursion, so as to determine whether the first cloud function has infinite recursion.
And 102, if the first cloud function is determined to have no infinite recursion through recursion detection, allowing the first cloud function to operate, monitoring the resource use condition of the first cloud function in the process of operating the first cloud function, and limiting the resource use of the first cloud function under the condition that the resource used by the first cloud function is monitored to meet the resource consumption abnormal condition.
The resources used by the first cloud function comprise at least one of parameters such as CPU (Central Processing Unit ) occupancy rate, memory occupancy size, disk occupancy size, flow and the like. The resource consumption supernormal condition refers to that the resources used by the cloud function exceed a preset limit threshold.
Two cases of determining that the first cloud function does not have infinite recursion through recursion detection exist, one is that in step 101, it is determined that the first cloud function does not have infinite recursion; the second is that if it is determined in step 101 that there is infinite recursion of the first cloud function, prompt information is output to the user, and when indication information that there is no infinite recursion of the first cloud function fed back by the user based on the prompt information is received, it is determined that there is no infinite recursion of the first cloud function.
Optionally, if it is determined through recursion detection that the first cloud function does not have infinite recursion, submitting the first cloud function to a cloud function resource management system, so that the cloud function resource management system triggers the first cloud function according to the event, and manages and provides resources required by the first cloud function.
In the process of running the first cloud function, monitoring resources consumed by the first cloud function in real time, namely resources used by the first cloud function, and if the resources used by the first cloud function exceed a preset limit threshold, or the resources used by the first cloud function are successfully matched with a certain rule in a preset rule base, determining that the resources used by the first cloud function meet the resource consumption abnormal condition. And then calling an API (Application Programming Interface ) of the cloud function resource management system to limit the resource use of the first cloud function, such as at least one of the concurrency number and the CPU occupancy rate of the first cloud function.
In the infinite recursion detection method of the cloud function, before the first cloud function uploaded by the user is operated, recursion detection is performed on the code of the first cloud function to determine whether infinite recursion exists in the first cloud function, if the first cloud function is determined to not exist through the recursion detection, the operation of the first cloud function is allowed, in the process of operating the first cloud function, the resource use condition of the first cloud function is monitored, and when the condition that the resource used by the first cloud function meets the resource consumption abnormal condition is monitored, the resource use of the first cloud function is limited, so that the code of the first cloud function is subjected to recursion detection before the operation of the first cloud function, and when the first cloud function is operated, the resource use condition of the first cloud function is monitored, and the infinite recursion of the cloud function is avoided through a double means.
In one embodiment, recursively detecting code of a first cloud function to determine whether the first cloud function has infinite recursion includes: detecting call parameters of each function included in the first cloud function based on codes of the first cloud function to obtain a first recursion detection result; detecting whether other cloud functions called by the first cloud function call back the first cloud function or not under the condition that the first recursion detection result is that the first cloud function does not have infinite recursion, and obtaining a second recursion detection result; and determining whether the first cloud function has infinite recursion according to the second recursion detection result.
Alternatively, as shown in fig. 2, a schematic flow chart of recursively detecting codes of the first cloud function is provided. The calling parameters comprise the number of calling stack layers, the calling parameters of each function included in the first cloud function are detected, and a first recursion detection result is obtained, wherein the method comprises the following steps: detecting whether the number of call stack layers of each function included in the first cloud function exceeds a preset layer number threshold; if the number of layers exceeds a preset layer threshold, determining that the first recursion detection result is that infinite recursion exists in the first cloud function; and if the number of layers does not exceed the preset layer threshold value, determining that the first recursion detection result is that the first cloud function does not have infinite recursion. The preset layer number threshold may be 1000 layers or 2000 layers, which may be set according to needs, and is not limited herein.
And outputting first result information of the recursion error to a user under the condition that the first recursion detection result is that the first cloud function has infinite recursion.
Detecting whether other cloud functions called by the first cloud function call back the first cloud function under the condition that the first recursion detection result is that the first cloud function does not have infinite recursion, if not, determining that other cloud functions called by the first cloud function under the second recursion detection result do not have callback to the first cloud function; if so, determining that the callback first cloud function exists for other cloud functions called by the first cloud function as a second recursion detection result.
And under the condition that the second recursion detection result is that other cloud functions called by the first cloud function do not have callback to the first cloud function, determining that the first cloud function does not have infinite recursion. And then submitting the first cloud function to a cloud function resource management system, and outputting first result information without recursion errors to a user.
And outputting prompt information to a user under the condition that the second recursion detection result is that other cloud functions called by the first cloud function call back the first cloud function, and determining whether the first cloud function has infinite recursion or not according to the instruction information fed back by the user based on the prompt information.
If the indication information indicates that the first cloud function does not have infinite recursion, submitting the first cloud function to a cloud function resource management system; if the indication information indicates that there is infinite recursion of the first cloud function, execution of the next step, that is, step 102, is ended.
In this embodiment, based on the code of the first cloud function, the call parameters of each function included in the first cloud function are detected to obtain a first recursion detection result, and if the first recursion detection result is that the first cloud function does not have infinite recursion, whether other cloud functions called by the first cloud function call back the first cloud function is detected to obtain a second recursion detection result, and whether the first cloud function has infinite recursion is determined according to the second recursion detection result, so that double detection of the first cloud function before operation is realized, and infinite recursion of the cloud function can be avoided to a great extent by the means, thereby reducing resource waste and huge bills caused by code errors of the first cloud function.
In one embodiment, detecting whether other cloud functions called by the first cloud function call back the first cloud function to obtain a second recursion detection result includes:
step 201, a cloud function call chain of a first cloud function is obtained, wherein a first cloud function in the cloud function call chain is called by the first cloud function, and a non-first cloud function in the cloud function call chain is called by a previous cloud function.
Optionally, searching the cloud function called by the first cloud function, and naming the cloud function as a class 1 associated cloud function; searching the cloud function called by the 1-level associated cloud function, naming the cloud function as a 2-level associated cloud function, and the like until no new associated cloud function exists, or searching the associated cloud function of a preset level, wherein the associated cloud function of the preset level can be a 5-level associated cloud function. The cloud function call chains can be obtained by arranging the associated cloud functions of different levels in sequence.
The cloud functions that the first cloud function may call are plural, and thus, the cloud function call chain of the first cloud function may be plural.
For example, the cloud functions called by the first cloud function have A1 and A2, the cloud functions called by A1 have B1 and B2, the cloud functions called by A2 have B3, the cloud functions called by B1 have C1, the cloud functions called by B2 have C2, the cloud functions called by B3 have C3, neither C1 nor C2 have called cloud functions, the cloud functions called by C3 have D1, and at this time, the cloud function call chain of the first cloud function has A1-B1-C1, A1-B2-C2 and A2-B3-C3-D1.
Step 202, determining whether each cloud function in the cloud function call chain calls back the first cloud function to obtain a second recursion detection result.
Optionally, if it is detected that each cloud function in the cloud function call chain has no callback to the first cloud function, the second recursion detection result is that other cloud functions called by the first cloud function have no callback to the first cloud function; if at least one callback first cloud function exists in each cloud function in the cloud function call chain, the second recursion detection result indicates that callback first cloud functions exist in other cloud functions called by the first cloud function.
And 203, outputting prompt information to a user under the condition that the second recursion detection result indicates that other cloud functions called by the first cloud function call back the first cloud function, and determining whether the first cloud function has infinite recursion according to the instruction information fed back by the user based on the prompt information.
The prompt information may include an identifier of a cloud function call chain that has a callback first cloud function, and the prompt information may further include a code segment that has a cloud function that has a callback first cloud function.
In this embodiment, by acquiring the cloud function call chain of the first cloud function, and then determining whether each cloud function in the cloud function call chain calls back the first cloud function to obtain the second recursion detection result, it is achieved that whether the first cloud function has infinite recursion or not is detected, and then the user is prompted under the condition that the first cloud function has infinite recursion, and infinite recursion of the cloud function can be avoided.
In one embodiment, the method further comprises: matching the monitored resource use condition of the first cloud function with a preset rule base; if the first cloud function is successfully matched with a certain rule in the preset rule base, determining that the resources used by the first cloud function meet the resource consumption abnormal condition.
The rules in the preset rule base include rules such as maximum resource limitation of a cloud function, resource consumption limitation in unit time, suspension time limitation, failure frequency limitation and the like, and the maximum resource limitation of the cloud function includes at least one of CPU occupancy rate limitation, memory occupancy size limitation, disk occupancy size limitation, flow limitation and the like. In addition, the user may customize the rules and modify parameters of the default rules.
And the preset rule base also stores a limiting instruction which is in one-to-one correspondence with the rules and limits the cloud function.
Optionally, as shown in fig. 3, a flowchart of monitoring a resource usage of the first cloud function is provided. In the process of running the first cloud function, monitoring the resource use condition of the first cloud function, judging whether the monitored resource use condition of the first cloud function accords with any rule in a preset rule base, and if not, continuing to execute the step of monitoring the resource use condition of the first cloud function; if so, limiting the resource usage of the first cloud function according to the rule according to the resource usage of the first cloud function, which may be specifically limiting the resource usage of the first cloud function according to the limiting instruction corresponding to the rule according to the resource usage of the first cloud function. And then outputting second result information to the user, wherein the second result information comprises at least one of prompt information for limiting the processing log and abnormal operation of the cloud function, and the second result information can be used for notifying the user through at least one of mail, short message, weChat, telephone and the like.
In this embodiment, the monitored resource usage situation of the first cloud function is matched with the preset rule base, if the monitored resource usage situation of the first cloud function is successfully matched with a certain rule in the preset rule base, it is determined that the resource used by the first cloud function meets the resource consumption abnormal condition, that is, whether the resource used by the first cloud function meets the resource consumption abnormal condition is determined by the rule in the preset rule base, quantitative judgment of the resource situation used by the first cloud function is achieved, and the method has the characteristics of being fast and high in accuracy.
In one embodiment, limiting the resource usage of the first cloud function includes: and limiting the concurrency number of the first cloud function.
Optionally, limiting the concurrency of the first cloud function includes: maintaining the current concurrency number of the first cloud function unchanged; or reducing the concurrency number of the first cloud function to a preset concurrency number threshold.
The preset concurrency threshold may be 0, which may be set as required, and is not limited herein.
Optionally, limiting the concurrency number of the first cloud function according to a rule, if the resource consumption of the first cloud function is greater than a first consumption threshold, which indicates that the resource consumption of the first cloud function is very serious, sending a first concurrency number limiting request to the cloud function resource management system through the API, where the first concurrency number limiting request is used to instruct the cloud function resource management system to reduce the concurrency number of the first cloud function to a preset concurrency number threshold. If the resource consumption of the first cloud function is larger than the second consumption threshold and smaller than the first consumption threshold, the resource consumption of the first cloud function is not serious, and a second concurrency limit request is sent to the cloud function resource management system through the API, and the second concurrency limit request is used for indicating the cloud function resource management system to keep the current concurrency of the first cloud function unchanged.
In this embodiment, only the API of the cloud function resource management system needs to be called, so that the original service is not affected, the code is not required to be modified, the possibility that the user accidentally triggers a huge bill can be greatly reduced, and the user can use the cloud function service more safely.
In summary, the detailed steps of the infinite recursion detection method for realizing the cloud function are as follows:
step 301, before a first cloud function uploaded by a user is operated, detecting whether the number of call stack layers of each function included in the first cloud function exceeds a preset number of layers threshold based on codes of the first cloud function, and if so, determining that a first recursion detection result is that the first cloud function has infinite recursion; and if the number of layers does not exceed the preset layer threshold value, determining that the first recursion detection result is that the first cloud function does not have infinite recursion.
Step 302, acquiring a cloud function call chain of a first cloud function when the first recursion detection result is that the first cloud function does not have infinite recursion, wherein a first cloud function in the cloud function call chain is called by the first cloud function, and a non-first cloud function in the cloud function call chain is called by a previous cloud function; and determining whether each cloud function in the cloud function call chain calls back the first cloud function so as to obtain a second recursion detection result.
Step 303, outputting prompt information to a user under the condition that the second recursion detection result is that other cloud functions called by the first cloud function call back the first cloud function, and determining whether the first cloud function has infinite recursion according to the instruction information fed back by the user based on the prompt information; and under the condition that the second recursion detection result is that other cloud functions called by the first cloud function do not have callback to the first cloud function, determining that the first cloud function does not have infinite recursion.
And step 304, if the first cloud function is determined to have no infinite recursion through recursion detection, allowing the first cloud function to run, and monitoring the resource use condition of the first cloud function in the process of running the first cloud function.
Step 305, matching the monitored resource usage of the first cloud function with a preset rule base; if the first cloud function is successfully matched with a certain rule in the preset rule base, determining that the resources used by the first cloud function meet the resource consumption abnormal condition.
Step 306, maintaining the current concurrency number of the first cloud function unchanged under the condition that the resources used by the first cloud function meet the resource consumption abnormal condition; or reducing the concurrency number of the first cloud function to a preset concurrency number threshold.
It should be understood that, although the steps in the flowcharts of fig. 1-3 are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in fig. 1-3 may include multiple steps or stages that are not necessarily performed at the same time, but may be performed at different times, nor do the order in which the steps or stages are performed necessarily performed in sequence, but may be performed alternately or alternately with at least a portion of the steps or stages in other steps or other steps.
In one embodiment, as shown in fig. 4, there is provided an infinite recursion detection apparatus of a cloud function, the infinite recursion detection apparatus 400 of the cloud function including: a detection module 401 and a monitoring module 402, wherein:
the detection module 401 is configured to recursively detect the code of the first cloud function before running the first cloud function uploaded by the user, so as to determine whether there is infinite recursion of the first cloud function.
And the monitoring module 402 is configured to allow the first cloud function to operate if it is determined by the recursion detection that the first cloud function does not have infinite recursion, monitor a resource usage condition of the first cloud function in a process of operating the first cloud function, and limit the resource usage of the first cloud function when it is monitored that the resource used by the first cloud function meets an abnormal condition of resource consumption.
In one embodiment, the detection module 401 is specifically configured to detect, based on a code of the first cloud function, a call parameter of each function included in the first cloud function, to obtain a first recursive detection result; detecting whether other cloud functions called by the first cloud function call back the first cloud function or not under the condition that the first recursion detection result is that the first cloud function does not have infinite recursion, and obtaining a second recursion detection result; and determining whether the first cloud function has infinite recursion according to the second recursion detection result.
In one embodiment, the call parameter includes a call stack layer number, and the detection module 401 is specifically configured to detect whether the call stack layer number of each function included in the first cloud function exceeds a preset layer number threshold; if the number of layers exceeds a preset layer threshold, determining that the first recursion detection result is that infinite recursion exists in the first cloud function; and if the number of layers does not exceed the preset layer threshold value, determining that the first recursion detection result is that the first cloud function does not have infinite recursion.
In one embodiment, the detection module 401 is specifically configured to obtain a cloud function call chain of a first cloud function, where a first cloud function in the cloud function call chain is called by the first cloud function, and a non-first cloud function in the cloud function call chain is called by a previous cloud function; and determining whether each cloud function in the cloud function call chain calls back the first cloud function so as to obtain a second recursion detection result.
In one embodiment, the detection module 401 is specifically configured to output prompt information to a user when the second recursion detection result indicates that the other cloud functions called by the first cloud function call back the first cloud function, and determine whether the first cloud function has infinite recursion according to the instruction information fed back by the user based on the prompt information; and under the condition that the second recursion detection result is that other cloud functions called by the first cloud function do not have callback to the first cloud function, determining that the first cloud function does not have infinite recursion.
In one embodiment, the monitoring module 402 includes a matching unit, configured to match the monitored resource usage of the first cloud function with a preset rule base; if the first cloud function is successfully matched with a certain rule in the preset rule base, determining that the resources used by the first cloud function meet the resource consumption abnormal condition.
In one embodiment, the monitoring module 402 is specifically configured to limit the concurrency of the first cloud function.
In one embodiment, the monitoring module 402 is specifically configured to maintain the current concurrency number of the first cloud function unchanged; or reducing the concurrency number of the first cloud function to a preset concurrency number threshold.
For a specific definition of the infinite recursion detection device of the cloud function, reference may be made to the definition of the infinite recursion detection method of the cloud function hereinabove, and the description thereof will not be repeated here. The respective modules in the infinite recursion detection device of the cloud function can be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, as shown in fig. 5, there is provided an infinite recursion detection system of a cloud function, the infinite recursion detection system of the cloud function including: the cloud function server comprises a terminal for uploading a first cloud function by a user, an infinite recursion detection device provided with a cloud function resource management system and a cloud function, and a server provided with cloud function services.
The infinite recursion detection device of the cloud function comprises a detection module and a monitoring module, wherein the detection module comprises a code detection unit, a cloud function analysis unit and a cloud function submitting unit; the monitoring module comprises a resource monitoring unit, a matching unit, a limiting processing unit and a notification unit.
The infinite recursion detection system of the cloud function performs the following steps:
in step 501, the code detection unit receives the code of the first cloud function uploaded by the user, detects whether the call stack layer number of each function included in the first cloud function exceeds a preset layer number threshold, if so, determines that the first recursion detection result is that the first cloud function has infinite recursion, and if not, determines that the first recursion detection result is that the first cloud function does not have infinite recursion.
And the cloud function analysis unit acquires a cloud function call chain of the first cloud function under the condition that the first recursion detection result is that the first cloud function does not have infinite recursion, and determines whether each cloud function in the cloud function call chain calls back the first cloud function so as to obtain a second recursion detection result.
In step 502, when the second recursion detection result is that each cloud function in the cloud function call chain of the first cloud function does not have callback to the first cloud function, that is, when the detection is passed, the cloud function submitting unit determines that the first cloud function does not have infinite recursion, and submits the code of the first cloud function to the cloud function resource management system.
In step 503, the cloud function resource management system triggers the first cloud function according to the event.
In step 504, the cloud function service controls to run the first cloud function, so as to implement recursive call of the first cloud function.
In step 505, during the running process of the first cloud function, the resource monitoring unit monitors the resource usage situation of the first cloud function.
And the matching unit matches the monitored resource use condition of the first cloud function with a preset rule base.
And the limiting processing unit is used for limiting the use of the resources of the first cloud function under the condition that the use of the resources of the first cloud function is successfully matched with a certain rule in the preset rule base.
The notification unit outputs information of the abnormality of the detection result to the terminal.
Specific limitations regarding the infinite recursion detection system of the cloud function may be found in the above limitations regarding the infinite recursion detection method of the cloud function, and will not be described in detail herein. The various modules in the infinite recursion detection system of cloud functions described above may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, which may be a server, the internal structure of which may be as shown in fig. 6. The computer device includes a processor, a memory, an Input/Output interface (I/O) and a communication interface. The processor, the memory and the input/output interface are connected through a system bus, and the communication interface is connected to the system bus through the input/output interface. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device is used for storing a plurality of second text vectors and different log types corresponding to the plurality of second text vectors. The input/output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a compiling method.
It will be appreciated by those skilled in the art that the structure shown in FIG. 6 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In one embodiment, a computer device is provided. The computer device comprises a memory storing a computer program and a processor implementing the steps of any of the method embodiments described above when the processor executes the computer program.
In one embodiment, a computer readable storage medium is provided, having stored thereon a computer program which, when executed by a processor, implements the steps of any of the method embodiments described above.
Embodiments of the present application also provide a computer program product comprising instructions which, when run on a computer, cause the computer to perform the steps of any of the method embodiments described above.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, or the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory. By way of illustration, and not limitation, RAM can be in the form of a variety of forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), and the like.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples illustrate only a few embodiments of the application, which are described in detail and are not to be construed as limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of protection of the present application is to be determined by the appended claims.

Claims (12)

1. A method of infinite recursion detection of a cloud function, the method comprising:
before a first cloud function uploaded by a user is operated, recursion detection is carried out on codes of the first cloud function so as to determine whether infinite recursion exists in the first cloud function;
and if the first cloud function is determined to have no infinite recursion through the recursion detection, allowing the first cloud function to operate, monitoring the resource use condition of the first cloud function in the process of operating the first cloud function, and limiting the resource use of the first cloud function under the condition that the resource used by the first cloud function is monitored to meet the resource consumption abnormal condition.
2. The method of claim 1, wherein recursively detecting the code of the first cloud function to determine whether there is infinite recursion of the first cloud function comprises:
detecting call parameters of each function included in the first cloud function based on the codes of the first cloud function to obtain a first recursion detection result;
detecting whether other cloud functions called by the first cloud function call back the first cloud function under the condition that the first recursion detection result is that the first cloud function does not have infinite recursion, and obtaining a second recursion detection result;
and determining whether the first cloud function has infinite recursion according to the second recursion detection result.
3. The method according to claim 2, wherein the call parameters include a call stack layer number, and the detecting call parameters of each function included in the first cloud function, to obtain a first recursive detection result, includes:
detecting whether the number of call stack layers of each function included in the first cloud function exceeds a preset number of layers threshold;
if the number of layers exceeds the preset layer threshold, determining that the first recursion detection result is that infinite recursion exists in the first cloud function;
And if the preset layer number threshold value is not exceeded, determining that the first recursion detection result is that the first cloud function does not have infinite recursion.
4. A method according to claim 3, wherein said detecting whether other cloud functions called by said first cloud function call back said first cloud function, resulting in a second recursive detection result, comprises:
acquiring a cloud function call chain of the first cloud function, wherein a first cloud function in the Yun Hanshu call chain is called by the first cloud function, and a non-first cloud function in the Yun Hanshu call chain is called by a previous cloud function;
determining whether each cloud function in the Yun Hanshu call chain calls back the first cloud function to obtain the second recursion detection result.
5. The method of claim 4, wherein said determining whether there is infinite recursion of the first cloud function based on the second recursion detection result comprises:
outputting prompt information to the user under the condition that the second recursion detection result is that other cloud functions called by the first cloud function call back the first cloud function, and determining whether the first cloud function has infinite recursion according to the instruction information fed back by the user based on the prompt information;
And if the second recursion detection result is that the callback of the first cloud function does not exist in other cloud functions called by the first cloud function, determining that the first cloud function does not have infinite recursion.
6. The method according to any one of claims 1 to 5, further comprising:
matching the monitored resource use condition of the first cloud function with a preset rule base;
and if the first cloud function is successfully matched with a certain rule in the preset rule base, determining that the resources used by the first cloud function meet the resource consumption abnormal condition.
7. The method according to any one of claims 1 to 5, wherein the limiting the resource usage of the first cloud function includes:
and limiting the concurrency number of the first cloud function.
8. The method of claim 7, wherein limiting the concurrency of the first cloud function comprises:
maintaining the current concurrency number of the first cloud function unchanged; or,
and reducing the concurrency number of the first cloud function to a preset concurrency number threshold.
9. An infinite recursion detection apparatus for cloud functions, the apparatus comprising:
The detection module is used for carrying out recursion detection on codes of a first cloud function uploaded by a user before the first cloud function is operated so as to determine whether the first cloud function has infinite recursion;
and the monitoring module is used for allowing the first cloud function to run if the first cloud function is determined to have no infinite recursion through the recursion detection, monitoring the resource use condition of the first cloud function in the process of running the first cloud function, and limiting the resource use of the first cloud function under the condition that the resource used by the first cloud function meets the resource consumption abnormal condition is monitored.
10. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any one of claims 1 to 8 when the computer program is executed.
11. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 8.
12. A computer program product comprising a computer program, characterized in that the computer program, when executed by a processor, implements the steps of the method of any one of claims 1 to 8.
CN202310994769.9A 2023-08-08 2023-08-08 Infinite recursion detection method, apparatus, device and storage medium for cloud function Pending CN117130911A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310994769.9A CN117130911A (en) 2023-08-08 2023-08-08 Infinite recursion detection method, apparatus, device and storage medium for cloud function

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310994769.9A CN117130911A (en) 2023-08-08 2023-08-08 Infinite recursion detection method, apparatus, device and storage medium for cloud function

Publications (1)

Publication Number Publication Date
CN117130911A true CN117130911A (en) 2023-11-28

Family

ID=88859162

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310994769.9A Pending CN117130911A (en) 2023-08-08 2023-08-08 Infinite recursion detection method, apparatus, device and storage medium for cloud function

Country Status (1)

Country Link
CN (1) CN117130911A (en)

Similar Documents

Publication Publication Date Title
CN111817974B (en) Interface current limiting method, device and system based on token bucket and readable storage medium
CN110995825B (en) Intelligent contract issuing method, intelligent node equipment and storage medium
CN113704117B (en) Algorithm testing system, method and device
CN109766198B (en) Stream processing method, device, equipment and computer readable storage medium
CN108111328B (en) Exception handling method and device
CN117130911A (en) Infinite recursion detection method, apparatus, device and storage medium for cloud function
CN115037653B (en) Service flow monitoring method, device, electronic equipment and storage medium
CN114706733B (en) Section program abnormity monitoring method and device
CN113849160B (en) Dynamic migration method and device for compiling tasks, electronic equipment and storage medium
CN115150399A (en) Load balancing method, load balancing device, processing system and storage medium
CN111061576B (en) Method and system for creating entity object
CN114168439A (en) Pressure measurement control method and device for service in cluster, storage medium and terminal
CN101964922B (en) Abnormal condition capturing method and device
CN113590178A (en) API (application program interface) instance management method and device, storage medium and electronic equipment
CN111698266A (en) Service node calling method, device, equipment and readable storage medium
CN111488236A (en) Order abnormity processing method, server, storage medium and processing device
CN111555986B (en) Congestion control method, device and equipment
CN112330453B (en) Intelligent contract calling method, device, equipment and storage medium based on blockchain
CN115242621B (en) Network private line monitoring method, device, equipment and computer readable storage medium
CN110119314B (en) Server calling method and device, server and storage medium
CN116909835A (en) Monitoring alarm method, device, equipment and storage medium for business system
CN105138346A (en) Application installation method and device
CN115499492A (en) Application service exception handling method, device, equipment and readable storage medium
CN116820719A (en) Process fusing method and device, computer equipment and storage medium
CN117130979A (en) Service resource migration method and device and electronic equipment

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