CN115408079A - Function execution method, device, equipment and storage medium based on state machine - Google Patents

Function execution method, device, equipment and storage medium based on state machine Download PDF

Info

Publication number
CN115408079A
CN115408079A CN202110577584.9A CN202110577584A CN115408079A CN 115408079 A CN115408079 A CN 115408079A CN 202110577584 A CN202110577584 A CN 202110577584A CN 115408079 A CN115408079 A CN 115408079A
Authority
CN
China
Prior art keywords
function
server
state
workflow
node
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
CN202110577584.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.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen 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 Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN202110577584.9A priority Critical patent/CN115408079A/en
Publication of CN115408079A publication Critical patent/CN115408079A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4498Finite state machines
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30003Arrangements for executing specific machine instructions
    • G06F9/3005Arrangements for executing specific machine instructions to perform operations for flow control

Abstract

The application discloses a function obtaining method, a function obtaining device and a function obtaining storage medium based on a state machine, which relate to the field of cloud computing and comprise the following steps: the method comprises the steps of obtaining a first state function of a first state node and a second state function of a second state node in a state machine, wherein the state machine comprises at least two state nodes, and the first state node is a previous state node adjacent to the second state node. And acquiring the output result type of the first state node and the input data type of the second state node according to the first state function and the second state function. And constructing a third state node, wherein the third state node is positioned between the first state node and the second state node and is used for executing the workflow function script which is used for converting the output result type into the input data type. And executing the first state function, the workflow function script and the second state function in sequence.

Description

