WO2019153973A1 - 事件驱动方法及装置 - Google Patents
事件驱动方法及装置 Download PDFInfo
- Publication number
- WO2019153973A1 WO2019153973A1 PCT/CN2018/125823 CN2018125823W WO2019153973A1 WO 2019153973 A1 WO2019153973 A1 WO 2019153973A1 CN 2018125823 W CN2018125823 W CN 2018125823W WO 2019153973 A1 WO2019153973 A1 WO 2019153973A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- event
- target
- function
- functions
- triggered
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 73
- 230000006870 function Effects 0.000 claims abstract description 707
- 230000001960 triggered effect Effects 0.000 claims abstract description 169
- 238000010586 diagram Methods 0.000 claims abstract description 54
- 238000012545 processing Methods 0.000 claims description 18
- 230000008569 process Effects 0.000 abstract description 32
- 238000004904 shortening Methods 0.000 abstract description 5
- 238000005516 engineering process Methods 0.000 abstract description 2
- 238000011161 development Methods 0.000 description 7
- 238000004590 computer program Methods 0.000 description 4
- 230000006399 behavior Effects 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 2
- 238000004891 communication Methods 0.000 description 2
- 238000007726 management method Methods 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 230000009466 transformation Effects 0.000 description 2
- 238000004458 analytical method Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 239000000835 fiber Substances 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000011112 process operation Methods 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 238000000926 separation method Methods 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
- 238000012546 transfer Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
- G06F9/5038—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/542—Event management; Broadcasting; Multicasting; Notifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/547—Remote procedure calls [RPC]; Web services
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/544—Remote
Definitions
- the present application relates to the field of cloud computing technologies, and in particular, to an event driven method and apparatus.
- the Serverless architecture is the latest emerging business software platform architecture. On the platform provided by the Serverless architecture, developers can submit functions for implementing specific services. These functions can be triggered by events, thus enabling developers. Get rid of the setting and management of the background device, focusing only on the business logic design of the function.
- the basic features of the Serverless architecture are Function as a Service (FaaS) and event-driven. FaaS refers to the abstraction of functions as a service to developers, so that developers can implement functions such as development, testing and online deployment on the Internet.
- Event-driven means that the functions in the Serverless architecture are executed by events, and the events are released by the event source. The essence is a service request, which is used to request the completion of the corresponding business.
- event sources can issue events, and each event can trigger one or more functions.
- the event source includes a client and an event processing process.
- the user's operation on the client may trigger the client to issue an event, and may also trigger the release of a new event during the event processing.
- the events can be cached in the event queue according to the release time order by the event-driven model.
- the event can be processed according to the progress of the event, and the event is extracted from the event queue in turn, and the extracted event is extracted.
- the processing of the extracted event includes: determining a function triggered by the event according to the triggered relationship between the stored event and the function, and executing a function triggered by the event to complete the service requested by the event.
- a new event may also be triggered. For the triggered new event, it needs to be cached in the event queue for subsequent scheduling execution.
- the function corresponding to the event needs to be executed after the event is queued, queued, and queued. Therefore, the execution time of the function will be lengthened, and the delay of the business process flow is large.
- an event-driven method which is applied to a serverless architecture, wherein the Serverless architecture deploys multiple services, each service includes at least one function chain, and each function chain is used to indicate that it can be triggered in sequence.
- the event source Receiving, by the event source, a target event for the target service, where the target service is any one of the multiple services, the event source being a client or other than the target service among the multiple services service;
- a plurality of functions indicated by the target function chain that can be triggered in sequence are executed to complete driving of the target event.
- each service includes at least one function chain
- each function chain is used to indicate multiple functions that can be triggered in sequence, when receiving the target service issued by the event source.
- the target event chain may be determined from at least one function chain included in the target service, and then the plurality of functions indicated by the target function chain that can be triggered in sequence are executed by the target service to complete the target event. drive. That is, in the Serverless architecture provided by the present application, an event can directly trigger an entire function chain through a service, thereby driving in a function chain unit, so as to avoid a queuing process required for an intermediate event triggered when the function is driven. , reducing the execution time of the function, shortening the delay of the business process flow, and improving system performance.
- the method before determining the target function chain corresponding to the target event from the at least one function chain included in the target service, the method further includes:
- At least one function chain composed of a function and an event trigger relationship may be assigned to one service by using an identifier of a plurality of functions satisfying the affinity condition, that is, multiple conditions satisfying the affinity condition may be used.
- the function chain consisting of functions is classified into a service, so that each service includes at least one function chain, and the function chain is managed by the service, so that the service is scheduled by the function chain, and the queue-free event-driven is realized, and the system is improved. performance.
- the target event carries an identifier of the target event
- the performing, by the target service, performing a plurality of functions that can be triggered in sequence by the target function chain including:
- a plurality of functions indicated by the target function chain that can be triggered in sequence are executed.
- each service may have one or more service instances, and each service instance is equivalent to one process of the service, and multiple service instances may be used to implement multi-process operation of the service, thereby improving the concurrency of the event.
- the target event carries an identifier of the target event
- the target service instance includes an event execution body, and the event execution body is configured to execute a function chain
- executing a plurality of functions that are triggered by the target function chain and can be triggered in sequence including:
- the function chain can be executed through the event instance of the service instance.
- the event execution body includes an event identification variable.
- the event execution body can be triggered to execute a new event-triggered function by updating the event identification variable.
- the target function chain includes a plurality of functions that can be triggered in sequence to indicate a storage address of a plurality of functions that can be triggered in sequence;
- a function of the target event trigger is executed by the event execution body according to a pointer of the function triggered by the target event.
- the pointer of the function triggered according to the target event, the function that is triggered by the target event is executed by the event execution body, including:
- the target event can trigger a plurality of functions
- the obtained pointers of the plurality of functions are put into a preset stack for stacking processing; and the events are passed according to a pop-up order of pointers of the plurality of functions processed by the stacking
- the execution body sequentially executes a plurality of functions triggered by the target event.
- the pointers of the multiple functions may be put into a preset stack for stacking processing, so as to pass the event according to the pop-up order of the pointers of the multiple functions.
- the execution body sequentially executes a plurality of functions triggered by the target event. In this way, the execution order of the multiple functions can be guaranteed by the stack, and the disordered scheduling of the functions can be avoided.
- the target event carries an identifier of a session to which the target event belongs;
- Determining the target service instance from the at least one service instance configured for the target service including:
- a service instance that has executed the function triggered by the event belonging to the session is determined as the target service instance.
- an event driving apparatus having a function of implementing the behavior of the event driving method in the above first aspect.
- the event driving device includes at least one module for implementing the event driving method provided by the above first aspect.
- an event driving apparatus in a third aspect, includes a processor and a memory, and the memory is configured to store a program supporting the event driving apparatus to execute the event driving method provided by the first aspect, And storing data involved in implementing the event driven method provided by the first aspect above.
- the processor is configured to execute a program stored in the memory.
- the operating device of the storage device may further include a communication bus for establishing a connection between the processor and the memory.
- a computer readable storage medium is provided, the instructions being stored in the computer readable storage medium, when executed on a computer, causing the computer to perform the event driven method of the first aspect described above.
- a computer program product comprising instructions which, when run on a computer, cause the computer to perform the event driven method of the first aspect described above.
- each service includes at least one function chain
- each function chain is used to indicate multiple functions that can be triggered in sequence, when receiving the target service issued by the event source.
- the target event chain may be determined from at least one function chain included in the target service, and then the plurality of functions indicated by the target function chain that can be triggered in sequence are executed by the target service to complete the target event. drive. That is, in the Serverless architecture provided by the present application, an event can directly trigger an entire function chain through a service, thereby driving in a function chain unit, so as to avoid a queuing process required for an intermediate event triggered when the function is driven. , reducing the execution time of the function, shortening the delay of the business process flow, and improving system performance.
- FIG. 1A is a schematic diagram of an event-driven method provided by the related art
- FIG. 1B is a schematic diagram of a Serverless architecture provided by an embodiment of the present application.
- FIG. 1C is a schematic diagram of another Serverless architecture provided by an embodiment of the present application.
- 1D is a schematic diagram of a Serverless architecture of a wireless transmission service according to an embodiment of the present application
- 1E is a flowchart of an event-driven method provided by an embodiment of the present application.
- FIG. 1F is a schematic diagram of a logical structure of an IDE 10 according to an embodiment of the present application.
- FIG. 1G is a schematic diagram of a function chain provided by an application embodiment
- 1H is a schematic diagram of operation of an SRE 20 according to an embodiment of the present application.
- FIG. 1I is a schematic diagram of a method for extending concurrency by expanding a queue according to the related art
- 1J is a schematic diagram of a function chain provided by an embodiment of the present application.
- 1K is a schematic diagram of a process of stacking processing provided by an embodiment of the present application.
- FIG. 1L is a schematic flowchart of performing a function chain by an event execution body according to an embodiment of the present application
- 1M is a schematic diagram of a target service scheduling Session event provided by an embodiment of the present application.
- 1N is a deployment relationship diagram of a service instance provided by an embodiment of the present application.
- FIG. 2 is a schematic structural diagram of an event driving apparatus according to an embodiment of the present application.
- the Serverless architecture provided by the embodiment of the present application is used to provide various service services for users.
- the Serverless architecture may be a cloud service for public users, and is used for providing users with Internet services, online shopping services, or voice communication services.
- FIG. 1B is a schematic diagram of a Serverless architecture provided by an embodiment of the present application.
- the Serverless architecture is deployed with multiple services 100, and each service 100 includes at least one function chain, and each function chain uses A plurality of functions (Functions) that can be triggered in sequence are indicated, and each function chain is predetermined according to a trigger relationship of an event and a function.
- the serverless architecture further includes a background device for supporting the plurality of services 100. Since the embodiment of the present application mainly focuses on an application for developers, the background device is not introduced too much.
- the function chain of each service 100 can be triggered by an event, the event is issued by the event source, the event source includes the client and the service 100, that is, the event can be between the client and the service 100, or the service 100 and the service 100 Interact between.
- the Serverless architecture may acquire multiple functions, multiple events, and event function relationship diagrams in advance, and then, according to the affinity relationship of the acquired multiple functions, identify the identifiers of the plurality of specified functions in which the affinity conditions are met.
- At least one function chain composed of the event function diagram is assigned to one service 100 such that each service 100 includes at least one function chain.
- the event function relationship diagram is used to indicate a trigger relationship between the acquired multiple functions and multiple events, and the affinity relationship is used to indicate the relevance and similarity of the functions.
- FIG. 1C is a schematic diagram of another Serverless architecture provided by an embodiment of the present application.
- the Serverless architecture includes an Integrated Development Environment (IDE) 10 and a Service Running Environment (SRE) 20 And Function Running Environment (FRE) 30.
- IDE Integrated Development Environment
- SRE Service Running Environment
- FRE Function Running Environment
- IDE 10 is used to provide a programming development framework that allows developers to pre-program function chains in the programming development framework. Specifically, the developer can implement function programming, event definition, and event-function (EF) relationship diagram writing in the IDE10 to submit multiple functions and multiple events to the Serverless architecture through the integrated development environment. And the EF diagram.
- EF event-function
- SRE 20 is used to assign a function chain to multiple services and manage the multiple services. Specifically, the SRE 20 may allocate, according to multiple functions, multiple events, and EF diagrams submitted by the IDE 10, a plurality of specified functions that satisfy the affinity condition to at least one function chain, and allocate the information to a service. Each of the plurality of services is caused to include at least one function chain and manage the function chain through the service.
- the SRE 20 includes a Service Manager module 21, a Session Manager module 22, a Load Balance module 23, a Name Service module 24, and a Resource Scheduler module. 25.
- the Service Manager module 21 is used to assign a function chain to a service and to manage the running state of the service. Among them, the running status of the service includes startup, loading and ending.
- the Session Manager module 22 is configured to classify events entering the service, record the status of the session, and the like.
- the session classification refers to the session to which the event for determining the service belongs.
- the Load Balance module 23 is used to ensure load balancing between service instances of each service.
- Each service is usually configured with multiple service instances, and each service instance is used to run the corresponding service.
- Name Service 24 is used to implement registration, logout, or state saving of services.
- the Resource Scheduler module 25 is configured to allocate resources to service instances of each service to run corresponding service instances through the allocated resources.
- FRE30 is used to load a function chain in a service instance and trigger the execution of the function chain based on the events passed in.
- the function chain loaded by the service instance is a function chain included in the corresponding service.
- the FRE 30 includes an Event Scheduler module 31, a Function Manager module 32, a Session Manager module 33, and a Scale Manager module 34.
- the Event Scheduler module 31 is configured to schedule load execution of the function chain based on events passed into the service instance.
- the Function Manager module 32 is used to implement management and loading of function chains.
- the Session Manager module 33 is configured to allocate an event to a thread corresponding to the session to be processed according to the session to which the event is delivered.
- the Scale Manager module 34 is configured to dynamically adjust the number of internal execution threads of the service instance according to the size of the service instance load, and report the information to the SRE when the service instance is overloaded, so as to trigger the SRE to adjust the number of service instances configured by the service.
- FIG. 1D is a schematic diagram of a Serverless architecture of a service provided by an embodiment of the present application.
- the Serverless architecture includes a service module 1, a software running environment and a service model, and a serverless Runtime module 3 and an IDE. Module 4.
- Service module 1 mainly used to implement the transformation of the Serverless architecture and the separation and transformation of specific business codes.
- the software running environment and service model 2 are mainly used to implement the software running environment and service construction.
- Serverless Runtime module 3 is mainly used to implement event calls and function chain execution.
- IDE module 4 is mainly used to implement function programming and E-F diagram writing.
- the service transmission module 1 and the software running environment and service model 2 in the solid line frame can refer to the existing Serverless architecture, and the Serverless Runtime module 3 and the IDE module 4 in the implementation box are provided by the present application.
- the Serverless architecture shown in FIG. 1C or FIG. 1D does not constitute a limitation of the Serverless architecture.
- the Serverless architecture may include more or less modules than the illustrated ones, or combine some Modules, or different component modules, are not limited in this embodiment of the present application.
- FIG. 1E is a flowchart of an event-driven method according to an embodiment of the present application.
- the method is applied to the Serverless architecture described in FIG. 1B or FIG. 1C, where the Serverless architecture is deployed with multiple services, and each service includes at least one function chain.
- Each function chain is used to indicate a plurality of functions that can be triggered in sequence, and each function chain is predetermined according to a trigger relationship of events and functions.
- the method includes the following steps:
- Step 101 Acquire a plurality of functions, a plurality of events, and an event function relationship diagram, where the event function relationship diagram is used to indicate a trigger relationship between the acquired multiple functions and the acquired multiple events.
- each of the plurality of functions is a business processing function for implementing specific business logic.
- Each of the plurality of events is essentially a service request for requesting the implementation of a particular service.
- An event can trigger one or more functions, and a function can also trigger a new event.
- the function codes of the plurality of functions may be pre-programmed by a developer to define functions of the plurality of functions.
- the plurality of events can be pre-defined by the developer to define the meaning of each event.
- the event function diagram can also be pre-written by the developer to define the trigger relationship between the multiple functions and multiple events.
- the Serverless architecture in the embodiment of the present application can provide an IDE for the developer to perform function programming, event definition, and event function relationship diagram in the IDE.
- an IDE programming framework can be designed in the Serverless architecture that defines the user's programming behavior.
- the development role of the system can be divided into three categories based on the IDE programming framework, namely, software engineer (SWE), system/module engineer (System/Mdule, SE/MDE), and platform developer.
- SWE software engineer
- SE/MDE system/module engineer
- platform developer The task of SWE and SE/MDE is to conduct business development, and the task of platform developers is to develop the platform.
- the task of SWE is to write the function code of the function through the IDE programming framework.
- the task of SE/MDE is to define events for the entire system through the IDE programming framework, as well as to segment the business system and write E-F diagrams. Further, the task of the SE/MDE further includes defining, by the programming framework, an affinity relationship of the function, the affinity relationship being used to indicate the correlation and similarity between the functions, so as to be subsequently determined according to the affinity relationship between the functions. Which functions are grouped into a service.
- the platform developer's task is to develop the FaaS platform, so that the FaaS platform can obtain functions, events, and EF diagrams written by SE/MDE, and can parse the EF diagram, schedule actual physical resources, and process the same as services and distributed. Transaction. It should be noted that complex distributed-related scheduling is all hidden inside the FaaS platform, which is invisible to developers, that is, all complex functions such as distributed, clustering, resource scheduling, and dynamic scaling, etc. People will not be aware of it, thus reducing the processing burden on developers.
- the IDE programming framework can also compile functions written by SE/MDE into SO files, and write E-F diagrams as json files.
- a function may be compiled into one SO file, or a plurality of functions may be compiled into one SO file, which is not limited in this embodiment of the present application.
- the FaaS platform can directly obtain the compiled SO file and json file, and parse the SO file and the json file to obtain multiple functions and E-F relationship graphs.
- the Serverless architecture can provide the developer with an IDE 10, which can include a functional programming module, an E-F programming module, and a compilation module.
- the function programming module is used to obtain the function code written by the developer
- the EF programming module is used to obtain the definition of the EF relationship diagram, the defined event and the defined function affinity relationship written by the developer
- the compiler module is used to obtain the function.
- the code, the EF diagram, the defined events, and the function affinity are compiled to get the packet and output the packet.
- the data packet can include multiple function codes, E-F relationship graphs, multiple events, and function affinity relationships.
- the above modules can be implemented based on plug-ins developed by development tools.
- Step 102 Determine, according to the obtained affinity relationship of the plurality of functions, a plurality of specified functions that satisfy the affinity condition among the acquired plurality of functions, and assign the plurality of specified functions to at least one function chain formed by the event function relationship diagram. Target service.
- the affinity relationship is used to indicate an association between functions
- the affinity condition refers to a condition that an affinity relationship between a plurality of functions that can be allocated to a service should satisfy.
- the affinity relationship may be used to indicate an association between services implemented by the function, and the affinity condition may be that the association between the services implemented by the multiple specified functions is greater than a preset threshold.
- the affinity relationship may be set by the developer according to specific needs, which is not limited by the embodiment of the present application.
- the target service is any one of a plurality of services deployed by the Serverless architecture. That is, each of the plurality of services includes at least one function chain, each function chain being used to indicate a plurality of functions that can be triggered in sequence.
- the Serverless architecture can group some of the functions that satisfy the affinity condition into a service to manage these parts of the function using the same service.
- the at least one function chain may be composed of identifiers of a plurality of specified functions satisfying the affinity condition, according to the event function relationship diagram, or may be triggered by the identifiers of the plurality of specified functions satisfying the affinity condition and the plurality of specified functions.
- the identifier of at least one event is composed according to the event function diagram.
- each function chain may include an identifier of a plurality of functions that can be triggered in sequence, or an identifier of a plurality of functions that can be triggered in sequence and an identifier of at least one event.
- the function's identifier is used to uniquely identify the function, which can be the name of the function, the identification number (ID), or a pointer.
- the identifier of the event is used to uniquely identify the event, which can be the name or ID of the event.
- each function chain includes an ID of a plurality of functions that can be sequentially triggered and an ID of at least one event.
- E represents an event
- F represents a function
- service A includes two functions consisting of a function ID and an event ID.
- Function chain function chain 1 and function chain 2
- service B includes a function chain consisting of function ID and event ID.
- the function chain 1 includes F1, E2, F2, E3, F3, and F4, and an arrow indicating a trigger relationship, which is used to indicate that F1 can trigger E2, E2 can trigger F2, F2 can trigger E3, and E3 can trigger F3 and F4, respectively.
- a function is located in a separate container (Docker), and each function runs independently in its own container.
- a plurality of functions indicated by a function chain may be located in the same container, and an entire function chain may be run in the same container, thereby reducing the maintenance amount of the container and avoiding a function and a container. Runs cause high latency due to frequent loading and improve system performance.
- a container is a resource allocated for a service to run a service.
- a function is usually abstracted into a service, and then driven by an event in units of functions. In this process, the triggered intermediate event needs to enter the event queue to be queued first, which will increase The execution delay of the function, the system performance is low.
- a plurality of functions satisfying the affinity relationship are formed into at least one function chain according to the event function relationship diagram, and at least one function chain of the composition is allocated to a service, thereby realizing abstraction of a string of function chains. For a service, the service is driven by the function chain, which avoids the queuing process of the event, shortens the processing delay of the function, and improves the system performance.
- step 101 and step 102 are used to configure a function chain for the service deployed by the Serverless architecture, and after the function chain is configured for the service, the event may be scheduled by the service chain according to the event published by the event source. That is, the following steps 103-105 are performed.
- the function chain of any configuration may be changed as needed, which is not limited in this embodiment of the present application.
- Step 103 Receive a target event for the target service published by the event source, where the target service is any one of a plurality of services, and the event source is a client or other services of the plurality of services except the target service.
- the target event for the target service published by the event source refers to an event sent by the event source to the target service.
- an event source can publish an event to a service requesting that the service provide business services.
- the event source may be a client or any one of the multiple services. That is, in the Serverless architecture, events can interact between the client and the service, or between the service and the service.
- events that interact between a client and a service, or between a service and a service can also be referred to as messages.
- Step 104 Determine an objective function chain corresponding to the target event from at least one function chain included in the target service.
- the target function chain corresponding to the target event may be directly determined from at least one function chain included in the target service.
- the target function chain corresponding to the target event refers to a function chain that the target event can trigger.
- the target event may carry the identifier of the target event
- determining the target function chain corresponding to the target event from the at least one function chain included in the target service may include the following two implementation manners:
- the first implementation manner is: determining an objective function triggered by the target event according to the identifier of the target event and a trigger relationship of the stored event and function; determining, by using the objective function as a starting point, from at least one function chain included in the target service a function chain; the function chain starting from the objective function is determined as the target function chain.
- each service may pre-store a trigger relationship between an event and a function, and the trigger relationship of the event and function stored in each service may include a trigger relationship of all functions and events in the system, or only a function managed by the service.
- the chain indicates the trigger relationship of multiple functions and events, or only the start function of each function chain hosted by the service and the trigger relationship of the event.
- the trigger relationship of the event and function stored by the target service may be acquired, and then according to the identifier of the target event and the trigger relationship of the event and function stored by the target service, including from the target service
- the at least one function chain determines the target function chain corresponding to the target event.
- the trigger relationship of the event and the function may include an identifier of the multiple events and an identifier of a function that can be triggered by the corresponding multiple events.
- determining, according to the identifier of the target event, and the triggered relationship between the stored event and the function, determining the target function triggered by the target event includes: searching for the target from the triggered relationship between the stored event and the function according to the identifier of the target event.
- the identifier of the function corresponding to the identifier of the event, and the function indicated by the identifier of the function corresponding to the identifier of the target event is taken as the objective function.
- each function chain in the at least one function chain included in the target service may include an identifier of a plurality of functions that can be triggered in sequence, and correspondingly, the target function may be determined from at least one function chain included in the target service.
- the identifier F1 of the target function that E1 can trigger can be determined according to the trigger relationship of the pre-stored event and function, and then from the service A.
- the function chain 1 starting from F1 is determined as the target function chain among the two function chains included.
- the second implementation manner is: determining, according to the identifier of the target event, the stored event identifier and the function chain, determining an objective function chain corresponding to the target event from at least one function chain included in the target service.
- each service may pre-store a correspondence between an event identifier and a function chain, where the correspondence between the event identifier and the function chain stores at least one function chain included in each service and an event corresponding to each function chain.
- the identifier, the identifier of the event corresponding to each function chain refers to the identifier of the event that can trigger the start function of the function chain.
- the function chain corresponding to the identifier of the target event may be searched from at least one function chain included in the target service according to the identifier of the target event and the corresponding relationship between the stored event identifier and the function chain, and the target event may be found.
- the function chain corresponding to the identifier is determined as the target function chain corresponding to the target event.
- Step 105 Perform, by the target service, a plurality of functions that can be triggered in sequence indicated by the target function chain to complete driving of the target event.
- executing, by the target service, performing, by the target function chain, the plurality of functions that can be triggered in sequence may include: determining, from the at least one service instance configured for the target service, a target service instance, each of the at least one service instance The service instances are used to run the target service; in the target service instance, a plurality of functions indicated by the target function chain that can be triggered in sequence are executed.
- each service has one or more service instances that are used to run the service, that is, each service instance can load and run at least one function chain included in the service.
- the running resources of the service instance of each service may be pre-allocated by the serverless architecture.
- the serverless architecture may be allocated by default according to a preset allocation rule, or may be manually allocated by a technician according to actual needs.
- FIG. 1H is a schematic diagram of an operation of the SRE 20 provided by the embodiment of the present application.
- the FRE 20 includes a Service Manager module 21, a Name Service module 24, and a Resource Scheduler module 25.
- the Service Manager module 21 can receive a data packet submitted by the developer through the IDE, and the data package can include a plurality of function codes, an EF relationship diagram, a defined plurality of events, and a function affinity relationship, and then parse the data packet according to the analysis.
- the obtained function affinity relationship and EF relationship diagram are obtained, and a plurality of functions conforming to the affinity condition are composed of at least one function chain assigned to a service. That is, the Service Manager module 21 is used to assign a function chain to multiple services in the Serverless architecture.
- the Service Manager module 21 may also send a resource request to the Resource Scheduler module 25 to request a running resource for the service instances of the multiple services.
- the Resource Scheduler module 25 is configured to allocate running resources for service instances of respective services according to resource requests of the Service Manager module 21. For example, two containers can be created in server 1 for running service A, respectively, to get two service instances of service A. A container can be created in server 2 and server 3 for running service B to obtain two service instances of service B.
- a Session is a session between multiple clients, and each session typically contains a series of events. Moreover, in order to ensure the order of the session, it is usually necessary to serially process a Session event, and process events between different Sessions in parallel.
- the Serverless architecture in the related art is difficult to solve the serial and parallel coordination problem of the Session event in a complex scenario because a function is independent in a container and is event-driven by means of a queue.
- a method of expanding a queue is also proposed to improve the degree of concurrency.
- FIG. 1I if there are three Sessions in the Serverless architecture, namely Session1, Session2, and Session3, respectively, a corresponding queue may be created for each of the three Sessions, and events generated by each Session are respectively placed in each Session.
- the corresponding queues are queued to process the events of each session in parallel.
- the Serverless architecture provided by the embodiment of the present application also supports the serial execution of the event-triggered function chain of the same session, and the function chain triggered by the event of different sessions is executed in parallel.
- the target event may further include an identifier of the session to which the target event belongs, and determining the target service instance from the at least one service instance configured for the target service may include: determining, according to the identifier of the session, the at least one service instance.
- a service instance of a function that is triggered by an event belonging to the session has been executed; a service instance that has executed a function triggered by an event belonging to the session is determined as the target service instance.
- a plurality of functions that can be triggered in sequence indicated by the target function chain can be executed in the target service instance. In this way, the function chain triggered by the events belonging to the same session can be processed in the same service instance to implement the serialization of the Session event.
- each service instance includes an event execution body, and the event execution body is an execution unit of the function chain, that is, each service instance can execute the function chain through the event execution body.
- Each service instance may include an event execution body, or may include multiple event execution bodies, and each event execution body is independent, and the function chain may be processed in parallel. That is, the function within the function chain can be executed serially by the event executor, and the functions between the function chains can be executed in parallel.
- the Serverless architecture provided by the embodiment of the present application may increase or delete the number of event execution bodies of each service instance according to actual needs.
- the target event carries an identifier of the target event
- the target service instance includes an event execution body
- the event execution body is configured to execute a function chain, and correspondingly, in the target service instance, performing the indication of the target function chain can be triggered in sequence
- the functions can include the following steps 1-3:
- the identifier of the target event is written to the event execution body of the target service instance, and the target event is triggered by the event execution body according to the identifier of the target event and the target function chain loaded in the target service instance.
- the function is written to the event execution body of the target service instance, and the target event is triggered by the event execution body according to the identifier of the target event and the target function chain loaded in the target service instance.
- the event execution body is essentially a function code segment, and the function code segment includes an event identification variable.
- the event execution body can be triggered to execute the target function chain by assigning an event identification variable in the event execution body.
- the identifier of the target event needs to be first written to the event execution body to trigger the event execution body to execute the function triggered by the target event.
- the identifier of the target event is written into the event execution body, which means that the event identification variable is assigned an identifier of the target event.
- the target function chain may include an identifier of a plurality of functions that can be triggered in sequence, according to the identifier of the target event and the target function chain, by executing the function, the function of the target event triggering may include: according to the target The identifier of the event, the identifier of the function triggered by the target event is obtained from the identifiers of the plurality of functions that are triggered by the target function chain; the identifier of the function triggered by the target event is executed by the event execution body Event triggered function.
- the identifier of the plurality of functions that can be triggered in sequence by the target function chain may be an ID or a pointer of the plurality of functions, and is used to indicate a storage address of the plurality of functions that can be triggered in sequence indicated by the target function chain.
- the function that performs the target event triggering may include the following two implementation manners:
- the first implementation manner is: when the target function chain includes IDs of a plurality of functions that can be triggered in sequence, according to the identifier of the target event, the target is obtained from IDs of the plurality of functions that are sequentially triggered by the target function chain The ID of the function triggered by the event; the ID of the function triggered by the target event, and the correspondence between the stored function ID and the function pointer, the pointer of the function triggered by the target event; the pointer of the function triggered according to the target event, Through the event execution body, the function triggered by the target event is executed.
- the second implementation manner is: when the target function chain includes a pointer of a plurality of functions that can be triggered in sequence, according to the identifier of the target event, the target is obtained from a pointer of the plurality of functions that are sequentially triggered by the target function chain A pointer to an event-triggered function; a pointer to a function triggered by the target event, through which the event-executing body executes a function triggered by the target event.
- the function of the function triggered by the target event may be in the following two manners:
- the first implementation manner when the target event can trigger a function, according to the pointer of the acquired function, the function triggered by the target event is executed by the event execution body.
- the storage address of the function triggered by the target event may be determined according to the pointer of the acquired function, and the function triggered by the target event is acquired from the storage address, and the function triggered by the target event is executed by the event execution body.
- the second implementation manner when the target event can trigger multiple functions, the pointers of the acquired multiple functions are put into the preset stack for stack processing; according to the stacking order of the pointers of the multiple functions processed by the stack Through the event execution body, multiple functions triggered by the target event are sequentially executed.
- the plurality of functions obtained refers to that the target event can trigger multiple functions.
- the plurality of functions triggered by the target event are sequentially executed by the event executing body, including the following steps 1)-3):
- the pressure is The pointer of the second function below the stack bit of the pointer of the first function in the pointer of the plurality of functions processed by the stack is subjected to the stack processing, the second function is obtained according to the pointer of the second function, and the body is executed according to the event Executing the first function, the second function is executed by the event execution body until the second function is executed by the event execution body in the branch of the target function chain.
- step 2) repeating step 2) until the pointer of the last function at the bottom of the stack in the pointer of the plurality of functions processed by the stack is popped, and the last function is executed in the target function by the event executable body Until the branch road in the chain.
- the target event is Event1
- Event1 is subscribed to by two functions (F2 and F1), that is, Event1 can trigger the two functions F2 and F1.
- F2 can trigger a new event Event2
- Event2 can trigger a new function F3
- F1 can trigger a new event Event3.
- the pointers of F2 and F1 can be respectively put into the preset stack for stack processing, then the pointer of F2 at the top of the stack is popped, and F2 is executed by the event execution body, and F2 is executed.
- a new event Event2 will be released and F3 will be executed according to Event2.
- the pointer of F1 can be popped and the F1 can be executed by the execution body.
- one of the multiple functions can also be processed by the current event execution body, and other functions of the multiple functions are scheduled to the The event service instance is processed by other event execution bodies than the event execution body. In this way, multiple functions can be asynchronously processed by multiple event execution bodies to increase concurrency.
- the identifier of the target event written in the event execution body is updated to the identifier of the new event, according to The identifier of the new event and the target function chain, through the event execution body, execute the function triggered by the new event until all functions included in the target function chain are executed by the event execution body.
- the identifier of the carried new event may be acquired from the new event, and the event execution body has been written
- the identifier of the target event is updated to the identifier of the new event, to re-assign the variable of the event identifier in the event execution body to the identifier of the new event, and trigger the function execution body to execute the function triggered by the new event.
- the method for performing the function triggered by the target event is the same.
- the event identifier written in the event execution body may be modified to be the identifier of the new event.
- the multiple functions may be subjected to a stack process, and the plurality of functions are sequentially executed by the event execution body according to the pop-up order of the multiple functions. The branch where the function is located, or some of the multiple functions can be dispatched to other event execution bodies for processing.
- the event execution body execution function chain may be triggered by modifying an event identification variable of the event execution body.
- the event execution body includes an event identification variable.
- the corresponding function chain may be obtained according to the identifier of the event, and the event flag is written into the event execution body.
- the event execution function is executed by the event execution body according to the identifier of the written event and the corresponding function chain. If a new event is issued after the function triggered by the event is executed, the event identifier variable of the event execution body may be updated according to the identifier of the new event, so that the event execution body identifies the variable according to the updated event.
- the corresponding function chain executes the new event-triggered function until all functions indicated by the function chain are executed.
- each service instance may further include multiple Faas instances, where the Faas instance is the next level of the service instance, and the multiple Faas instances have the same execution logic, and multiple events scheduled to the service instance may be processed in parallel.
- the service instance is equivalent to the service process, and the multiple Faas instances of the service instance are equivalent to multiple threads of the process.
- events scheduled to be executed by the target service instance events belonging to the same session may be scheduled to be executed by the same Faas instance in the target service instance, and events belonging to different sessions may be scheduled to be executed by the same or different Faas instances to support the session.
- the internal events are serially executed, and the events between the sessions are executed in parallel to further realize the serial parallel coordinated scheduling of the Session events.
- the target service includes three service instances: service instance 1, service instance 2, and service instance 3.
- Service instance 1 includes three Faas instances: Faas instance 1, Faas instance 2, and Faas instance 3.
- the events of the target service include events belonging to Session1, Session2, and Session3, respectively.
- the event of Session 1 can be scheduled to be processed in Faas instance 1 in sequence, and the event of Session 2 is scheduled to be processed in Faas instance 2, and the event of Session 3 is scheduled to be processed in Faas instance 3.
- the serial execution of the events in the Session can be realized, and the events between the Sessions are executed in parallel.
- FIG. 1A is a deployment relationship diagram of a service instance provided by an embodiment of the present application.
- the Serverless architecture deploys two services: service A and service B, and service A can be set in a pre-allocated container.
- Service B can also set multiple service instances in a pre-allocated container.
- Each service instance may include multiple Faas instances for running a function chain included in the corresponding service.
- the Serverless architecture can also include a caching service for caching the running state of the session.
- the service is abstracted into an event-driven manner based on a function chain, which can support efficient and fast scheduling of events. For example, in one embodiment, assuming 1000 sessions, each session has 5 events, then the 1000 sessions have a total of 5000 events, assuming that the 5000 events trigger a total of 18 function chains, which is provided by the present application.
- the event-driven method the total duration of the processing of these 5000 events is less than 40ms, and the average processing time per event is less than 8us.
- the call duration of each function in the function chain is also in the order of us, the performance has directly approached the direct call of the function, greatly improving the system performance.
- Table 1 is a performance comparison table of a queue-based event-driven instance provided by the related art and a function chain-based event-driven instance provided by the embodiment of the present application. As shown in Table 1, the queue-based event-driven instance is shown in Table 1. Only 1000 session concurrency can be supported, and event-driven instances based on function chains can support the concurrency of tens of thousands of sessions, and the degree of concurrency is greatly improved. Moreover, the execution delay of queue-based event-driven instances is 200ms, and based on the function chain. The execution delay of the event-driven instance can be less than 10us, and the execution delay is also greatly shortened, which improves system performance.
- each service includes at least one function chain
- each function chain is used to indicate multiple functions that can be triggered in sequence, when receiving the target service issued by the event source.
- the target event chain may be determined from at least one function chain included in the target service, and then the plurality of functions indicated by the target function chain that can be triggered in sequence are executed by the target service to complete the target event. drive. That is, in the Serverless architecture provided by the present application, an event can directly trigger an entire function chain through a service, thereby driving in a function chain unit, so as to avoid a queuing process required for an intermediate event triggered when the function is driven. , reducing the execution time of the function, shortening the delay of the business process flow, and improving system performance.
- FIG. 2 is a schematic structural diagram of an event driving apparatus according to an embodiment of the present application.
- the event driving apparatus is applied to a serverless architecture, where the Serverless architecture deploys multiple services, and each service includes at least one function chain.
- the function chain is used to indicate a plurality of functions that can be triggered in sequence, and each function chain is predetermined according to a trigger relationship of events and functions, and the device includes a receiving module 201, a determining module 202, and an executing module 203.
- the receiving module 201 is configured to perform the operations performed by step 103 in the foregoing embodiment of FIG. 1E;
- a first determining module 202 configured to perform the operations performed by step 104 in the foregoing embodiment of FIG. 1E;
- the executing module 203 is configured to perform the operations performed by step 105 in the embodiment described above in FIG. 1E.
- the device further includes an obtaining module, a second determining module, and an allocating module:
- An obtaining module configured to perform the operations performed by step 101 in the embodiment described in FIG. 1E above;
- the second determining module and the assigning module are configured to perform the operations performed by step 102 in the embodiment described above with respect to FIG. 1E.
- the target event carries an identifier of the target event; the first determining module 202 is specifically configured to perform the first implementation manner or the second implementation manner described in step 104 in the foregoing embodiment of FIG. 1E.
- the executing module 203 includes:
- a determining unit configured to determine a target service instance from at least one service instance configured for the target service, each of the at least one service instance being configured to run the target service;
- an execution unit configured to execute, in the target service instance, a plurality of finger functions that can be triggered in sequence by the target function chain.
- the target event carries an identifier of the target event, where the target service instance includes an event execution body, where the event execution body is used to execute a function chain; the execution unit is specifically configured to:
- the identifier of the target event written in the event execution body is updated to the identifier of the new event, according to the new The identifier of the event and the target function chain loaded in the target service instance, through the event execution body, executing the function triggered by the new event until all functions included in the target function chain are executed by the event execution body .
- the target function chain includes a pointer of a plurality of functions that can be triggered in sequence to indicate a storage address of a plurality of functions that can be triggered in sequence;
- the execution unit is specifically used to:
- the function triggered by the target event is executed by the event execution body.
- the execution unit is specifically configured to:
- the target event can trigger a function, determining a storage address of the function triggered by the target event according to the pointer of the acquired function; acquiring a function triggered by the target event from the storage address; executing the target event through the event execution body Triggered function;
- the pointers of the acquired multiple functions are put into the preset stack for stacking processing; according to the stacking order of the pointers of the multiple functions processed by the stacking, the event executing body is executed. , in turn, execute multiple functions triggered by the target event.
- the target event carries an identifier of a session to which the target event belongs;
- the determining module is specifically used to:
- a service instance that has executed a function triggered by an event belonging to the session is determined as the target service instance.
- each service includes at least one function chain
- each function chain is used to indicate multiple functions that can be triggered in sequence, when receiving the target service issued by the event source.
- the target event chain may be determined from at least one function chain included in the target service, and then the plurality of functions indicated by the target function chain that can be triggered in sequence are executed by the target service to complete the target event. drive. That is, in the Serverless architecture provided by the present application, an event can directly trigger an entire function chain through a service, thereby driving in a function chain unit, so as to avoid a queuing process required for an intermediate event triggered when the function is driven. , reducing the execution time of the function, shortening the delay of the business process flow, and improving system performance.
- a computer readable storage medium having stored therein instructions that, when executed on a computer, cause the computer to perform the events described above with respect to the embodiment of FIG. 1E Drive method.
- a computer program product comprising instructions which, when run on a computer, cause the computer to perform the event driven method described above with respect to the embodiment of FIG. 1E.
- the computer program product includes one or more computer instructions.
- the computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable device.
- the computer instructions can be stored in a computer readable storage medium or transferred from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be from a website site, computer, server or data center Transfer to another website site, computer, server, or data center by wire (eg, coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (eg, infrared, wireless, microwave, etc.).
- the computer readable storage medium can be any available media that can be accessed by a computer or a data storage device such as a server, data center, or the like that includes one or more available media.
- the usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a digital versatile disc (DVD)), or a semiconductor medium (for example, a solid state disk (SSD)). )Wait.
- a magnetic medium for example, a floppy disk, a hard disk, a magnetic tape
- an optical medium for example, a digital versatile disc (DVD)
- DVD digital versatile disc
- SSD solid state disk
- a person skilled in the art may understand that all or part of the steps of implementing the above embodiments may be completed by hardware, or may be instructed by a program to execute related hardware, and the program may be stored in a computer readable storage medium.
- the storage medium mentioned may be a read only memory, a magnetic disk or an optical disk or the like.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Multimedia (AREA)
- Stored Programmes (AREA)
- Debugging And Monitoring (AREA)
Abstract
一种事件驱动方法及装置,属于云计算技术。所述方法应用于Serverless架构中,该Serverless架构部署有多个服务,每个服务包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数,且每个函数链是根据事件和函数的触发关系预先确定得到,所述方法包括:获取多个函数、多个事件以及事件函数关系图,该事件函数关系图用于指示获取的多个函数和多个事件之间的触发关系(101);根据获取的多个函数的亲和关系,确定获取的多个函数中满足亲和条件的多个指定函数,将该多个指定函数按照事件函数关系图组成的至少一个函数链分配给目标服务(102);接收事件源发布的针对目标服务的目标事件,该目标服务为多个服务中的任一个,该事件源为客户端或者该多个服务中除该目标服务之外的其他服务(103);从该目标服务包括的至少一个函数链中确定目标事件对应的目标函数链(104);通过目标服务,执行目标函数链指示的能够依次触发的多个函数,以完成该目标事件的驱动(105)。该方法基于服务的函数链可以进行免队列事件驱动,减小了函数的执行时长,缩短了业务处理流程的时延,提高了系统性能。
Description
本申请要求于2018年02月12日提交的申请号为201810153094.4、发明名称为“事件驱动方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及云计算技术领域,特别涉及一种事件驱动方法及装置。
无服务器(Serverless)架构是目前最新兴起的业务软件平台架构,在Serverless架构提供的平台上,开发者可以提交用于实现具体业务的函数,这些函数可以通过事件触发执行,如此,可以使得开发者摆脱对后台设备的设置和管理工作,仅关注于函数的业务逻辑设计。Serverless架构的基本特征是函数即服务(Function as a Service,FaaS)和事件驱动。FaaS是指将函数抽象为一种服务提供给开发者,以使开发者能够在互联网上实现函数的开发、测试以及在线部署等功能。事件驱动是指Serverless架构中的函数由事件驱动执行,事件由事件源发布,其实质是一种业务请求,用于请求完成相应的业务。
目前的Serverless架构中,通常采用一种通用的事件驱动模型来驱动函数执行,这种事件驱动模型是基于队列实现的。具体地,参见图1A,在Serverless架构中,事件源可以发布事件,每个事件可以触发一个或多个函数。其中,事件源包括客户端和事件处理过程,例如,用户在客户端的操作可以触发客户端发布事件,在事件处理过程中也可以触发发布新的事件。对于事件源发布的事件,一方面可以通过事件驱动模型将这些事件按照发布时间顺序依次缓存在事件队列中,另一方面可以按照事件处理进度,从事件队列中依次提取事件,并对提取的事件进行处理。其中,对提取的事件进行处理包括:根据存储的事件和函数的触发关系,确定该事件触发的函数,并执行该事件触发的函数,以完成该事件请求的业务。另外,在执行该事件触发的函数的过程中,还可能触发新的事件,对于触发的新的事件,需要先缓存在事件队列中,以便后续调度执行。
上述事件驱动过程中,事件对应的函数需要在事件的入队列、排队等待、出队列等环节完成之后才能被执行,因此函数的执行时间将被拉长,业务处理流程的时延较大。
发明内容
为了解决相关技术中存在的函数的执行时间长,业务处理流程的时延大问题,本申请提供了一种事件驱动方法及装置。所述技术方案如下:
第一方面,提供了一种事件驱动方法,应用于无服务器Serverless架构中,所述Serverless架构部署有多个服务,每个服务包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数,且每个函数链是根据事件和函数的触发关系预先确定得到,所述方法包括:
接收事件源发布的针对目标服务的目标事件,所述目标服务为所述多个服务中的任一个,所述事件源为客户端或者所述多个服务中除所述目标服务之外的其他服务;
从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链;
通过所述目标服务,执行所述目标函数链指示的能够依次触发的多个函数,以完成所述目标事件的驱动。
本申请实施例中,可以在Serverless架构中部署多个服务,每个服务包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数,当接收到事件源发布的针对目标服务的目标事件时,可以从目标服务包括的至少一个函数链中确定该目标事件对应的目标函数链,然后通过目标服务执行该目标函数链指示的能够依次触发的多个函数,以完成目标事件的驱动。也即是,在本申请提供的Serverless架构,事件可以通过服务直接触发一整个函数链,从而以函数链为单位进行驱动,如此可以避免以函数为单位驱动时触发的中间事件需要进行的排队流程,减小了函数的执行时长,缩短了业务处理流程的时延,提高了系统性能。
在另一实施例中,所述从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链之前,还包括:
获取多个函数、多个事件以及事件函数关系图,所述事件函数关系图用于指示获取的多个函数和获取的多个事件之间的触发关系;
根据所述获取的多个函数的亲和关系,确定所述获取的多个函数中满足亲和条件的多个指定函数;
将所述多个指定函数的标识按照所述事件函数关系图组成的至少一个函数链分配给所述目标服务。
本申请实施例中,可以将满足亲和条件的多个函数的标识,按照函数和事件的触发关系组成的至少一个函数链分配给一个服务,也即是,可以将满足亲和条件的多个函数组成的函数链归入一个服务中,使得每个服务包括至少一个函数链,通过服务对函数链进行管理,以便后续通过服务以函数链为单位进行调度,实现免队列的事件驱动,提高系统性能。
在具体实施例中,所述目标事件携带所述目标事件的标识;
所述从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链,包括:
根据所述目标事件的标识,以及存储的事件和函数的触发关系,确定所述目标事件触发的目标函数;从所述目标服务包括的至少一个函数链中确定以所述目标函数为起点的函数链;将所述以所述目标函数为起点的函数链确定为所述目标函数链;
或者,
根据所述目标事件的标识,以及存储的事件标识和函数链的对应关系,从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链。
在具体实施例中,所述通过所述目标服务,执行所述目标函数链指示的能够依次触发的多个函数,包括:
从为所述目标服务配置的至少一个服务实例中确定目标服务实例,所述至少一个服务实例中的每个服务实例用于运行所述目标服务;
在所述目标服务实例中,执行所述目标函数链指示的能够依次触发的多个函数。
本申请实施例中,每个服务可以具有一个或多个服务实例,每个服务实例相当于服务的一个进程,通过多个服务实例可以实现服务的多进程运行,提升事件的并发度。
在具体实施例中,所述目标事件携带所述目标事件的标识,所述目标服务实例包括事件执行体,所述事件执行体用于执行函数链;
所述在所述目标服务实例中,执行所述目标函数链指示的能够依次触发的多个函数,包括:
在所述目标服务实例中加载所述目标函数链;
将所述目标事件的标识写入所述事件执行体;
根据所述目标事件的标识和在所述目标服务实例中加载的所述目标函数链,通过所述事件执行体,执行所述目标事件触发的函数;
当检测到在通过所述事件执行体执行所述目标事件触发的函数之后发布了新的事件时,将所述事件执行体中写入的所述目标事件的标识更新为所述新的事件的标识,根据所述新的事件的标识和在所述目标服务实例中加载的所述目标函数链,通过所述事件执行体,执行所述新的事件触发的函数,直至通过所述事件执行体执行完所述目标函数链包括的所有函数为止。
在服务实例中,可以通过服务实例的事件执行体执行函数链。其中,事件执行体包括事件标识变量,在通过事件执行体执行函数链的过程中,如果发布了新的事件,可以通过更新事件标识变量来触发事件执行体执行新的事件触发的函数。这种通过更新事件执行体的事件标识变量,执行函数链的方式,避免了中间事件的排队过程,减小了事件的执行时延,提高了系统性能。
在具体实施例中,所述目标函数链包括能够依次触发的多个函数的指针,用于指示能够依次触发的多个函数的存储地址;
所述根据所述目标事件的标识和在所述目标服务实例中加载的所述目标函数链,通过所述事件执行体,执行所述目标事件触发的函数,包括:
根据所述目标事件的标识,从所述目标函数链包括的能够依次触发的多个函数的指针中获取所述目标事件触发的函数的指针;
根据所述目标事件触发的函数的指针,通过所述事件执行体,执行所述目标事件触发的函数。
在具体实施例中,所述根据所述目标事件触发的函数的指针,通过所述事件执行体,执行所述目标事件触发的函数,包括:
当所述目标事件能够触发一个函数时,根据获取的函数的指针,确定所述目标事件触发的函数的存储地址;从所述存储地址获取所述目标事件触发的函数;通过所述事件执行体,执行所述目标事件触发的函数;
当所述目标事件能够触发多个函数时,将获取的多个函数的指针放入预设堆栈中进行压栈处理;根据压栈处理的多个函数的指针的出栈顺序,通过所述事件执行体,依次执行所述目标事件触发的多个函数。
本申请实施例中,当一个事件能够触发多个函数时,可以将该多个函数的指针放入预设堆栈中进行压栈处理,以便根据这多个函数的指针的出栈顺序,通过事件执行体依次执行目标事件触发的多个函数。如此,可以通过堆栈保证该多个函数的执行顺序,避免函数的无序调度。
在具体实施例中,所述目标事件携带所述目标事件所属的会话的标识;
所述从为所述目标服务配置的至少一个服务实例中确定目标服务实例,包括:
根据所述会话的标识,从所述至少一个服务实例中确定已执行了属于所述会话的事件触发的函数的服务实例;
将所述已执行了属于所述会话的事件触发的函数的服务实例,确定为所述目标服务实例。
本申请实施例中,通过将属于同一会话的事件调度到同一服务实例中进行处理,可以保证会话内事件的串行执行,实现会话事件的串并行协调,进一步提高系统性能。
第二方面,提供了一种事件驱动装置,所述事件驱动装置具有实现上述第一方面中事件驱动方法行为的功能。所述事件驱动装置包括至少一个模块,该至少一个模块用于实现上述第一方面所提供的事件驱动方法。
第三方面,提供了一种事件驱动装置,所述事件驱动装置的结构中包括处理器和存储器,所述存储器用于存储支持事件驱动装置执行上述第一方面所提供的事件驱动方法的程序,以及存储用于实现上述第一方面所提供的事件驱动方法所涉及的数据。所述处理器被配置为用于执行所述存储器中存储的程序。所述存储设备的操作装置还可以包括通信总线,该通信总线用于该处理器与存储器之间建立连接。
第四方面,提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述第一方面所述的事件驱动方法。
第五方面,提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述第一方面所述的事件驱动方法。
上述第二方面、第三方面、第四方面和第五方面所获得的技术效果与第一方面中对应的技术手段获得的技术效果近似,在这里不再赘述。
本申请提供的技术方案带来的有益效果是:
本申请实施例中,可以在Serverless架构中部署多个服务,每个服务包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数,当接收到事件源发布的针对目标服务的目标事件时,可以从目标服务包括的至少一个函数链中确定该目标事件对应的目标函数链,然后通过目标服务执行该目标函数链指示的能够依次触发的多个函数,以完成目标事件的驱动。也即是,在本申请提供的Serverless架构,事件可以通过服务直接触发一整个函数链,从而以函数链为单位进行驱动,如此可以避免以函数为单位驱动时触发的中间事件需要进行的排队流程,减小了函数的执行时长,缩短了业务处理流程的时延,提高了系统性能。
图1A是相关技术提供的一种事件驱动方法的示意图;
图1B是本申请实施例提供的一种Serverless架构的示意图;
图1C是本申请实施例提供的另一种Serverless架构的示意图;
图1D是本申请实施例提供的一种无线传输业务的Serverless架构示意图;
图1E是申请实施例提供的一种事件驱动方法的流程图;
图1F是申请实施例提供的一种IDE10的逻辑结构示意图;
图1G是申请实施例提供的一种函数链的示意图;
图1H是本申请实施例提供的一种SRE20的运行示意图;
图1I是本相关技术中提供的一种的通过扩展队列的方式来提升并发度的示意图;
图1J是本申请实施例提供的一种函数链的示意图;
图1K是本申请实施例提供的一种压栈处理过程示意图;
图1L是本申请实施例提供的一种通过事件执行体执行函数链的流程示意图;
图1M是本申请实施例提供的一种目标服务调度Session事件的示意图;
图1N是本申请实施例提供的一种服务实例的部署关系图;
图2是本申请实施例提供的一种事件驱动装置的结构示意图。
为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。
在对本申请实施例进行详细介绍之前,先对本申请实施例的应用场景进行简单介绍。
本申请实施例提供的Serverless架构用于为用户提供各种业务服务,比如该Serverless架构可以是面向公共用户的云服务,用于为用户提供上网业务、网上购物业务或者语音通信业务等等。
接下来对本申请实施例的系统架构进行介绍。
图1B是本申请实施例提供的一种Serverless架构的示意图,如图1B所示,该Serverless架构部署有多个服务(Service)100,每个服务100包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数(Function),且每个函数链是根据事件(Event)和函数的触发关系预先确定得到。另外,该Serverless架构还包括用于支持该多个服务100的后台设备,由于本申请实施例主要关注于面向开发者的应用,所以对后台设备不做过多介绍。
其中,每个服务100的函数链可以由事件触发,事件由事件源发布,事件源包括客户端和服务100,也即是,事件可以在客户端与服务100之间,或者服务100与服务100之间进行交互。
具体地,该Serverless架构可以预先获取多个函数、多个事件以及事件函数关系图,然后根据获取的多个函数的亲和关系,将其中满足亲和条件的多个指定函数的标识,按照该事件函数关系图组成的至少一个函数链分配给一个服务100,使得每个服务100包括至少一个函数链。其中,该事件函数关系图用于指示获取的多个函数和多个事件之间的触发关系,该亲和关系用于指示函数的关联性和相似性。
图1C是本申请实施例提供的另一种Serverless架构的示意图,如图1C所示,该Serverless架构包括集成开发环境(Integrated Development Environment,IDE)10、服务运行环境(Service Running Environment,SRE)20和函数运行环境(Function Running Environment, FRE)30。
IDE 10用于提供一套编程开发框架,使得开发者可以在该编程开发框架中进行函数链的预编程。具体地,开发者可以在该IDE10中实现函数的编程、事件的定义以及事件函数(Event-Function,E-F)关系图的编写,以通过该集成开发环境向Serverless架构提交多个函数、多个事件以及E-F关系图。
SRE 20用于为多个服务分配函数链,并对该多个服务进行管理。具体地,该SRE 20可以根据IDE10提交的多个函数、多个事件以及E-F关系图,分别将该多个函数中满足亲和条件的多个指定函数组成至少一个函数链,分配给一个服务,使得该多个服务中的每个服务包括至少一个函数链,并通过服务管理函数链。
具体地,该SRE 20包括服务管理(Service Manager)模块21,会话管理(Session Manager)模块22,负载均衡(Load Balance)模块23,名字服务(Name Service)模块24以及资源调度(Resource Scheduler)模块25。
Service Manager模块21用于将函数链分配给服务,以及管理服务的运行状态。其中,服务的运行状态包括启动、加载和结束等。
Session Manager模块22用于对进入服务的事件进行会话分类、对会话的状态进行记录等。其中,会话分类是指确定进行服务的事件所属的会话。
Load Balance模块23用于保证每个服务的服务实例之间的负载均衡。其中,每个服务通常配置有多个服务实例,每个服务实例用于运行对应的服务。
Name Service24用于实现服务的注册、注销或状态保存等。
Resource Scheduler模块25用于给每个服务的服务实例分配资源,以便通过分配的资源运行对应的服务实例。
FRE30用于在一个服务实例中加载函数链,根据传递进来的事件触发函数链的执行。其中,该服务实例所加载的函数链为对应的服务包括的函数链。具体地,FRE30包括事件调度(Event Scheduler)模块31,函数管理(Function Manager)模块32,会话管理(Session Manager)模块33和负载管理(Scale Manager)模块34。
Event Scheduler模块31用于根据传递进该服务实例的事件,调度函数链的加载执行。
Function Manager模块32用于实现函数链的管理和加载。
Session Manager模块33用于根据传递进行的事件所属的会话,将事件分配到所属会话对应的线程中进行处理。
Scale Manager模块34用于根据服务实例负荷的大小,动态调整服务实例内部执行线程的数目,以及当服务实例超载时,向SRE上报信息,以触发SRE对该服务配置的服务实例的数目进行调整。
图1D是本申请实施例提供的一种业务的Serverless架构示意图,如图1D所示,该Serverless架构包括业务模块1、软件运行环境和服务模型2、无服务运行(Serverless Runtime)模块3和IDE模块4。
业务模块1,主要用于实现Serverless架构的改造以及具体业务代码的分离和改造等。
软件运行环境和服务模型2,主要用于实现软件运行环境和服务的构建。
Serverless Runtime模块3,主要用于实现事件的调用以及函数链的执行等。
IDE模块4,主要用于实现函数的编程,以及E-F关系图的编写等。
其中,实线框中的业务传输模块1和软件运行环境和服务模型2可以参考现有Serverless架构,实现框中的Serverless Runtime模块3和IDE模块4由本申请提供。
本领域技术人员可以理解,图1C或图1D中示出的Serverless架构并不构成对Serverless架构的限定,实际应用中,Serverless架构可以包括比图示更多或更少的模块,或者组合某些模块,或者不同的部件模块,本申请实施例对此不做限定。
接下来对本申请实施例提供的事件驱动方法进行详细介绍。
图1E是申请实施例提供的一种事件驱动方法的流程图,该方法应用于上述图1B或图1C所述的Serverless架构,该Serverless架构部署有多个服务,每个服务包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数,且每个函数链是根据事件和函数的触发关系预先确定得到。如图1E所示,该方法包括如下步骤:
步骤101:获取多个函数、多个事件以及事件函数关系图,该事件函数关系图用于指示获取的多个函数和获取的多个事件之间的触发关系。
其中,所述多个函数中的每个函数为业务处理函数,用于实现具体的业务逻辑。所述多个事件中的每个事件实质是一种业务请求,用于请求实现特定的业务。另外,事件和函数之间具有特定的触发关系,一个事件可以触发一个或多个函数,一个函数也可以触发一个新的事件。
其中,所述多个函数的函数代码可以由开发人员预先编程,以定义该多个函数的功能。所述多个事件可以由开发人员预先定义,以定义每个事件的含义。事件函数关系图也可以由开发人员预先编写,以定义这多个函数和多个事件之间的触发关系。本申请实施例中的Serverless架构,可以为开发人员提供一个IDE,由开发人员在该IDE中进行函数的编程、事件的定义以及事件函数关系图的编写。
在一个实施例中,可以在该Serverless架构中设计一套IDE编程框架,该IDE编程框架用于定义用户的编程行为。例如,可以基于该IDE编程框架将系统的开发角色分区分为3类,分别为软件工程师(Software,SWE)、系统/模块工程师(System/Mdule,SE/MDE)以及平台开发人员。SWE和SE/MDE的任务是进行业务开发,平台开发人员的任务是进行平台开发。
其中,SWE的任务是通过该IDE编程框架编写函数的函数代码。SE/MDE的任务是通过该IDE编程框架定义整个系统的事件,以及分割业务系统,编写E-F关系图。进一步地,该SE/MDE的任务还包括通过该编程框架定义函数的亲和关系,该亲和关系用于指示函数之间的关联性和相似性,以便后续根据函数之间的亲和关系确定将哪些函数归入一个服务。平台开发人员的任务是开发FaaS平台,使得该FaaS平台可以获取SE/MDE编写的函数、事件以及E-F关系图,并可以解析该E-F关系图,调度实际物理资源,处理与服务和分布式相同的事务。需要说明的是,复杂的分布式相关的调度全部隐藏在该FaaS平台内部,对开发人员不可见,也即是,所有的和分布式、集群、资源调度和动态伸缩等等复杂的功能,开发人员将不感知,从而减轻开发人员的处理负担。
进一步地,该IDE编程框架还可以将SE/MDE编写的函数编译为SO文件,以及将E-F关系图编写为json文件。具体地,可以将一个函数编译为一个SO文件,也可以将多个函数编译为一个SO文件,本申请实施例对此不做限定。相应地,该FaaS平台可以直接获取编 译的SO文件和json文件,并对SO文件和json文件进行解析,得到多个函数以及E-F关系图。
在一个具体实施例中,参见图1F,该Serverless架构可以为开发人员提供IDE10,该IDE10可以包括函数编程模块、E-F编程模块和编译模块。其中,函数编程模块用于获取开发人员编写的函数代码,E-F编程模块用于获取开发人员编写的E-F关系图、定义的事件以及定义的函数亲和关系的定义,编译模块用于对获取的函数代码、E-F关系图、定义的事件和函数亲和关系进行编译,得到数据包,并输出该数据包。该数据包可以包括多个函数代码、E-F关系图、多个事件以及函数亲和关系。实际应用中,上述模块可以基于开发工具开发的插件来实现。
步骤102:根据获取的多个函数的亲和关系,确定获取的多个函数中满足亲和条件的多个指定函数,将该多个指定函数按照事件函数关系图组成的至少一个函数链分配给目标服务。
其中,该亲和关系用于指示函数之间的关联性,该亲和条件是指能够分配给一个服务的多个函数之间的亲和关系应该满足的条件。具体地,该亲和关系可以用于指示函数所实现业务之间的关联性,该亲和条件可以为多个指定函数所实现业务之间的关联性大于预设阈值。当然,该亲和关系也可以根据具体需要由开发人员进行设置,本申请实施例对此不做限定。
其中,该目标服务为该Serverless架构部署的多个服务中的任一服务。也即是,该多个服务中的每个服务均包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数。
获取到多个函数之后,该Serverless架构可以将其中满足亲和条件的部分函数归入一个服务,以将这部分函数使用相同的服务管理起来。其中,该至少一个函数链可以由满足亲和条件的多个指定函数的标识,按照该事件函数关系图组成,也可以由满足亲和条件的多个指定函数的标识以及该多个指定函数触发的至少一个事件的标识,按照该事件函数关系图组成。通过将组成的至少一个函数链分配给目标服务,可以使得该多个服务中的每个服务均包括至少一个函数链,且每个服务包括的至少一个函数链所指示的多个函数之间的亲和关系均满足亲和条件。
其中,每个函数链可以包括能够依次触发的多个函数的标识,或者包括能够依次触发的多个函数的标识和至少一个事件的标识。函数的标识用于唯一标识该函数,可以为函数的名称、标识号(Identification,ID)或指针等。事件的标识用于唯一标识该事件,可以为事件的名称或ID等。
以每个函数链包括能够依次触发的多个函数的ID和至少一个事件的ID为例,如图1G所示,E表示事件、F表示函数,服务A包括由函数ID和事件ID组成的两个函数链:函数链1和函数链2,服务B包括由函数ID和事件ID组成的一个函数链。比如,函数链1包括F1、E2、F2、E3、F3和F4以及表示触发关系的箭头,用于指示F1能够触发E2,E2能够触发F2,F2能够触发E3,E3能够分别触发F3和F4。
相关技术中,一个函数位于一个独立的容器(Docker)中,各个函数在各自所属的容器独立运行。而本申请实施例中,一个函数链所指示的多个函数可以位于相同的容器中,可以在相同的容器中运行一整个函数链,如此可以减小容器的维护量,以及避免一个函数一个容器运行导致频繁加载带来的高时延,提高系统性能。其中,容器是指为服务分配的用 于运行服务的资源。
而且,需要说明的是,相关技术中通常是将一个函数抽象为一个服务,然后通过事件以函数为单位进行驱动,在此过程中,触发的中间事件需要先进入事件队列进行排队,这将增加函数的执行时延,系统性能较低。而本申请实施例中,通过将满足亲和关系的多个函数按照该事件函数关系图组成至少一个函数链,并将组成的至少一个函数链分配给一个服务,实现了将一串函数链抽象为一个服务,通过服务以函数链为单位进行驱动,避免了事件的排队流程,缩短了函数的处理时延,提高了系统性能。
需要说明的是,步骤101和步骤102用于为Serverless架构部署的服务配置函数链,而在为服务配置完函数链之后,即可根据事件源发布的事件,通过服务以函数链为单位进行调度,也即是执行下述步骤103-105。另外,实际应用中,为服务配置完函数链之后,还可以根据需要对任意配置的函数链进行更改,本申请实施例对此不做限定。
步骤103:接收事件源发布的针对目标服务的目标事件,该目标服务为多个服务中的任一个,该事件源为客户端或者该多个服务中除该目标服务之外的其他服务。
其中,事件源发布的针对目标服务的目标事件是指事件源向目标服务发送的事件,
在该Serverless架构中,事件源可以向服务发布事件,以请求该服务为其提供业务服务。其中,所述事件源可以为客户端或该多个服务中的任一服务。也即是,在该Serverless架构中,事件可以在客户端与服务之间,或者服务与服务之间进行交互。
实际应用中,还可以将客户端与服务之间,或者服务与服务之间交互的事件称之为消息。
步骤104:从该目标服务包括的至少一个函数链中确定该目标事件对应的目标函数链。
对于事件源发布的针对目标服务的目标事件,可以直接从该目标服务包括的至少一个函数链中确定该目标事件对应的目标函数链。该目标事件对应的目标函数链是指该目标事件能够触发的函数链。
具体地,该目标事件可以携带该目标事件的标识,从该目标服务包括的至少一个函数链中确定该目标事件对应的目标函数链可以包括以下两种实现方式:
第一种实现方式:根据该目标事件的标识,以及存储的事件和函数的触发关系,确定该目标事件触发的目标函数;从该目标服务包括的至少一个函数链中确定以该目标函数为起点的函数链;将该以该目标函数为起点的函数链确定为该目标函数链。
本申请实施例中,每个服务可以预先存储事件和函数的触发关系,每个服务存储的事件和函数的触发关系可以包括系统中所有函数和事件的触发关系,或者仅包括该服务托管的函数链指示的多个函数和事件的触发关系,或者仅包括该服务托管的各个函数链的起点函数和事件的触发关系。
接收到针对目标服务的目标事件之后,可以获取该目标服务存储的事件和函数的触发关系,然后根据该目标事件的标识,以及该目标服务存储的事件和函数的触发关系,从该目标服务包括的至少一个函数链中确定该目标事件对应的目标函数链。
其中,事件和函数的触发关系可以包括多个事件的标识以及对应的该多个事件能够触发的函数的标识。具体地,根据该目标事件的标识,以及存储的事件和函数的触发关系,确定该目标事件触发的目标函数包括:根据该目标事件的标识,从存储的事件和函数的触发关系中查找该目标事件的标识对应的函数的标识,将该目标事件的标识对应的函数的标 识指示的函数作为该目标函数。
其中,该目标服务包括的至少一个函数链中的每个函数链可以包括能够依次触发的多个函数的标识,相应地,可以从该目标服务包括的至少一个函数链中确定以该目标函数的标识为起点的函数链,将以该目标函数的标识为起点的函数链作为该目标函数链。
例如,参见图1F,以目标服务为服务A,目标事件的标识为E1为例,可以先根据预先存储的事件和函数的触发关系,确定E1能够触发的目标函数的标识F1,然后从服务A包括的两个函数链中确定以F1为起点的函数链1作为目标函数链。
第二种实现方式:根据该目标事件的标识,以及存储的事件标识和函数链的对应关系,从该目标服务包括的至少一个函数链中确定该目标事件对应的目标函数链。
本申请实施例中,每个服务可以预先存储事件标识和函数链的对应关系,该事件标识和函数链的对应关系存储有每个服务包括的至少一个函数链以及每个函数链对应的事件的标识,每个函数链对应的事件的标识是指能够触发该函数链的起点函数的事件的标识。
具体地,可以根据该目标事件的标识,以及存储的事件标识和函数链的对应关系,从该目标服务包括的至少一个函数链中查找该目标事件的标识对应的函数链,并将该目标事件的标识对应的函数链确定为该目标事件对应的目标函数链。
步骤105:通过该目标服务,执行该目标函数链指示的能够依次触发的多个函数,以完成该目标事件的驱动。
具体地,通过该目标服务,执行该目标函数链指示的能够依次触发的多个函数可以包括:从为该目标服务配置的至少一个服务实例中确定目标服务实例,该至少一个服务实例中的每个服务实例用于运行该目标服务;在该目标服务实例中,执行该目标函数链指示的能够依次触发的多个函数。
在Serverless架构中,每个服务具有一个或多个服务实例,这些服务实例均用于运行该服务,也即是,每个服务实例均可以加载并运行该服务包括的至少一个函数链。其中,每个服务的服务实例的运行资源可以由该Serverless架构预先分配,具体地,可以由该Serverless架构按照预先设置的分配规则默认分配,也可以由技术人员按照实际需要人为分配。
例如,图1H是本申请实施例提供的一种SRE20的运行示意图,如图1H所示,该FRE20包括Service Manager模块21、Name Service模块24和Resource Scheduler模块25。
Service Manager模块21可以接收开发人员通过IDE提交的数据包,该数据包可以包括多个函数代码、E-F关系图、定义的多个事件以及函数亲和关系,然后对该数据包进行解析,根据解析得到的定义的函数亲和关系和E-F关系图,将符合亲和条件的多个函数组成至少一个函数链分配给一个服务。也即是,该Service Manager模块21用于为Serverless架构中的多个服务分配函数链。另外,该Service Manager模块21还可以向Resource Scheduler模块25发送资源申请,以为该多个服务的服务实例申请运行资源。
Resource Scheduler模块25用于根据Service Manager模块21的资源申请,为各个服务的服务实例分配运行资源。例如,可以在服务器1中创建两个容器,分别用于运行服务A,得到服务A的两个服务实例。可以在服务器2和服务器3中分别创建一个容器,用于运行服务B,得到服务B的两个服务实例。
在具体业务场景中,通常会有多用户的概念,如会话(Session)。Session是指多个客户 端之间的会话,每个会话通常包含一系列的事件。而且为了保证会话的顺序,通常需要将一个Session的事件串行处理,不同Session间的事件并行处理。但是相关技术中的Serverless架构,由于采用一个函数在一个容器中独立,并通过队列的方式进行事件驱动的方式,因此很难解决复杂场景下Session事件的串行和并行的协同问题。
另外,相关技术中,还提出了一种通过扩展队列的方式来提升并发度。例如,如图1I所示,假设Serverless架构中存在3个Session,分别为Session1、Session2和Session3,则可以为这3个Session分别创建对应的队列,并将各个Session产生的事件分别放入各个Session对应的队列中进行排队,以对各个Session的事件并行处理。但是一个真实的系统中通常存在百万甚至千万的Session,因此如果采用这种通过扩展队列来提升并发度的方式,也就需要创建百万甚至千万的队列,实际实现时很容易遇到瓶颈。
为了解决Session事件的串行和并行的协同问题,本申请实施例提供的Serverless架构还支持将同一会话的事件触发的函数链串行执行,将不同会话的事件触发的函数链并行执行。
具体地,目标事件还可以包括该目标事件所属的会话的标识,从为该目标服务配置的至少一个服务实例中确定目标服务实例可以包括:根据该会话的标识,从该至少一个服务实例中确定已执行了属于该会话的事件触发的函数的服务实例;将该已执行了属于该会话的事件触发的函数的服务实例,确定为该目标服务实例。之后,可以在该目标服务实例中,执行该目标函数链指示的能够依次触发的多个函数。通过这种方式,可以将属于同一会话的事件触发的函数链在同一个服务实例中进行处理,以实现Session事件的串行。
进一步地,本申请实施例中,每个服务实例包括事件执行体,事件执行体是函数链的执行单元,也即是,每个服务实例可以通过事件执行体来执行函数链。其中,每个服务实例可以包括一个事件执行体,也可以包括多个事件执行体,各个事件执行体都是独立的,可以并行处理函数链。也即是,通过事件执行体可以将函数链内的函数串行执行,将函数链间的函数并行执行。而且,本申请实施例提供的Serverless架构可以根据实际需要增加或删除每个服务实例的事件执行体的个数。
具体地,目标事件携带目标事件的标识,目标服务实例包括事件执行体,事件执行体用于执行函数链,相应地,在该目标服务实例中,执行该目标函数链指示的能够依次触发的多个函数可以包括如下步骤1-3:
1,在该目标服务实例中加载目标函数链。
2,将该目标事件的标识写入该目标服务实例的事件执行体,根据该目标事件的标识和在该目标服务实例中加载的该目标函数链,通过该事件执行体,执行该目标事件触发的函数。
其中,该事件执行体实质是一个函数代码段,该函数代码段包括一个事件标识变量。实际实现时,可以通过对事件执行体中的事件标识变量进行赋值,来触发事件执行体执行该目标函数链。在接收到目标事件之后,首先需要将该目标事件的标识写入该事件执行体,以触发该事件执行体执行该目标事件触发的函数。其中,将该目标事件的标识写入该事件执行体,是指将该事件标识变量赋值为该目标事件的标识。
具体地,该目标函数链可以包括能够依次触发的多个函数的标识,根据该目标事件的标识和该目标函数链,通过该事件执行体,执行该目标事件触发的函数可以包括:根据该 目标事件的标识,从该目标函数链包括的能够依次触发的多个函数的标识中获取该目标事件触发的函数的标识;根据该目标事件触发的函数的标识,通过该事件执行体,执行该目标事件触发的函数。
其中,该目标函数链包括的能够依次触发的多个函数的标识可以为该多个函数的ID或指针,用于指示该目标函数链指示的能够依次触发的多个函数的存储地址。
具体地,根据该目标事件触发的函数的标识,通过该事件执行体,执行该目标事件触发的函数可以包括以下两种实现方式:
第一种实现方式:当该目标函数链包括能够依次触发的多个函数的ID时,根据该目标事件的标识,从该目标函数链包括的能够依次触发的多个函数的ID中获取该目标事件触发的函数的ID;根据该目标事件触发的函数的ID,以及存储的函数ID和函数指针的对应关系中,确定该目标事件触发的函数的指针;根据该目标事件触发的函数的指针,通过该事件执行体,执行该目标事件触发的函数。
第二种实现方式:当该目标函数链包括能够依次触发的多个函数的指针时,根据该目标事件的标识,从该目标函数链包括的能够依次触发的多个函数的指针中获取该目标事件触发的函数的指针;根据该目标事件触发的函数的指针,通过该事件执行体,执行该目标事件触发的函数。
其中,根据该目标事件触发的函数的指针,通过该事件执行体,执行该目标事件触发的函数可以包括以下两种方式:
第一种实现方式:当该目标事件能够触发一个函数时,根据获取的函数的指针,通过该事件执行体,执行该目标事件触发的函数。
具体地,可以根据获取的函数的指针,确定该目标事件触发的函数的存储地址,从该存储地址获取该目标事件触发的函数,通过该事件执行体,执行该目标事件触发的函数。
第二种实现方式:当该目标事件能够触发多个函数时,将获取的多个函数的指针放入预设堆栈中进行压栈处理;根据压栈处理的多个函数的指针的出栈顺序,通过该事件执行体,依次执行该目标事件触发的多个函数。
其中,所述获取的多个函数是指该目标事件能够触发多个函数。
具体地,根据压栈处理的多个函数的指针的出栈顺序,通过该事件执行体,依次执行该目标事件触发的多个函数包括以下步骤1)-3):
1)对该压栈处理的多个函数的指针中位于栈顶的第一函数的指针进行出栈处理,根据第一函数的指针获取第一函数,通过该事件执行体执行该第一函数。当检测到通过该事件执行体执行该第一个出栈的函数之后发布了新的事件时,将该事件执行体中写入的该目标事件的标识更新为该新的事件的标识,根据该新的事件的标识和该目标函数链,通过该事件执行体,执行该新的事件触发的函数,直至通过该事件执行体执行完该第一函数在该目标函数链所在支路为止。
2)在通过该事件执行体执行完该第一函数位于该目标函数链所在的支路之后,或者在通过该事件执行体执行该第一函数之后未检测到发布新的事件时,将该压栈处理的多个函数的指针中在第一函数的指针的栈位之下的第二函数的指针进行出栈处理,根据该第二函数的指针获取第二函数,并按照通过该事件执行体执行该第一函数的方式,通过该事件执行体执行第二函数,直至通过该事件执行体执行完该第二函数在该目标函数链所在支路为 止。
3)重复步骤2),直至将该压栈处理的多个函数的指针中位于栈底的最后一个函数的指针进行出栈处理,并通过该事件执行体执行完该最后一个函数在该目标函数链中所在支路为止。
例如,参见图1J,假设目标事件为Event1,且Event1被两个函数(F2和F1)订阅,即Event1能够触发F2和F1这两个函数。其中,F2能够触发一个新的事件Event2,Event2能够触发一个新的函数F3,F1能够触发一个新的事件Event3。则参见图K,可以先将F2和F1的指针分别放入预设堆栈中进行压栈处理,然后将位于栈顶的F2的指针进行出栈处理,并通过事件执行体执行F2,执行完F2之后将发布新的事件Event2,并根据Event2触发执行F3。在执行完F3之后,即可将F1的指针进行出栈处理,并通过执行体执行F1。
在另一实施例中,当该目标事件能够触发多个函数时,还可以将该多个函数中的一个函数通过当前的事件执行体进行处理,并将该多个函数的其他函数调度到该目标服务实例中除该事件执行体之外的其他事件执行体进行处理。如此,可以通过多个事件执行体对该多个函数进行异步处理,增加并发性。
3,当检测到在通过该事件执行体执行该目标事件触发的函数之后发布了新的事件时,将该事件执行体中写入的该目标事件的标识更新为该新的事件的标识,根据该新的事件的标识和该目标函数链,通过该事件执行体,执行该新的事件触发的函数,直至通过该事件执行体执行完该目标函数链包括的所有函数为止。
当检测到在通过该事件执行体执行该目标事件触发的函数之后发布了新的事件时,可以从该新的事件中获取携带的新的事件的标识,并该事件执行体中已写入的目标事件的标识更新为该新的事件的标识,以将该事件执行体中的事件标识的变量重新赋值为该新的事件的标识,触发该事件执行体执行该新的事件触发的函数。
其中,根据该新的事件的标识和该目标函数链,通过该事件执行体,执行该新的事件触发的函数的方式,与上述根据该目标事件的标识和该目标函数链,通过该事件执行体,执行该目标事件触发的函数的方式同理,具体实现方式可以参考上述步骤2的相关描述,本申请实施例在此不再赘述。
也即是,在通过事件执行体执行该目标函数链的过程中,如果触发了新的事件发布,则可以通过将该事件执行体中已写入的事件标识修改为该新的事件的标识,来触发新的事件的执行;如果一个事件触发了多个函数,则可以将该多个函数进行入栈处理,并根据该多个函数的出栈顺序,通过该事件执行体依次执行该多个函数所在的支路,或者,也可以将该多个函数中的部分函数调度到其他事件执行体中进行处理。
本申请实施例中,可以通过修改事件执行体的事件标识变量,来触发事件执行体执行函数链。参见图1L,事件执行体包括事件标识变量,外部事件进入该事件执行体所在的服务实例之后,可以根据该事件的标识获取对应的函数链,并将该事件的标志写入该事件执行体,以使该事件执行体根据写入的事件的标识和对应的函数链,执行该事件触发的函数。而在执行该事件触发的函数之后如果发布了新的事件,则可以根据该新的事件的标识,更新该事件执行体的事件标识变量,以使该事件执行体根据更新后的事件标识变量和对应的函数链,执行新的事件触发的函数,直至执行完该函数链指示的所有函数为止。
进一步地,本申请实施例还支持在服务实例内,将Session内的事件串行执行,将Session 间的事件并行执行。具体地,每个服务实例还可以包括多个Faas实例,Faas实例为服务实例的下一级,且该多个Faas实例具有相同的执行逻辑,可以并行处理调度到该服务实例的多个事件。其中,服务实例相当于服务的进程,服务实例的多个Faas实例相当于进程的多个线程。对于调度到目标服务实例的执行的事件,还可以在目标服务实例内,将属于同一Session的事件调度到同一Faas实例执行,将属于不同Session的事件调度到相同或不同Faas实例执行,以支持Session内的事件串行执行,Session间的事件并行执行,进一步实现Session事件的串并行协调调度。
例如,参见图1M,假设目标服务包括3个服务实例:服务实例1,服务实例2和服务实例3,服务实例1包括3个Faas实例:Faas实例1,Faas实例2和Faas实例3,进入该目标服务的事件包括分别属于Session1、Session2和Session3的事件。实际实现时,可以将Session1的事件依次调度到Faas实例1进行处理,将Session2的事件依次调度到Faas实例2进行处理,将Session3的事件依次调度到Faas实例3进行处理。如此可以实现Session内的事件串行执行,Session间的事件并行执行。
图1N是本申请实施例提供的一种服务实例的部署关系图,如图1H所示,假设该Serverless架构部署有两个服务:服务A和服务B,服务A可以在预先分配的容器中设置多个服务实例,服务B也可以在预先分配的容器中设置多个服务实例。其中,每个服务实例可以包括多个Faas实例,用于运行对应服务包括的函数链。而且,该Serverless架构还可以包括缓存服务,该缓存服务用于缓存Session的运行状态。
本申请实施例中,业务被抽象为基于函数链的事件驱动方式,可以支持事件的高效快速调度。例如,在一个实施例中,假设有1000个Session,每个Session有5个事件,则这1000个Session一共有5000个事件,假设这5000个事件共触发18个函数链,则通过本申请提供的事件驱动方法,这5000个事件全部处理完成的总时长小于40ms,平均每个事件的处理时长小于8us。其中,函数链中每个函数的调用时长也在us数量级,性能已经直接逼近函数的直接调用,极大地提升了系统性能。
下表1为相关技术中提供的一种基于队列的事件驱动实例和本申请实施例提供的一种基于函数链的事件驱动实例的性能对比表,如表1所示,基于队列的事件驱动实例仅能支持1000个Session并发,而基于函数链的事件驱动实例则可以支持千万级Session的并发,并发度大大提升,而且,基于队列的事件驱动实例的执行时延为200ms,而基于函数链的事件驱动实例的执行时延可以小于10us,执行时延也大大缩短,提升了系统性能。
表1
本申请实施例中,可以在Serverless架构中部署多个服务,每个服务包括至少一个函数 链,每个函数链用于指示能够依次触发的多个函数,当接收到事件源发布的针对目标服务的目标事件时,可以从目标服务包括的至少一个函数链中确定该目标事件对应的目标函数链,然后通过目标服务执行该目标函数链指示的能够依次触发的多个函数,以完成目标事件的驱动。也即是,在本申请提供的Serverless架构,事件可以通过服务直接触发一整个函数链,从而以函数链为单位进行驱动,如此可以避免以函数为单位驱动时触发的中间事件需要进行的排队流程,减小了函数的执行时长,缩短了业务处理流程的时延,提高了系统性能。
图2是本申请实施例提供的一种事件驱动装置的结构示意图,该事件驱动装置应用于无服务器Serverless架构中,所述Serverless架构部署有多个服务,每个服务包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数,且每个函数链是根据事件和函数的触发关系预先确定得到,所述装置包括接收模块201、确定模块202和执行模块203。
接收模块201,用于执行上述图1E所述实施例中步骤103执行的操作;
第一确定模块202,用于执行上述图1E所述实施例中步骤104执行的操作;
执行模块203,用于执行上述图1E所述实施例中步骤105执行的操作。
可选地,所述装置还包括获取模块、第二确定模块和分配模块:
获取模块,用于执行上述图1E所述实施例中步骤101执行的操作;
第二确定模块和分配模块,用于执行上述图1E所述实施例中步骤102执行的操作。
可选地,目标事件携带目标事件的标识;所述第一确定模块202具体用于执行上述图1E所述实施例中步骤104所述的第一种实现方式或第二种实现方式。
可选地,所述执行模块203包括:
确定单元,用于从为该目标服务配置的至少一个服务实例中确定目标服务实例,该至少一个服务实例中的每个服务实例用于运行该目标服务;
执行单元,用于在该目标服务实例中,执行该目标函数链指示的能够依次触发的多个指函数。
可选地,该目标事件携带该目标事件的标识,该目标服务实例包括事件执行体,该事件执行体用于执行函数链;该执行单元具体用于:
在该目标服务实例中加载该目标函数链;
将该目标事件的标识写入该事件执行体;
根据该目标事件的标识和在该目标服务实例中加载的该目标函数链,通过该事件执行体,执行该目标事件触发的函数;
当检测到在通过该事件执行体执行该目标事件触发的函数之后发布了新的事件时,将该事件执行体中写入的该目标事件的标识更新为该新的事件的标识,根据该新的事件的标识和在该目标服务实例中加载的该目标函数链,通过该事件执行体,执行该新的事件触发的函数,直至通过该事件执行体执行完该目标函数链包括的所有函数为止。
可选地,该目标函数链包括能够依次触发的多个函数的指针,用于指示能够依次触发的多个函数的存储地址;
该执行单元具体用于:
根据该目标事件的标识,从该目标函数链包括的能够依次触发的多个函数的指针中获 取该目标事件触发的函数的指针;
根据该目标事件触发的函数的指针,通过该事件执行体,执行该目标事件触发的函数。
可选地,该执行单元具体用于:
当该目标事件能够触发一个函数时,根据获取的函数的指针,确定该目标事件触发的函数的存储地址;从该存储地址获取该目标事件触发的函数;通过该事件执行体,执行该目标事件触发的函数;
当该目标事件能够触发多个函数时,将获取的多个函数的指针放入预设堆栈中进行压栈处理;根据压栈处理的多个函数的指针的出栈顺序,通过该事件执行体,依次执行该目标事件触发的多个函数。
可选地,该目标事件携带该目标事件所属的会话的标识;
该确定模块具体用于:
根据该会话的标识,从该至少一个服务实例中确定已执行了属于该会话的事件触发的函数的服务实例;
将该已执行了属于该会话的事件触发的函数的服务实例,确定为该目标服务实例。
本申请实施例中,可以在Serverless架构中部署多个服务,每个服务包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数,当接收到事件源发布的针对目标服务的目标事件时,可以从目标服务包括的至少一个函数链中确定该目标事件对应的目标函数链,然后通过目标服务执行该目标函数链指示的能够依次触发的多个函数,以完成目标事件的驱动。也即是,在本申请提供的Serverless架构,事件可以通过服务直接触发一整个函数链,从而以函数链为单位进行驱动,如此可以避免以函数为单位驱动时触发的中间事件需要进行的排队流程,减小了函数的执行时长,缩短了业务处理流程的时延,提高了系统性能。
需要说明的是:上述实施例提供的事件驱动装置在进行事件驱动时,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。另外,上述实施例提供的事件驱动装置与事件驱动方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。
在另一实施例中,还提供了一种计算机可读存储介质,所述计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述图1E实施例所述的事件驱动方法。
在另一实施例中,还提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述图1E实施例所述的事件驱动方法。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意结合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如:同轴电缆、光纤、 数据用户线(Digital Subscriber Line,DSL))或无线(例如:红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如:软盘、硬盘、磁带)、光介质(例如:数字通用光盘(Digital Versatile Disc,DVD))、或者半导体介质(例如:固态硬盘(Solid State Disk,SSD))等。
本领域普通技术人员可以理解实现上述实施例的全部或部分步骤可以通过硬件来完成,也可以通过程序来指令相关的硬件完成,所述的程序可以存储于一种计算机可读存储介质中,上述提到的存储介质可以是只读存储器,磁盘或光盘等。
以上所述为本申请提供的实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。
Claims (16)
- 一种事件驱动方法,其特征在于,应用于无服务器Serverless架构中,所述Serverless架构部署有多个服务,每个服务包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数,且每个函数链是根据事件和函数的触发关系预先确定得到,所述方法包括:接收事件源发布的针对目标服务的目标事件,所述目标服务为所述多个服务中的任一个,所述事件源为客户端或者所述多个服务中除所述目标服务之外的其他服务;从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链;通过所述目标服务,执行所述目标函数链指示的能够依次触发的多个函数,以完成所述目标事件的驱动。
- 如权利要求1所述的方法,其特征在于,所述从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链之前,还包括:获取多个函数、多个事件以及事件函数关系图,所述事件函数关系图用于指示获取的多个函数和获取的多个事件之间的触发关系;根据所述获取的多个函数的亲和关系,确定所述获取的多个函数中满足亲和条件的多个指定函数;将所述多个指定函数的标识按照所述事件函数关系图组成的至少一个函数链分配给所述目标服务。
- 如权利要求1或2所述的方法,其特征在于,所述目标事件携带所述目标事件的标识;所述从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链,包括:根据所述目标事件的标识,以及存储的事件和函数的触发关系,确定所述目标事件触发的目标函数;从所述目标服务包括的至少一个函数链中确定以所述目标函数为起点的函数链;将所述以所述目标函数为起点的函数链确定为所述目标函数链;或者,根据所述目标事件的标识,以及存储的事件标识和函数链的对应关系,从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链。
- 如权利要求1-3任一所述的方法,其特征在于,所述通过所述目标服务,执行所述目标函数链指示的能够依次触发的多个函数,包括:从为所述目标服务配置的至少一个服务实例中确定目标服务实例,所述至少一个服务实例中的每个服务实例用于运行所述目标服务;在所述目标服务实例中,执行所述目标函数链指示的能够依次触发的多个函数。
- 如权利要求4所述的方法,其特征在于,所述目标事件携带所述目标事件的标识,所述目标服务实例包括事件执行体,所述事件执行体用于执行函数链;所述在所述目标服务实例中,执行所述目标函数链指示的能够依次触发的多个函数,包 括:在所述目标服务实例中加载所述目标函数链;将所述目标事件的标识写入所述事件执行体;根据所述目标事件的标识和在所述目标服务实例中加载的所述目标函数链,通过所述事件执行体,执行所述目标事件触发的函数;当检测到在通过所述事件执行体执行所述目标事件触发的函数之后发布了新的事件时,将所述事件执行体中写入的所述目标事件的标识更新为所述新的事件的标识,根据所述新的事件的标识和在所述目标服务实例中加载的所述目标函数链,通过所述事件执行体,执行所述新的事件触发的函数,直至通过所述事件执行体执行完所述目标函数链包括的所有函数为止。
- 如权利要求5所述的方法,其特征在于,所述目标函数链包括能够依次触发的多个函数的指针,用于指示能够依次触发的多个函数的存储地址;所述根据所述目标事件的标识和在所述目标服务实例中加载的所述目标函数链,通过所述事件执行体,执行所述目标事件触发的函数,包括:根据所述目标事件的标识,从所述目标函数链包括的能够依次触发的多个函数的指针中获取所述目标事件触发的函数的指针;根据所述目标事件触发的函数的指针,通过所述事件执行体,执行所述目标事件触发的函数。
- 如权利要求6所述的方法,其特征在于,所述根据所述目标事件触发的函数的指针,通过所述事件执行体,执行所述目标事件触发的函数,包括:当所述目标事件能够触发一个函数时,根据获取的函数的指针,确定所述目标事件触发的函数的存储地址;从所述存储地址获取所述目标事件触发的函数;通过所述事件执行体,执行所述目标事件触发的函数;当所述目标事件能够触发多个函数时,将获取的多个函数的指针放入预设堆栈中进行压栈处理;根据压栈处理的多个函数的指针的出栈顺序,通过所述事件执行体,依次执行所述目标事件触发的多个函数。
- 如权利要求4-7任一所述的方法,其特征在于,所述目标事件携带所述目标事件所属的会话的标识;所述从为所述目标服务配置的至少一个服务实例中确定目标服务实例,包括:根据所述会话的标识,从所述至少一个服务实例中确定已执行了属于所述会话的事件触发的函数的服务实例;将所述已执行了属于所述会话的事件触发的函数的服务实例,确定为所述目标服务实例。
- 一种事件驱动装置,其特征在于,应用于无服务器Serverless架构中,所述Serverless架构部署有多个服务,每个服务包括至少一个函数链,每个函数链用于指示能够依次触发的多个函数,且每个函数链是根据事件和函数的触发关系预先确定得到,所述装置包括:接收模块,用于接收事件源发布的针对目标服务的目标事件,所述目标服务为所述多个服务中的任一个,所述事件源为客户端或者所述多个服务中除所述目标服务之外的其他服务;第一确定模块,用于从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链;执行模块,用于通过所述目标服务,执行所述目标函数链指示的能够依次触发的多个函数,以完成所述目标事件的驱动。
- 如权利要求9所述的装置,其特征在于,所述装置还包括:获取模块,用于获取多个函数、多个事件以及事件函数关系图,所述事件函数关系图用于指示获取的多个函数和获取的多个事件之间的触发关系;第二确定模块,用于根据所述获取的多个函数的亲和关系确定所述获取的多个函数中满足亲和条件的多个指定函数;分配模块,用于将所述多个指定函数的标识按照所述事件函数关系图组成的至少一个函数链分配给所述目标服务。
- 如权利要求9或10所述的装置,其特征在于,所述目标事件携带所述目标事件的标识;所述第一确定模块具体用于:根据所述目标事件的标识,以及存储的事件和函数的触发关系,确定所述目标事件触发的目标函数;从所述目标服务包括的至少一个函数链中确定以所述目标函数为起点的函数链;将所述以所述目标函数为起点的函数链确定为所述目标函数链;或者,根据所述目标事件的标识,以及存储的事件标识和函数链的对应关系,从所述目标服务包括的至少一个函数链中确定所述目标事件对应的目标函数链。
- 如权利要求9-11任一所述的装置,其特征在于,所述执行模块包括:确定单元,用于从为所述目标服务配置的至少一个服务实例中确定目标服务实例,所述至少一个服务实例中的每个服务实例用于运行所述目标服务;执行单元,用于在所述目标服务实例中,执行所述目标函数链指示的能够依次触发的多个函数。
- 如权利要求12所述的装置,其特征在于,所述目标事件携带所述目标事件的标识,所述目标服务实例包括事件执行体,所述事件执行体用于执行函数链;所述执行单元具体用于:在所述目标服务实例中加载所述目标函数链;将所述目标事件的标识写入所述事件执行体;根据所述目标事件的标识和在所述目标服务实例中加载的所述目标函数链,通过所述事件执行体,执行所述目标事件触发的函数;当检测到在通过所述事件执行体执行所述目标事件触发的函数之后发布了新的事件时, 将所述事件执行体中写入的所述目标事件的标识更新为所述新的事件的标识,根据所述新的事件的标识和在所述目标服务实例中加载的所述目标函数链,通过所述事件执行体,执行所述新的事件触发的函数,直至通过所述事件执行体执行完所述目标函数链包括的所有函数为止。
- 如权利要求13所述的装置,其特征在于,所述目标函数链包括能够依次触发的多个函数的指针,用于指示能够依次触发的多个函数的存储地址;所述执行单元具体用于:根据所述目标事件的标识,从所述目标函数链包括的能够依次触发的多个函数的指针中获取所述目标事件触发的函数的指针;根据所述目标事件触发的函数的指针,通过所述事件执行体,执行所述目标事件触发的函数。
- 如权利要求14所述的装置,其特征在于,所述执行单元具体用于:当所述目标事件能够触发一个函数时,根据获取的函数的指针,确定所述目标事件触发的函数的存储地址;从所述存储地址获取所述目标事件触发的函数;通过所述事件执行体,执行所述目标事件触发的函数;当所述目标事件能够触发多个函数时,将获取的多个函数的指针放入预设堆栈中进行压栈处理;根据压栈处理的多个函数的指针的出栈顺序,通过所述事件执行体,依次执行所述目标事件触发的多个函数。
- 如权利要求12-15任一所述的装置,其特征在于,所述目标事件携带所述目标事件所属的会话的标识;所述确定模块具体用于:根据所述会话的标识,从所述至少一个服务实例中确定已执行了属于所述会话的事件触发的函数的服务实例;将所述已执行了属于所述会话的事件触发的函数的服务实例,确定为所述目标服务实例。
Priority Applications (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
EP18905106.3A EP3742293B1 (en) | 2018-02-12 | 2018-12-29 | Event driving method and device |
US16/987,555 US20200364098A1 (en) | 2018-02-12 | 2020-08-07 | Event driving method and apparatus |
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810153094.4 | 2018-02-12 | ||
CN201810153094.4A CN110162413B (zh) | 2018-02-12 | 2018-02-12 | 事件驱动方法及装置 |
Related Child Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
US16/987,555 Continuation US20200364098A1 (en) | 2018-02-12 | 2020-08-07 | Event driving method and apparatus |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2019153973A1 true WO2019153973A1 (zh) | 2019-08-15 |
Family
ID=67548157
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2018/125823 WO2019153973A1 (zh) | 2018-02-12 | 2018-12-29 | 事件驱动方法及装置 |
Country Status (4)
Country | Link |
---|---|
US (1) | US20200364098A1 (zh) |
EP (1) | EP3742293B1 (zh) |
CN (1) | CN110162413B (zh) |
WO (1) | WO2019153973A1 (zh) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110650215A (zh) * | 2019-10-24 | 2020-01-03 | 百度在线网络技术(北京)有限公司 | 边缘网络的函数执行方法及装置 |
Families Citing this family (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US10901783B2 (en) * | 2018-10-16 | 2021-01-26 | Vmware, Inc. | Reducing the startup latency of functions in a FaaS infrastructure |
CN112929195A (zh) * | 2019-12-05 | 2021-06-08 | 北京沃东天骏信息技术有限公司 | 服务系统、由服务系统执行的方法、处理装置和存储介质 |
CN111274297A (zh) * | 2020-01-19 | 2020-06-12 | 政采云有限公司 | 一种基于存储库的无服务端化共享资源方法及系统 |
CN111314735A (zh) * | 2020-03-06 | 2020-06-19 | 新华智云科技有限公司 | 视频处理方法、系统及存储介质 |
CN111526202B (zh) * | 2020-04-29 | 2023-04-25 | 华润电力技术研究院有限公司 | 一种风机故障预警系统和方法 |
CN111797314A (zh) * | 2020-06-28 | 2020-10-20 | 百度在线网络技术(北京)有限公司 | 数据处理方法、装置、设备和存储介质 |
US11948010B2 (en) * | 2020-10-12 | 2024-04-02 | International Business Machines Corporation | Tag-driven scheduling of computing resources for function execution |
CN112328362B (zh) * | 2020-11-03 | 2023-03-28 | 浪潮云信息技术股份公司 | 一种基于容器技术实现函数计算服务的方法 |
US20220253347A1 (en) * | 2021-02-10 | 2022-08-11 | International Business Machines Corporation | Reducing start latency of serverless microservices |
CN113065302B (zh) * | 2021-03-23 | 2023-03-17 | 芯华章科技股份有限公司 | 用于仿真逻辑系统设计的方法、仿真器及可读存储介质 |
CN113157570A (zh) * | 2021-04-07 | 2021-07-23 | 腾讯音乐娱乐科技(深圳)有限公司 | 确定触发主体信息的方法、设备及存储介质 |
CN114257597B (zh) * | 2021-12-22 | 2023-12-29 | 中国工商银行股份有限公司 | 用于函数计算的并发控制方法、装置、设备及介质 |
US12020022B2 (en) | 2022-03-10 | 2024-06-25 | International Business Machines Corporation | In-band instantiation configuration for application workloads |
CN115834708B (zh) * | 2022-11-23 | 2024-10-18 | 中科驭数(北京)科技有限公司 | 负载均衡方法、装置、设备及计算机可读存储介质 |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101582916A (zh) * | 2009-06-19 | 2009-11-18 | 武汉钢铁(集团)公司 | 一种基于p2p的网络应用系统及其应用方法 |
WO2016190912A1 (en) * | 2015-01-26 | 2016-12-01 | Adventive Ipbank | Secure dynamic communication network and protocol |
US20170024717A1 (en) * | 2015-07-21 | 2017-01-26 | Mitoc Group Inc. | Microapplications Software Marketplace for Digital Systems and Method of Use |
CN106681834A (zh) * | 2016-12-28 | 2017-05-17 | 上海优刻得信息科技有限公司 | 分布式计算方法、管理装置及系统 |
US20170160963A1 (en) * | 2015-12-08 | 2017-06-08 | Ultrata, Llc | Object memory interfaces across shared links |
Family Cites Families (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9417938B2 (en) * | 2009-03-17 | 2016-08-16 | Microsoft Technology Licensing, Llc | Remote procedure call chains |
CN101833712B (zh) * | 2010-05-27 | 2012-06-27 | 湖南科技大学 | 一种支持工作流活动实例成批处理执行的方法 |
CN102932474B (zh) * | 2012-11-14 | 2015-06-17 | 北京星网锐捷网络技术有限公司 | 报文解析方法、设备及系统 |
WO2014186760A2 (en) * | 2013-05-17 | 2014-11-20 | Huawei Technologies Co., Ltd. | Multi-tier push service control architecture for large scale conference over icn |
CN105934914A (zh) * | 2013-12-19 | 2016-09-07 | 谷歌公司 | 用于服务处理的系统、方法和计算机程序产品 |
US10581703B2 (en) * | 2014-12-24 | 2020-03-03 | Koninklijke Kpn N.V. | Method for controlling on-demand service provisioning |
US20170060112A1 (en) * | 2015-08-24 | 2017-03-02 | Katrina Danielle PIRNER | Control program for accessing browser data and for controlling appliance |
-
2018
- 2018-02-12 CN CN201810153094.4A patent/CN110162413B/zh active Active
- 2018-12-29 WO PCT/CN2018/125823 patent/WO2019153973A1/zh unknown
- 2018-12-29 EP EP18905106.3A patent/EP3742293B1/en active Active
-
2020
- 2020-08-07 US US16/987,555 patent/US20200364098A1/en not_active Abandoned
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101582916A (zh) * | 2009-06-19 | 2009-11-18 | 武汉钢铁(集团)公司 | 一种基于p2p的网络应用系统及其应用方法 |
WO2016190912A1 (en) * | 2015-01-26 | 2016-12-01 | Adventive Ipbank | Secure dynamic communication network and protocol |
US20170024717A1 (en) * | 2015-07-21 | 2017-01-26 | Mitoc Group Inc. | Microapplications Software Marketplace for Digital Systems and Method of Use |
US20170160963A1 (en) * | 2015-12-08 | 2017-06-08 | Ultrata, Llc | Object memory interfaces across shared links |
CN106681834A (zh) * | 2016-12-28 | 2017-05-17 | 上海优刻得信息科技有限公司 | 分布式计算方法、管理装置及系统 |
Non-Patent Citations (1)
Title |
---|
See also references of EP3742293A4 |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110650215A (zh) * | 2019-10-24 | 2020-01-03 | 百度在线网络技术(北京)有限公司 | 边缘网络的函数执行方法及装置 |
Also Published As
Publication number | Publication date |
---|---|
US20200364098A1 (en) | 2020-11-19 |
CN110162413B (zh) | 2021-06-04 |
EP3742293A4 (en) | 2021-03-17 |
EP3742293A1 (en) | 2020-11-25 |
CN110162413A (zh) | 2019-08-23 |
EP3742293B1 (en) | 2024-11-06 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2019153973A1 (zh) | 事件驱动方法及装置 | |
US11216302B2 (en) | Modifying task dependencies at worker nodes using precompiled libraries | |
CN108537543B (zh) | 区块链数据的并行处理方法、装置、设备和存储介质 | |
US8434085B2 (en) | Scalable scheduling of tasks in heterogeneous systems | |
WO2016078008A1 (zh) | 调度数据流任务的方法和装置 | |
US20150199214A1 (en) | System for distributed processing of stream data and method thereof | |
WO2017016421A1 (zh) | 一种集群中的任务执行方法及装置 | |
US11321090B2 (en) | Serializing and/or deserializing programs with serializable state | |
CN106775948B (zh) | 一种基于优先级的云任务调度方法及装置 | |
CN112307065B (zh) | 一种数据处理方法、装置及服务器 | |
CN113051245A (zh) | 用于迁移数据的方法、装置及系统 | |
Zhong et al. | Speeding up Paulson’s procedure for large-scale problems using parallel computing | |
US20200310828A1 (en) | Method, function manager and arrangement for handling function calls | |
CN113225269A (zh) | 基于容器的工作流调度方法、装置、系统及存储介质 | |
CN109271236A (zh) | 一种业务调度的方法、装置、计算机存储介质及终端 | |
CA2631255A1 (en) | Scalable scheduling of tasks in heterogeneous systems | |
CN114357029A (zh) | 业务数据的处理方法、装置、设备、介质及程序产品 | |
CN112486468A (zh) | 基于spark内核的任务执行方法、系统和计算机设备 | |
CN113407343A (zh) | 一种基于资源分配的业务处理方法、装置及设备 | |
CN112748855B (zh) | 处理高并发数据请求的方法和装置 | |
CN117271122A (zh) | 基于cpu和gpu分离的任务处理方法、装置、设备及存储介质 | |
CN116881003A (zh) | 资源分配方法、装置、服务设备及存储介质 | |
JP2016081495A (ja) | 高負荷経路に基づく複合イベントの処理装置及びその方法 | |
CN117093335A (zh) | 分布式存储系统的任务调度方法及装置 | |
GB2600554A (en) | Method and system to identify and prioritize re-factoring to improve micro-service identification |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 18905106 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
ENP | Entry into the national phase |
Ref document number: 2018905106 Country of ref document: EP Effective date: 20200817 |