Function execution method, device, equipment and storage medium based on state machine
Technical Field
The present application relates to the field of cloud computing, and in particular, to a method, an apparatus, a device, and a storage medium for function acquisition based on a state machine.
Background
The state machine is a control center which is composed of a state register and a combinational logic circuit, can carry out state transition according to a preset state according to a control signal, coordinates relative signal actions and completes specific operations. The state machine comprises a plurality of state nodes, the state types of each state node are different, wherein the task type is the most common state type, is used for executing or calling related services and corresponds to an operation function.
The state machine executes response operation according to the input and transmits the output to the next state, so that for two adjacent state nodes, the output of the previous node is used as the input of the next node, and because the function types corresponding to different state nodes are different, the condition that the type of the output result of the previous node cannot be matched with the type of the next node occurs.
In order to ensure the normal operation of the state machine, generally, a function of a previous node needs to be designed according to an input type of an operation function corresponding to a next node, and the output result type of the previous node is ensured to be just consistent with the input type of the next node; therefore, the relevance of the nodes in the state machine is extremely high, and when a certain node fails, functions corresponding to all the state nodes need to be modified, so that the performance of the state machine is greatly influenced.
Disclosure of Invention
The embodiment of the application provides a function obtaining method, a function obtaining device and a function obtaining storage medium based on a state machine.
In view of the above, an aspect of the present application provides a method for executing a function based on a state machine, including:
the method comprises the steps of obtaining a first state function of a first state node and a second state function of a second state node in a state machine, wherein the state machine comprises at least two state nodes, and the first state node is a previous state node adjacent to the second state node.
And acquiring the output result type of the first state node and the input data type of the second state node according to the first state function and the second state function.
And constructing a third state node, wherein the third state node is positioned between the first state node and the second state node and is used for executing the workflow function script which is used for converting the output result type into the input data type.
And executing the first state function, the workflow function script and the second state function in sequence.
Another aspect of the present application provides a function execution apparatus based on a state machine, including:
the state machine comprises at least two state nodes, and the first state node is a previous state node adjacent to the second state node.
And the acquisition unit is further used for acquiring the output result type of the first state node and the input data type of the second state node according to the first state function and the second state function.
And the processing unit is used for constructing a third state node, the third state node is positioned between the first state node and the second state node, the third state node is used for executing a workflow function script, and the workflow function script is used for converting the output result type into the input data type.
And the execution unit is used for sequentially executing the first state function, the workflow function script and the second state function.
In one possible design, the apparatus further includes a receiving unit configured to receive, by the control server, a function registration request for registering the workflow function, where the workflow function includes a workflow function script.
And the acquisition unit is also used for responding to the function registration request through the control server and acquiring the working server corresponding to the control server.
And the processing unit is also used for distributing the work servers corresponding to the control servers for the workflow function through the control servers and determining the target work servers in the work servers corresponding to the control servers.
And the execution unit is also used for indicating the target work server to register the workflow function, and the target work server is used for executing the workflow function according to the function calling instruction.
In a possible design, the receiving unit is further configured to receive, by the control server, first indication information sent by the work server, where the first indication information is used to periodically report the survival status of the work server to the control server.
And the processing unit is specifically used for determining that the work server is the work server corresponding to the control server if the control server receives the first indication information sent by the work server. And if the control server does not receive the first indication information sent by the working server within the preset time period, determining that the working server is not the working server corresponding to the control server.
In a possible design, the processing unit is specifically configured to determine that all the work servers corresponding to the control server are the target work servers if the number of the work servers corresponding to the control server is smaller than a preset threshold. And if the number of the working servers corresponding to the control server is greater than or equal to the preset threshold value, determining a target working server in the working servers corresponding to the control server according to the function weight value of the workflow function.
In one possible design, the processing unit is specifically configured to obtain a function weight value of the workflow function through the control server, determine a distribution number according to the function weight value, determine a priority level of a work server corresponding to the control server according to a load condition of the work server corresponding to the control server, and determine a target work server in the work servers corresponding to the control server according to the distribution number and the priority level.
In a possible design, the receiving unit is further configured to receive a function call instruction regarding the workflow function after the target work server registers the workflow function.
And the acquisition unit is also used for responding to the function call instruction and acquiring a plurality of target work servers registered with the workflow function.
And the processing unit is also used for determining a first server in the plurality of target working servers according to the execution strategy.
And the execution unit is further used for controlling the first server to execute the workflow function according to the network address of the first server acquired by the acquisition unit.
In a possible implementation manner, the processing unit is specifically configured to perform a polling operation on a plurality of target work servers, and determine the first server according to a polling result. Or acquiring first identifications of the plurality of target work servers, determining hash values respectively corresponding to the plurality of target work servers according to the first identifications of the plurality of target work servers, and determining a first server of the plurality of target work servers according to the consistent hash algorithm and the hash values respectively corresponding to the plurality of target work servers.
Another aspect of the present application provides a computer-readable storage medium having stored therein instructions, which when executed on a computer, cause the computer to perform the method of the above-described aspects.
According to the technical scheme, the embodiment of the application has the following advantages:
in the embodiment of the application, a function execution method based on a state machine is provided, the state functions corresponding to two adjacent state nodes of the state machine are firstly obtained, then a workflow function script for type conversion is designed according to the output result type of the previous node and the input data type of the next node, the workflow function is finally obtained to assist the state transfer of the state machine, and then the functions corresponding to the three nodes are sequentially executed.
Drawings
Fig. 1 is a schematic structural diagram of a state machine according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of a method for executing a function based on a state machine according to an embodiment of the present application;
fig. 3A is a schematic structural diagram of an original state machine according to an embodiment of the present application;
fig. 3B is a schematic structural diagram of a new state machine according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an operation interface of a state machine template according to an embodiment of the present disclosure;
fig. 5 is a schematic structural diagram of a function script configuration interface according to an embodiment of the present disclosure;
fig. 6 is a system architecture diagram of a function registration system according to an embodiment of the present application;
fig. 7 is a schematic flowchart of a method for registering and calling a workflow function according to an embodiment of the present application;
fig. 8 is a schematic structural diagram of a workflow function registration system according to an embodiment of the present application;
fig. 9 is a schematic structural diagram of a function execution apparatus based on a state machine according to an embodiment of the present application;
fig. 10 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
The embodiment of the application provides a function obtaining method, a function obtaining device and a function obtaining storage medium based on a state machine.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims of the present application and in the drawings described above, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "corresponding" and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
The state machine is composed of a state register and a combinational logic circuit, and can perform state transition according to a preset state according to a control signal, namely the state machine is a control center which coordinates related signal actions and completes specific operations. One exact description of a state machine is: it is a directed graph, consisting of a set of nodes and a set of corresponding state functions. The state machine begins to run by responding to a series of events. Each event is within the control range of a state function belonging to the current node, where the range of the function is a subset of the nodes. The function returns the "next" (perhaps the same) node. At least one of the nodes must be in a final state, and the state machine stops when the final state is reached.
Wherein the state machine comprises a computational model comprising a set of state sets (states), a start state (start state), a set of input symbols (alphabet), a transformation function (transformation function) mapping input symbols and current state to next state. When a symbol string is input, the state machine then enters an initial state and then realizes the state transition depending on the state function corresponding to each node. The control flow of the state machine basically follows preset logic and is executed from beginning to end. Few events can change the standard execution flow.
Fig. 1 is a schematic structural diagram of a state machine according to an embodiment of the present application, and as can be seen from fig. 1, the state machine is a model for describing a finite number of states and behaviors such as transitions and actions between the states. Each node corresponds to an action, each node also corresponds to a function service, and when the state is transferred to one node, the node can call the corresponding state function of the node, execute the related action, and then transfer to the next node to continue executing the action of the next node until the end.
The types of the state nodes are various, and exemplary types include task, pass, wait, choice, parallel, foreach and the like; the task type is the most common state and is used to describe performing some tasks, such as executing local scripts, invoking various cloud services, and the like. That is, function services are corresponding to the state nodes of the task type, and the state machine needs to sequentially execute the function services corresponding to the state nodes of the task type according to the node sequence.
For a certain task, the state machine can control the execution flow of the task, that is, each node in the state machine is associated with each other, and since the output of the previous node is the input of the next node, in order to ensure the state transition of the state machine, it is necessary to control the type of the output result of the previous node to exactly match the input of the state function corresponding to the next node, otherwise, the state machine will stop running due to the problem of non-adaptation. In the prior art, the internal structure of the state machine needs to be designed accurately according to tasks, a state function corresponding to a subsequent node is completely limited by the type of the state function corresponding to a previous node, the state functions corresponding to two adjacent nodes in the state machine are designed in a mutually matched manner, and the coupling is extremely high.
However, the high-coupling state node design cannot meet the requirement of an atomic service, which means a service that cannot be decomposed into finer granularity, and has higher stability as a minimum unit of service. In the above state machine, if the function type corresponding to a certain node in the state machine changes, the function type will be interrupted in both the previous node and the next node, the state machine cannot be normally executed, and to ensure the normal operation of the state machine, the state functions of all nodes need to be adjusted in coordination with the function type of the new node. The high coupling property is a huge maintenance workload of the state machine, and the performance of the state machine is seriously influenced, so how to realize the decoupling of each state node of the state machine and ensure the independence of each state node becomes a problem to be solved urgently.
Based on the above description, the present application provides a function obtaining method based on a state machine, when a state machine based on a certain task is obtained, a workflow function is designed according to state functions corresponding to two adjacent state nodes, and the workflow function is used for completing data type conversion between the two adjacent nodes and assisting state transfer between the nodes of the state machine, so that each state node in the state machine can be decoupled, and independence of each state node is maintained.
Before introducing the scheme of the present application, since the embodiments of the present application are implemented based on a cloud computing technology, cloud computing is introduced first below. Cloud computing (cloud computing) is a computing model that distributes computing tasks over a pool of resources formed by a large number of computers, enabling various application systems to obtain computing power, storage space, and information services as needed. The network that provides the resources is called the "cloud". Resources in the "cloud" appear to the user as being infinitely expandable and available at any time, available on demand, expandable at any time, and paid for on-demand.
As a basic capability provider of cloud computing, a cloud computing resource pool (called as an ifas (Infrastructure as a Service) platform for short is established, and multiple types of virtual resources are deployed in the resource pool and are selectively used by external clients.
According to the logic function division, a PaaS (Platform as a Service) layer can be deployed on an IaaS (Infrastructure as a Service) layer, a SaaS (Software as a Service) layer is deployed on the PaaS layer, and the SaaS can be directly deployed on the IaaS. PaaS is a platform on which software runs, such as a database, a web container, etc. SaaS is a variety of business software, such as web portal, sms, and mass texting. Generally speaking, saaS and PaaS are upper layers relative to IaaS.
Fig. 2 is a schematic flowchart of a method for executing a function based on a state machine according to an embodiment of the present application, and as shown in fig. 2, the method includes the following steps:
201. a first state function of a first state node and a second state function of a second state node in a state machine are obtained.
When a state machine for a certain task is obtained, the structure of the state machine is firstly analyzed, and state functions of two original adjacent state nodes are sequentially obtained. For example, the state function corresponding to the previous state node may be labeled as a first state function, and the state function corresponding to the next state node may be labeled as a second state function. The state machine is then redesigned by analyzing the function types of the first state function and the second state function.
202. And acquiring the output result type of the first state node and the input data type of the second state node according to the first state function and the second state function.
Specifically, an output result type corresponding to the first state function and an output data type of the second state function need to be obtained, and then a workflow function script for type conversion is designed according to the output result type and the input data type, wherein the workflow function script has a function of realizing type conversion, namely, is used for matching the first state node and the second state node. Therefore, the first state node and the second state node can be decoupled, so that two adjacent nodes in the state machine are relatively independent, and even if the function type corresponding to the first state node is changed, the corresponding workflow function script is only required to be modified, and the conversion between the new output result type output by the new function and the input data type of the next node is completed. The working efficiency of the state machine is improved.
203. And constructing a third state node, and designing a corresponding workflow function script for the third state node.
Specifically, a state node may be inserted between two adjacent nodes of the state machine, where the state node is used to execute a workflow function script, that is, the state of the state machine is transferred to the first state node, after the first state function is executed, a workflow function script corresponding to the third state node is executed first, and after the workflow function script converts the output result type corresponding to the first state function into the input data type corresponding to the second state function, the workflow function script is transferred to the second state node to execute the second state function.
The type conversion may include various forms, for example, the output result of the first state function is a floating point number, and the second state function requires the input data to be an integer number, so that the function of the workflow function script between the first state node and the second state node is to convert the floating point number into the integer number.
Illustratively, the output result of the first state function is matrix data, and the input data is required to be vector data by the second state function, so that the function of the workflow function script between the first state node and the second state node is to split the matrix data into a plurality of vector data.
Illustratively, the output result of the first state function is large-size picture data, and the second state function requires fixed-size picture data, so that the function of the workflow function script between the first state node and the second state node is to implement picture clipping, and the output result of the first state function is clipped according to the fixed size of the second state function.
204. And determining the workflow function according to the workflow function script.
After the workflow function scripts between each pair of adjacent nodes are determined, a plurality of workflow function scripts can be combined to obtain the workflow function. The workflow function can realize a complete workflow function, and realize processes of compiling, calculating and the like of input variables. When the state machine is started, the workflow function is executed immediately, and the state transition in the state machine is assisted.
205. And executing the first state function, the workflow function script and the second state function in sequence according to the workflow function.
Specifically, after a new state machine structure is constructed, state functions of related nodes need to be sequentially executed according to the new state machine structure, that is, a first state function, a workflow function script and a second state function need to be sequentially executed to realize state transition and ensure normal operation of the state machine.
Based on the description of the above embodiment, fig. 3A provides a schematic structural diagram of an original state machine, as shown in fig. 3A, the state machine is in a string-type structure, and the state transition direction is from a general camera to face priority service, then to face attribute identification, face feature storage, face retrieval, ID conversion service, and then to result storage. Each node corresponds to one function service, and if the serial structure design is directly performed, the function service of each node needs to be designed in a relevance manner, which results in high difficulty, complex design and high stability of function design.
In the embodiment of the present application, it is necessary to analyze input and output of a state function corresponding to an adjacent node, design a workflow function script for type conversion, add a new node to a structure of an original state machine, as shown in fig. 3B, and associate the new node with the workflow function script, so that, during a state transition process of the state machine, first sequentially execute function services in the original node, then output a function execution result, and then, before executing a next original node, first execute a section of workflow function script to convert an output result type of a previous node into a function type conforming to input data of the next node. Therefore, the decoupling between two adjacent nodes in the original state machine can be realized, so that the latter node is not limited by the state function type of the former node. Therefore, when the state function corresponding to a certain node in the original state machine is changed, the normal operation of the state machine can be realized only by modifying the function flow working script corresponding to the node, and other nodes do not need to be modified.
In the embodiment of the application, a function execution method based on a state machine is provided, the state functions corresponding to two adjacent state nodes of the state machine are firstly obtained, then a workflow function script for type conversion is designed according to the output result type of the previous node and the input data type of the next node, the workflow function is finally obtained to assist the state transfer of the state machine, and then the functions corresponding to the three nodes are sequentially executed.
Based on the above description, in the embodiment of the present application, a new state node needs to be inserted into two state nodes to execute a workflow function script, for example, a user may input the whole process of a state machine through a presentation interface provided by a computer, the computer generates each node of the state machine according to the received state machine process, and controls the execution of the state machine, specifically, the whole process of the state machine is described through a language such as Json or Yaml format, and becomes a state machine template, which may be formulated by the user, fig. 4 is a state machine template operation interface provided by the embodiment of the present application, where a toolbar includes various components, and the template layout bar is used to receive a user operation and present a state machine process. The user may insert a new step node in the flowchart and determine the specific action that the step node needs to perform.
After a user inserts a new step node into the above state machine template operation interface, the function script corresponding to the step node may be configured, for example, the function script configuration interface shown in fig. 5 may be displayed by selecting the newly inserted step node in a manner of double-click, and the like, where the function script configuration interface may include a script name, a script type, a code input interface, and the like. The script name is used to define the function script corresponding to the step node, and the script type may include a selection button of the corresponding formula script or the stream mode script. The response type script is a function requesting a response calling mode, and the stream mode script refers to a stream type response function, namely a stream type long link, namely the function can continuously send data to a downstream node of the state machine. And the code input interface is used for inputting specific function codes. Through the function script configuration interface, the required function script can be designed for the new node so as to complete the adaptation between the nodes.
Based on the above embodiment, after a plurality of function scripts are designed through a plurality of interfaces, a workflow function corresponding to a state machine needs to be combined according to the plurality of function scripts, and finally, the workflow function needs to be registered and controlled to be normally used, and a registration process of the workflow function is described in detail below.
Fig. 6 is a system architecture diagram of a function registration system according to an embodiment of the present application, where as shown in fig. 6, the function registration system includes an access stratum and a registration stratum. The access layer comprises a network gateway and is mainly used for receiving the function registration request and sending the function registration request to the registration layer.
The registration layer can be divided into a function service control layer, a function service routing layer and a function service execution layer. The function service control layer comprises a control server, and the control server is used for responding to the function registration request, determining a work server for executing function registration according to the strategy, and controlling the registration process of the work server. The function service execution layer comprises a working server which is used for executing a specific function registration process and providing function services of registered functions to the outside, and when receiving a function call command sent by the outside, the function service execution layer executes the registered functions. The function service routing layer comprises a routing server, specifically, a routing address of a work server which wants to control the server to request about the registered function according to the function call command, then, the specific work server is determined according to the routing address, and the work server is instructed to execute the registered function.
In the embodiment of the present application, the established workflow function needs to be registered and executed. Specifically, the gateway needs to send a workflow function registration request to the control server, and then the control server responds to the workflow function registration request, obtains information of a plurality of work servers under the control of the control server, and then selects at least one work server according to a relevant policy to register the workflow function, and establishes a corresponding relationship between the workflow function and the work servers. When the gateway receives a workflow function call instruction, the routing server sends a query request to the control server to acquire routing information of the work servers registered with the workflow function, and if the plurality of work servers are all registered with the workflow function, the routing server needs to screen the plurality of work servers, determine a final target work server, and instruct the execution unit to call the target work server, so that the target work server executes the workflow function.
With reference to the system architecture diagram shown in fig. 6, the following describes in detail a registration execution flow of a workflow function, and as shown in fig. 7, a flow diagram of a method for registering and calling a workflow function provided in an embodiment of the present application includes:
701. the work server sends first indication information to the control server.
Generally, a control server can control the work flows of a plurality of work servers, and the control server needs to judge the connection state with the work servers according to a heartbeat test. For example, the work server may be configured to periodically send the first indication information to the control server, for example, the work server may send a heartbeat signal to the control server every second, so that the control server may monitor the heartbeat signal to determine the connection status of the control server and the work server.
702. The control server judges whether the first indication information is received in a preset time period.
Based on the above description, the control server may preset a fixed time period in advance, and when the control server can receive the first indication information sent by the work server at least once within the preset time period, it is determined that the connection between the control server and the work server is normal. If the control server does not receive the first indication information sent by a certain working server all the time within a preset time period, it can be determined that the connection between the control server and the working server is abnormal, so that the control server can reject the connection between the control server and the working server, and can also enter a protection stage, further detect the connection state between the control server and the working server, and determine whether to reject the working server according to the detection result, without limitation.
703. And the control server determines a working server corresponding to the control server in the working servers according to the judgment result.
In the above example, the control server may preset the detection time period (preset time period) to be 15s, and if the control server does not receive a piece of first indication information from the work server within 15s, the control server may determine that a problem occurs in connection with the work server, and further may determine that the work server is not a work server corresponding to the control server, and conversely, as long as every 15s can ensure that the control server receives at least one piece of first indication information, the control server may determine that the work server is a work server corresponding to the control server.
For example, the first indication information may include an ID of the work server, and an operation state of the work server, such as a load condition of the work server and a data processing capability of the work server, and the control server determines the work server according to the first indication information, so as to control the operation state of the work server subsequently.
704. And the control server distributes a work server corresponding to the control server for the workflow function and determines a target work server.
After the control server determines the work servers which can be controlled by the control server, the control server also needs to determine a specific target work server according to the running condition of the work servers to register the workflow function. For example, the control server may obtain load operation conditions of a plurality of work servers, and then determine one or more work servers with lighter loads as target work servers; for example, the control server may further obtain data processing capabilities of the plurality of work servers, and determine one or more work servers with strong data processing capabilities as target work servers; for example, the control server may further obtain the sizes of the storage spaces of the plurality of work servers, and determine one or more work servers with larger storage spaces as target work servers, which is not limited specifically.
For example, the control server needs to determine the number of servers of the work servers that can be controlled, and if the number of servers of the work servers that can be controlled by the control server is less than 2, it needs to determine that all the work servers that can be controlled by the control server are the target work servers. If the number of the servers of the work servers which can be controlled by the control server is large, the priority of each work server can be determined according to the strategy, and a preset number of work servers are taken as target work servers according to the priority sequence, so that the aim of ensuring that the plurality of target work servers realize the registration of the workflow function is fulfilled, and the condition that the execution of the workflow function is interrupted due to the damage of the target work servers is avoided.
705. And receiving a workflow function registration request sent by the gateway.
Specifically, after receiving a workflow function created by a user, a server needs to send a workflow function registration request to a control server through a gateway, where the workflow function registration request is used to request the control server to register and execute a workflow function for the workflow function, and after receiving the workflow function registration request, the control server needs to start a workflow server selection process to allocate a target workflow server for the workflow function according to a certain policy.
706. And the control server sends an instruction command to the target work server.
After the control server receives a workflow function request sent by the gateway, the control server needs to respond to the workflow function request first, and at least one target work server is selected for the workflow function in a plurality of work servers under the control of the control server to execute the workflow function.
For example, the control server may obtain load information of a plurality of servers controlled by the control server, and select a target work server among the plurality of servers according to a load condition of the work server, for example, one or more servers with a lighter load may be selected as a target work server corresponding to the workflow function.
For example, the control server may obtain storage conditions of a plurality of servers controlled by the control server, and select a target work server among the servers according to the size of the available storage space of the work server, for example, one or more servers with large available storage spaces may be selected as a target work server corresponding to the workflow function, so as to ensure the registration success rate of the workflow function.
For example, one or more servers of the operation rate block can be selected as the target work server corresponding to the workflow function, so as to avoid the karton phenomenon when the workflow function is executed.
It is to be understood that the control server may also select the target work server according to other policies, such as a combination of the above cases, and the like, which is not limited herein.
For example, if the task priority of the state machine corresponding to the workflow function is higher, the workflow function is registered only on one target work server, and it is likely that the function operation is interrupted due to a line problem. Therefore, the number of the target work servers can be increased, so that the plurality of target work servers are all registered with the workflow function, and therefore, when one target work server is interrupted, other target work servers can be called to execute the workflow function, stable operation of the workflow function is guaranteed, and execution efficiency of the workflow function is improved.
For example, a preset threshold may be determined in advance according to the importance of the task in the state machine, for example, the preset threshold is 3, which indicates that at least 3 target work servers are to register the workflow function. If the number of the work servers corresponding to the controller is greater than 3, 3 target work servers need to be selected from the plurality of work servers according to the description, and if the number of the work servers corresponding to the control server is less than 3, the number of the target work servers needs to be increased as much as possible, that is, all the work servers corresponding to the control server can be determined as the target work servers, so that the workflow function is registered on all the target work servers.
Based on the above description, fig. 8 is a schematic structural diagram of a workflow function registration system provided in an embodiment of the present application, and as shown in fig. 8, the system includes a gateway, a control server, a storage, and a work server.
The gateway is configured to provide a gateway service, receive a function registration request of a workflow function, where the function registration request may include a code corresponding to the workflow function, and may instruct the control server to allocate a work server to the workflow function, and register the workflow function through the work server.
The control server comprises three modules, namely a registration function module, a management logic module and a repair logic module; the registration function module is used for controlling the work server to register the workflow function, specifically, heartbeat signals sent by the work server can be monitored, when the heartbeat signals sent by the work server can be detected in a continuous preset time period, the work server can be determined to be the work server which can be controlled by the control server, and then a target work server in the work server is selected according to a relevant strategy to complete the registration of the workflow function.
The management logic module is used to manage the relationship between the registered workflow function and the target work server, for example, the control server controls a plurality of target work servers to register the workflow function, after the workflow function is registered, the management logic module can establish a corresponding relationship table between the workflow function and the target work server, and maintain the corresponding relationship table according to the heartbeat signal.
For example, after the repair logic module finds that a heartbeat signal of a certain target work server cannot be detected, it may be determined that the target work server and the control server are interrupted, and the target work server cannot execute and interact with the execution unit even though a workflow function has been registered, so that a corresponding relationship between the target work server and the workflow function needs to be removed, and meanwhile, the registration logic module requests the registration function module to reallocate a new target work server for the workflow function based on a relevant policy, and registration and execution of the workflow function are completed through the new target work server.
The work server comprises a heartbeat testing module, a registration function module and an execution logic module, wherein the heartbeat testing module is used for periodically sending heartbeat signals to the control server, so that the control signals can monitor the connection state between the control server and the work server according to the heartbeat signals. The register function module is used for receiving the instruction sent by the control server, completing the register process of the work server according to the instruction and providing a necessary execution environment for the workflow function. The execution logic module is used for receiving the function call instruction sent by the execution unit, executing the workflow function according to the function call instruction, and sending an execution result to the execution unit.
After the control server determines a target work server for registering the workflow function based on the above policy, it needs to send an instruction command to the target work server to instruct the target work server to complete the registration process of the workflow function, and control the target work server to execute the workflow function.
707. And the target work server registers the workflow function according to the instruction command.
Specifically, after the target job server receives the instruction command, the workflow function needs to be registered according to the instruction command. And after receiving the call instruction, starting a workflow function execution flow according to the call instruction, and inputting an execution result into the original state machine.
708. And the execution unit sends a workflow function calling instruction to the routing server.
After the registration of the workflow function is completed, the workflow function needs to be used, specifically, the execution unit may obtain an execution result of the workflow function by calling the work server, and then complete the state transition in the state machine according to the execution result. As can be known from the above description, the workflow function is executed by the target work server, and is different from the execution unit that executes the steps of the state machine, so to implement the call of the target work server, the routing server is required to perform routing, and the execution result of the target work server is obtained through the routing server.
The execution unit needs to send a workflow function call instruction to the routing server, and then the routing server performs routing, so that the execution unit calls a target work server to execute the workflow function according to a routing result of the routing server, and the execution unit can obtain an execution result of the workflow function according to the routing result, and complete state transition in the state machine according to the execution result.
709. And the routing server responds to the workflow function call instruction and sends a query instruction to the control server.
The router responds to the workflow function call instruction and starts a routing process, firstly, the routing server needs to acquire information of a target work server registered with the workflow function from the control server, and then a first server for finally executing the workflow function is determined according to the information. Specifically, the routing server may send a query instruction to the control server, which requests the control server to send information of all target work servers to the routing server.
710. And the control server sends the target work server information to the routing server according to the query instruction.
It is understood that the control server may maintain a table about the target work servers, for example, the control server may determine a table about a target work server for a workflow function after controlling a plurality of target work servers to register the workflow function. For example, the target work server table may include an identifier of the workflow function, and identifiers, network addresses, running states, and the like corresponding to the plurality of target work servers, which is not limited specifically.
When the routing server sends the query instruction to the control server, the query instruction may carry an identifier of the workflow function, so that the control server may determine a target server table corresponding to the workflow function according to the identifier, and send information of each target server carried in the target server table to the routing server, so that the routing server determines a first server to be finally called according to the information of each target server.
711. And the routing server determines a first server according to the target work server information.
There are various methods for selecting the first server by the routing server, and in an alternative embodiment, the routing server may perform a polling operation on a plurality of target servers, and determine the first server according to a polling result. That is, the routing server may determine the first server in the order of the target servers, for example, when the execution unit sends the workflow function call instruction for the first time, the routing server may determine that the target work server a is the first server to execute the workflow function. When the execution unit sends the workflow function call instruction for the second time, the routing server may determine that the next adjacent target work server B of the target work server a is the first server, and execute the workflow function.
In an optional embodiment, the first server of the target work servers may also be determined according to a consistent hashing algorithm. The process of the consistent hash algorithm is specifically that first, first identifiers of a plurality of target work servers are obtained, then hash values corresponding to the first identifiers of the target work servers are calculated respectively, and the hash values are configured on a circle with a fixed size. And then, calculating a hash value corresponding to the identification of the routing server by adopting the same method, and mapping the hash value to the circle, so that each target work server and the routing server have a corresponding position on the circle, then, starting from the position corresponding to the routing server, clockwise searching, and when meeting the first target work server, determining the target work server as the first server to execute the workflow function.
In an optional embodiment, the routing server may further randomly select a target working server as the first server, and a specific routing method is not limited.
712. The routing server sends the first server information to the execution unit.
After the routing server determines a first server in the target working server, the information corresponding to the first server needs to be sent to the execution unit, so that the execution unit can complete the call of the first server, instruct the first server to run the workflow function, and acquire the execution result of the workflow function from the first server.
For example, the first server information may include an identifier of the first server and a network address of the first server, and when the execution unit receives the first server information, the execution unit may send a call instruction to the first server according to the network address of the first server, where the call instruction may be used to instruct the first server to specifically execute a certain code in the workflow function, and when the first server finishes executing, send an execution result to the execution unit.
713. The execution unit invokes the first server.
Specifically, the execution unit may call the first server according to the address of the first server sent by the routing server, and instruct the first server to execute the workflow function.
714. The first server executes the workflow function and sends an execution result to the execution unit.
After receiving the call instruction sent by the execution unit, the first server starts the workflow function execution flow and sends the execution result to the execution unit, so that the execution unit can complete state transition in the state machine according to the execution result and transfer from the first state node to the second state node, and the adaptation of the first state node and the second state node is completed.
Based on the above description, this embodiment provides a method for executing a workflow function by registration, where the workflow function can be registered through the above process, and an execution unit can call a target work server registered with the workflow function to obtain an execution result, and complete state transition in a state machine according to the execution result, and the execution flow by registration can ensure stable operation of the workflow function, provide a complete execution environment for the workflow function, and improve execution efficiency and stability of the workflow function.
Fig. 9 is a schematic structural diagram of a function execution device based on a state machine according to an embodiment of the present application, and as shown in fig. 9, the function execution device includes:
an obtaining unit 901, configured to obtain a first state function of a first state node and a second state function of a second state node in a state machine, where the state machine includes at least two state nodes, and the first state node is a previous state node adjacent to the second state node.
The obtaining unit 901 is further configured to obtain an output result type of the first state node and an input data type of the second state node according to the first state function and the second state function.
The processing unit 902 is configured to construct a third state node, where the third state node is located between the first state node and the second state node, and the third state node is configured to execute a workflow function script, where the workflow function script is configured to convert an output result type into an input data type.
The execution unit 903 is configured to sequentially execute the first state function, the workflow function script, and the second state function.
In one possible design, the apparatus further includes a receiving unit 904, where the receiving unit 904 is configured to receive, by the control server, a function registration request, where the function registration request is configured to register a workflow function, and the workflow function includes a workflow function script.
The obtaining unit 901 is further configured to obtain a work server corresponding to the control server by the control server responding to the function registration request.
The processing unit 902 is further configured to allocate, by the control server, a work server corresponding to the control server for the workflow function, and determine a target work server in the work servers corresponding to the control server.
The executing unit 903 is further configured to instruct the target work server to register the workflow function, and the target work server is configured to execute the workflow function according to the function call instruction.
In a possible design, the receiving unit 904 is further configured to receive, by the control server, first indication information sent by the work server, where the first indication information is used to periodically report the survival status of the work server to the control server.
The processing unit 902 is specifically configured to determine that the work server is the work server corresponding to the control server if the control server receives the first indication information sent by the work server. And if the control server does not receive the first indication information sent by the working server within the preset time period, determining that the working server is not the working server corresponding to the control server.
In a possible design, the processing unit 902 is specifically configured to determine all the work servers corresponding to the control server as target work servers if the number of the work servers corresponding to the control server is smaller than a preset threshold. And if the number of the working servers corresponding to the control server is greater than or equal to the preset threshold value, determining a target working server in the working servers corresponding to the control server according to the function weight value of the workflow function.
In a possible design, the processing unit 902 is specifically configured to obtain a function weight value of a workflow function through a control server, determine a distribution number according to the function weight value, determine a priority level of a work server corresponding to the control server according to a load condition of the work server corresponding to the control server, and determine a target work server in the work servers corresponding to the control server according to the distribution number and the priority level.
In a possible design, the receiving unit 904 is further configured to receive a function call instruction regarding the workflow function after the target work server registers the workflow function.
The obtaining unit 901 is further configured to obtain, in response to the function call instruction, a plurality of target work servers in which the workflow function is registered.
The processing unit 902 is further configured to determine a first server of the plurality of target working servers according to the execution policy.
The executing unit 903 is further configured to control the first server to execute the workflow function according to the network address of the first server acquired by the acquiring unit.
In a possible implementation manner, the processing unit 902 is specifically configured to perform a polling operation on a plurality of target work servers, and determine a first server according to a polling result. Or acquiring first identifications of the plurality of target servers, determining hash values respectively corresponding to the plurality of target servers according to the first identifications of the plurality of target servers, and determining a first server in the plurality of target work servers according to the consistent hash algorithm and the hash values respectively corresponding to the plurality of target servers.
Embodiments of the present application further provide a computer device, which may be deployed in a server, please refer to fig. 10, where fig. 10 is a schematic diagram of an embodiment of a server in the embodiments of the present application, and as shown in the figure, the server 1000 may generate a relatively large difference due to different configurations or performances, and may include one or more Central Processing Units (CPUs) 1022 (e.g., one or more processors) and a memory 1032, and one or more storage media 1030 (e.g., one or more mass storage devices) storing an application 1042 or data 1044. Memory 1032 and storage medium 1030 may be, among other things, transient or persistent storage. The program stored on the storage medium 1030 may include one or more modules (not shown), each of which may include a series of instruction operations for the server. Still further, a central processor 1022 may be disposed in communication with the storage medium 1030, and configured to execute a series of instruction operations in the storage medium 1030 on the server 1000.
The Server 1000 may also include one or more power supplies, one or more wired or wireless network interfaces 1050, one or more input-output interfaces 1058, and/or one or more operating systems 1041, such as a Windows Server TM ,Mac OS X TM ,Unix TM ,Linux TM ,FreeBSD TM And so on.
The steps performed by the server in the above embodiment may be based on the server structure shown in fig. 10.
In the embodiment of the present application, the CPU1022 included in the server is configured to execute the following steps:
the method comprises the steps of obtaining a first state function of a first state node and a second state function of a second state node in a state machine, wherein the state machine comprises at least two state nodes, and the first state node is a previous state node adjacent to the second state node.
And acquiring the output result type of the first state node and the input data type of the second state node according to the first state function and the second state function.
And constructing a third state node, wherein the third state node is positioned between the first state node and the second state node and is used for executing the workflow function script which is used for converting the output result type into the input data type.
And executing the first state function, the workflow function script and the second state function in sequence.
In an embodiment of the present application, a computer-readable storage medium is further provided, where a computer program is stored, and when the computer program runs on a computer, the computer is caused to perform the steps performed by the server in the method described in the foregoing embodiments shown in fig. 3B to fig. 8.
Also provided in embodiments of the present application is a computer program product including a program, which when run on a computer, causes the computer to perform the steps performed by the server in the method described in the foregoing embodiments shown in fig. 3B to 8.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present application.

Claims (10)

1. A method for executing a function based on a state machine, comprising:
acquiring a first state function of a first state node and a second state function of a second state node in a state machine, wherein the state machine comprises at least two state nodes, and the first state node is a previous state node adjacent to the second state node;
acquiring the output result type of the first state node and the input data type of the second state node according to the first state function and the second state function;
constructing a third state node, wherein the third state node is positioned between the first state node and the second state node and is used for executing a workflow function script which is used for converting the output result type into the input data type;
and executing the first state function, the workflow function script and the second state function in sequence.
2. The method of claim 1, wherein prior to sequentially executing the first state function, the workflow function script, and the second state function, the method further comprises:
receiving a function registration request through a control server, wherein the function registration request is used for registering a workflow function; the workflow function comprises the workflow function script;
responding to the function registration request through the control server to obtain a working server corresponding to the control server;
distributing a working server corresponding to the control server for the workflow function through the control server, and determining a target working server in the working servers corresponding to the control server;
instructing the target work server to register the workflow function; and the target work server is used for executing the workflow function according to the function calling instruction.
3. The method according to claim 2, wherein the obtaining of the work server corresponding to the control server includes:
receiving first indication information sent by a work server through the control server, wherein the first indication information is used for periodically reporting the survival state of the work server to the control server:
if the control server receives the first indication information sent by the work server, determining that the work server is a work server corresponding to the control server;
and if the control server does not receive the first indication information sent by the working server within a preset time period, determining that the working server is not the working server corresponding to the control server.
4. The method according to claim 2 or 3, wherein the allocating, by the control server, the work server corresponding to the control server for the workflow function, and determining the target work server in the work servers corresponding to the control server, comprises:
if the number of the working servers corresponding to the control server is smaller than a preset threshold value, determining all the working servers corresponding to the control server as the target working servers;
and if the number of the working servers corresponding to the control server is greater than or equal to the preset threshold value, determining the target working server in the working service corresponding to the control server according to the function weight value of the workflow function.
5. The method according to claim 4, wherein the determining the target work server in the work service corresponding to the control server according to the function weight value of the workflow function comprises:
acquiring a function weight value of the workflow function through the control server;
determining the distribution quantity according to the function weight value;
determining the priority level of the working server corresponding to the control server according to the load condition of the working server corresponding to the control server;
and determining the target working server in the working servers corresponding to the control server according to the distribution quantity and the priority level.
6. The method of claim 5, further comprising:
after the target work server finishes registering the workflow function, receiving a function call instruction about the workflow function;
responding to the function call instruction, and acquiring a plurality of target work servers registered with the workflow function;
determining a first server of the plurality of target work servers according to an execution policy;
and acquiring the network address of the first server, and controlling the first server to execute the workflow function according to the network address of the first server.
7. The method of claim 6, wherein determining the first server of the plurality of target work servers according to the execution policy comprises:
polling the plurality of target working servers, and determining the first server according to a polling result; or
The determining a first server of the plurality of target work servers according to the execution policy includes:
acquiring first identifications of the target work servers;
determining hash values respectively corresponding to the target work servers according to the first identifications of the target work servers;
and determining the first server in the plurality of target work servers according to the consistent hash algorithm and the hash values respectively corresponding to the plurality of target work servers.
8. A function execution apparatus based on a state machine, comprising:
the device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a first state function of a first state node and a second state function of a second state node in a state machine, the state machine comprises at least two state nodes, and the first state node is a previous state node adjacent to the second state node;
the obtaining unit is further configured to obtain an output result type of the first state node and an input data type of the second state node according to the first state function and the second state function;
the processing unit is used for constructing a third state node, the third state node is positioned between the first state node and the second state node, the third state node is used for executing a workflow function script, and the workflow function script is used for converting the output result type into the input data type;
and the execution unit is used for sequentially executing the first state function, the workflow function script and the second state function.
9. A server, comprising: a memory, a transceiver, a processor, and a bus system;
wherein the memory is used for storing programs;
the processor is used for executing the program in the memory to realize the function execution method of any one of claims 1 to 7;
the bus system is used for connecting the memory and the processor so as to enable the memory and the processor to communicate.
10. A computer-readable storage medium comprising instructions that, when executed on a computer, cause the computer to perform the function execution method of any one of claims 1 to 7.
CN202110577584.9A 2021-05-26 2021-05-26 Function execution method, device, equipment and storage medium based on state machine Pending CN115408079A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110577584.9A CN115408079A (en) 2021-05-26 2021-05-26 Function execution method, device, equipment and storage medium based on state machine

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110577584.9A CN115408079A (en) 2021-05-26 2021-05-26 Function execution method, device, equipment and storage medium based on state machine

Publications (1)

Publication Number Publication Date
CN115408079A true CN115408079A (en) 2022-11-29

Family

ID=84155712

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110577584.9A Pending CN115408079A (en) 2021-05-26 2021-05-26 Function execution method, device, equipment and storage medium based on state machine

Country Status (1)

Country Link
CN (1) CN115408079A (en)

Similar Documents

Publication Publication Date Title
EP3668009B1 (en) Network service lifecycle management method and device
CN107547595B (en) Cloud resource scheduling system, method and device
CN104199957A (en) Redis universal agent implementation method
CN105049268A (en) Distributed computing resource allocation system and task processing method
US20180024866A1 (en) System, virtualization control apparatus, method for controlling a virtualization control apparatus, and program
US8572621B2 (en) Selection of server for relocation of application program based on largest number of algorithms with identical output using selected server resource criteria
CN110738389A (en) Workflow processing method and device, computer equipment and storage medium
JPWO2008146677A1 (en) Virtual machine management apparatus, virtual machine management method, and virtual machine management program
CN112948063B (en) Cloud platform creation method and device, cloud platform and cloud platform implementation system
EP3442201B1 (en) Cloud platform construction method and cloud platform
CN109614227A (en) Task resource concocting method, device, electronic equipment and computer-readable medium
CN111190823A (en) UI automation test method, electronic device and computer readable storage medium
WO2018000878A1 (en) Distributed task processing method and apparatus
CN115292026A (en) Management method, device and equipment of container cluster and computer readable storage medium
US9898273B1 (en) Dynamically updating APIS based on updated configuration file of a computing system
CN109889406A (en) For managing method, apparatus, equipment and the storage medium of network connection
US9323509B2 (en) Method and system for automated process distribution
CN112448833A (en) Multi-management-domain communication method and device
CN115408079A (en) Function execution method, device, equipment and storage medium based on state machine
CN113746676B (en) Network card management method, device, equipment, medium and product based on container cluster
CN115061774A (en) Application image management and release method, system, device and storage medium
CN114564249A (en) Recommendation scheduling engine, recommendation scheduling method, and computer-readable storage medium
CN109818767B (en) Method and device for adjusting Redis cluster capacity and storage medium
US10528397B2 (en) Method, device, and non-transitory computer readable storage medium for creating virtual machine
CN105187244A (en) Access management system of digital communication equipment supporting multiple management modes

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