Application starting method and device, equipment, storage medium and program product
By constructing a directed graph parallel execution service instance, the problem of prolonged application startup time in distributed banking systems was solved, and the application startup efficiency was improved.
Patent Information
- Application Number
- CN202511595433.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-03
- Publication Date
- 2026-01-23
AI Technical Summary
Existing technologies in distributed banking systems suffer from prolonged startup times due to serial execution mechanisms, impacting the efficiency of continuous application deployment.
A directed graph is constructed based on the dependencies between multiple service instances of the application. The directed graph is traversed to obtain a list of services to be executed. A thread pool is then created based on this list, and threads are allocated to each set of services to be executed to execute the service instances in parallel.
By executing service instances in parallel, application startup time is reduced and application efficiency is improved during continuous deployment.
Smart Images

Figure CN121387393A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of financial technology, and in particular to an application starting method, an electronic device, a storage medium and a program product. BACKGROUND
[0002] In a distributed banking system, the application involves initialization operations on a large number of service instances during the startup process. Among them, part of the service instances involve high-delay network input and output operations, such as connection authentication of a remote configuration center, pre-warm loading of a distributed cache, and establishment of a database connection pool.
[0003] The prior art uses a serial execution mechanism to initialize a large number of service instances, that is, to create and initialize components (Beans) one by one in order. In this method, the Bean after the previous Bean must wait for the completion of the initialization before starting the loading operation.
[0004] Therefore, when there are independent Beans without dependency, due to the limitation of the serial execution mechanism, the independent Beans need to wait for the completion of the initialization of the multiple Beans in front of them before performing the initialization operation, thereby prolonging the time of application startup and affecting the efficiency of the application in continuous deployment. SUMMARY
[0005] The present application provides an application starting method, an electronic device, a storage medium and a program product to solve the technical problem that the prior art prolongs the time of application startup and thus affects the efficiency of the application in continuous deployment.
[0006] In a first aspect, the present application provides an application starting method, comprising:
[0007] When the application starts, a directed graph is constructed based on the dependency relationship between a plurality of service instances of the application;
[0008] A plurality of service instances corresponding to a to-be-executed list are obtained by traversing the directed graph, and a thread pool is created based on the to-be-executed list, the to-be-executed list comprising: a plurality of service instances corresponding to a to-be-executed set;
[0009] A corresponding thread is allocated to each to-be-executed set, and the service instances in the corresponding to-be-executed set are executed in parallel through the thread.
[0010] In a possible implementation, the above-mentioned constructing a directed graph based on the dependency relationship between a plurality of service instances of the application comprises:
[0011] The dependency relationship between the plurality of service instances is determined, and the dependency relationship is used to represent the calling relationship between the plurality of service instances;
[0012] Each service instance is taken as a node, and a directed edge is established between multiple nodes according to the dependency relationship;
[0013] A directed graph is constructed based on the multiple nodes and the directed edges.
[0014] In a possible implementation, the initial state of the to-be-executed list is empty, and the traversing of the directed graph to obtain the to-be-executed list corresponding to the multiple service instances comprises the following steps.
[0015] The directed graph is traversed to determine multiple root nodes with an in-degree of 0;
[0016] Any root node in the multiple root nodes is selected, a corresponding to-be-executed set is created in the to-be-executed list, the root node is added to the to-be-executed set, and the traversal state of the root node is updated to be traversed. The initial traversal state of the multiple nodes in the directed graph is: not traversed.
[0017] It is determined whether the root node corresponds to at least one directed edge.
[0018] In a case where the root node corresponds to at least one directed edge, successor nodes of the root node are sequentially added to the to-be-executed set according to the directions of the directed edges.
[0019] Any root node with a traversal state of not traversed is selected, and the above steps are repeatedly executed until the traversal states of the multiple root nodes are all traversed.
[0020] In a case where the root node is not connected to a directed edge, any root node with a traversal state of not traversed is selected, and the above steps are repeatedly executed until the traversal states of the multiple root nodes are all traversed.
[0021] In a possible implementation, the above step of sequentially adding the successor nodes of the root node to the to-be-executed set according to the directions of the directed edges comprises the following steps.
[0022] For any directed edge in the at least one directed edge, a first successor node pointed to by the directed edge is added behind the root node in the to-be-executed set, and the traversal state of the first successor node is updated to be traversed.
[0023] The first successor node is taken as a current node, and at least one current directed edge connected to the current node is determined.
[0024] For any current directed edge in the at least one current directed edge, a second successor node corresponding to the current directed edge is added behind the current node in the to-be-executed set, and the traversal state of the second successor node is updated to be traversed. The second successor node is taken as the current node, and the above steps are repeatedly executed until the current node has no successor node.
[0025] In one possible implementation, the above-mentioned creation of a thread pool based on a list of tasks to be executed includes:
[0026] Based on the number of sets to be executed in the list of sets to be executed, a thread pool is constructed, the size of which is the same as the number of sets to be executed.
[0027] In one possible implementation, before the application starts, the above method also includes:
[0028] The initialization logic of the service instances of the above applications is modified to be executed asynchronously.
[0029] Secondly, this application provides an application launching device, comprising:
[0030] The building module is used to construct a directed graph based on the dependencies between multiple service instances of the application when the application starts.
[0031] The traversal module is used to traverse the directed graph and obtain a list of services to be executed for multiple service instances.
[0032] A creation module is used to create a thread pool based on a list of services to be executed, which includes a set of services to be executed for multiple service instances.
[0033] The execution module is used to allocate a corresponding thread for each set to be executed, and to execute the service instances in the corresponding set of execution in parallel through the threads.
[0034] In one possible implementation, the above-mentioned apparatus further includes: a determining module;
[0035] The determination module is used to determine the dependencies between multiple service instances, which characterize the calling relationships between multiple service implementations;
[0036] The building module is also used to treat each service instance as a node and establish directed edges between multiple nodes based on dependencies;
[0037] The building module is specifically used to construct directed graphs based on multiple nodes and directed edges.
[0038] In one possible implementation, the above-mentioned device further includes: a judgment module and an addition module;
[0039] The traversal module is specifically used to traverse a directed graph and determine multiple root nodes with an in-degree of 0.
[0040] The creation module is also used to select any one of multiple root nodes, create a corresponding set to be executed in the list to be executed, add the root node to the set to be executed, and update the traversal status of the root node to be traversed. The initial traversal status of multiple nodes in the directed graph is: untraversed.
[0041] determining whether the root node corresponds to at least one directed edge;
[0042] adding, in a case where the root node corresponds to at least one directed edge, the successor nodes of the root node to the to-be-executed set in sequence according to the directions of the directed edges;
[0043] The traversal module is further configured to select any root node with the traversal state being untraversed, and repeatedly execute the above steps until the traversal states of the root nodes are all traversed.
[0044] The traversal module is further configured to, in a case where the root node is not connected with a directed edge, select any root node with the traversal state being untraversed, and repeatedly execute the above steps until the traversal states of the root nodes are all traversed.
[0045] In a possible implementation, the traversal module is further configured to, for any directed edge in the at least one directed edge, add a first successor node pointed by the directed edge to the back of the root node in the to-be-executed set, and update the traversal state of the first successor node to be traversed.
[0046] The determining module is further configured to take the first successor node as a current node, and determine at least one current directed edge connected with the current node.
[0047] The traversal module is further configured to, for any current directed edge in the at least one current directed edge, add a second successor node corresponding to the current directed edge to the back of the current node in the to-be-executed set, and update the traversal state of the second successor node to be traversed, take the second successor node as the current node, and repeatedly execute the above steps until the current node has no successor node.
[0048] In a possible implementation, the constructing module is specifically configured to construct a thread pool according to the number of the to-be-executed sets in the to-be-executed list, and the size of the thread pool is the same as the number of the to-be-executed sets.
[0049] In a possible implementation, the apparatus further includes a modifying module.
[0050] The modifying module is configured to modify the initialization logic of the service instance of the application to an asynchronous execution mechanism.
[0051] In a third aspect, an embodiment of the present application provides an electronic device, including a processor, and a memory connected with the processor in communication;
[0052] The memory stores computer execution instructions;
[0053] The processor executes the computer execution instructions stored in the memory to implement the first aspect and / or various possible implementation manners of the first aspect.
[0054] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the first aspect and / or various possible implementations of the first aspect.
[0055] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the first aspect and / or various possible implementations of the first aspect.
[0056] The application startup method provided in this application constructs a directed graph based on the dependencies between multiple service instances of the application during application startup. This directed graph is traversed to obtain a list of services to be executed for each instance. A thread pool is then created based on this list, and a corresponding thread is allocated to each set of services to be executed in the list. This allows multiple threads to execute the service instances in their respective sets in parallel. By allocating a thread to each set of services to be executed, this method ensures that if there are no dependencies between service instances, those instances are loaded in parallel, thereby reducing application startup time and improving application efficiency during continuous deployment. Attached Figure Description
[0057] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0058] Figure 1 A flowchart illustrating an application startup method provided in this application embodiment. Figure 1 ;
[0059] Figure 2 A flowchart illustrating an application startup method provided in this application embodiment. Figure 2 ;
[0060] Figure 3 A directed graph provided for an embodiment of this application;
[0061] Figure 4 A schematic diagram of the structure of the starting device for the application provided in this application;
[0062] Figure 5 A schematic diagram of the structure of the electronic device provided in this application.
[0063] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. DETAILED DESCRIPTION
[0064] The exemplary embodiments will be described in detail herein with reference to the attached drawings. In the following description, like reference numerals refer to like elements, unless the context clearly dictates otherwise. The following exemplary embodiments described herein represent implementations consistent with the present application. However, the following descriptions are merely examples consistent with a few aspects of the present application, as detailed in the appended claims.
[0065] It should be noted that the user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of related data comply with relevant laws, regulations and standards of relevant countries and regions, necessary security measures are taken, public order and good customs are not violated, and appropriate operation portals are provided for users to choose authorization or refusal.
[0066] And the present application involves big data analysis of user information (including but not limited to personal biological characteristics, identity data, consumption data, asset data, electronic terminal operation data, etc.), and uses artificial intelligence technology for automatic decision-making, and makes technical solutions based on automatic decision-making results that have a significant impact on personal rights and interests, provides appropriate operation portals for users to choose to agree or refuse automatic decision-making results; if the user chooses to refuse, the expert decision-making process is entered.
[0067] It should be noted that the application startup method, device, equipment, storage medium and program product provided by the present application can be used in the field of financial technology, and can also be used in any field other than financial technology. The application field of the application startup method, device, equipment, storage medium and program product in the present application is not limited.
[0068] With the development of financial technology, in order to meet the needs of high concurrency and flexible expansion of bank business, distributed bank system has become the mainstream architecture. In the distributed bank system, the application involves initialization operation of a large number of service instances in the startup process. Some of the initialization operations involve network input output (Input Output, IO) operations, such as establishing a connection with a database, obtaining configuration information from a remote service, etc. These service instances involving network IO operations are affected by network conditions, service response time and other factors, and require a long execution time.
[0069] However, since the existing initialization method uses a serial execution mechanism, it performs initialization operations on multiple service instances one by one in order. Even if a certain service instance has no dependency relationship with other service instances, it must wait for all the service instances in front of it to complete initialization before it can perform initialization operations.
[0070] Therefore, existing initialization methods further extend the application startup time, thereby affecting the efficiency of the application in continuous deployment.
[0071] The application startup method provided in this application constructs a directed graph based on the dependencies between multiple service instances of the application, and determines a list of services to be executed corresponding to the multiple service instances based on the directed graph. The list of services to be executed includes at least one set of services to be executed, and each set of services to be executed includes at least one service instance. A thread pool is created based on the above list of services to be executed, and a thread is allocated to each set of services to be executed, so that the service instances in the corresponding set of services to be executed are executed in parallel by multiple threads. This avoids the extension of application startup time caused by serial execution mechanism, thereby improving the efficiency of application in continuous deployment.
[0072] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0073] Figure 1 A flowchart illustrating an application startup method provided in this application embodiment. Figure 1 .like Figure 1 As shown, the method includes:
[0074] S101. When the application starts, a directed graph is constructed based on the dependencies between multiple service instances of the application.
[0075] Determine the dependencies between each service instance, including the direction of the dependency. For example, the payment service can only execute after the database connection pool has finished initializing; that is, the execution of the payment service requires calling the database to which the database connection pool is connected. Therefore, the dependency direction between the payment service and the database connection pool is: payment service → database connection pool.
[0076] After obtaining the dependencies between multiple service instances, each service instance is abstracted into a node, and directed edges are constructed between the nodes based on the dependencies between the multiple service instances to generate a directed graph.
[0077] S102, traverse the directed graph to obtain a plurality of service instance corresponding to-be-executed lists, and create a thread pool based on the to-be-executed lists.
[0078] The to-be-executed list includes a plurality of to-be-executed sets corresponding to the plurality of service instances, and the directed graph includes a plurality of dependency links.
[0079] The directed graph is traversed, and a to-be-executed set is created for each root node with an in-degree of 0 in the to-be-executed list, and the root node is added to the corresponding to-be-executed set. For each root node, the successor nodes of the root node are sequentially added to the corresponding to-be-executed set according to the direction of the directed edges in the dependency link where the root node is located.
[0080] After the traversal of the directed graph is completed, the to-be-executed list obtained includes a plurality of to-be-executed sets, and each to-be-executed set includes at least one node corresponding to a service instance. In order to realize parallel execution of service instances without dependency relationship, a thread pool is created based on the to-be-executed list, and the size of the thread pool is consistent with the number of to-be-executed sets in the to-be-executed list.
[0081] S103, assign a corresponding thread to each to-be-executed set, and execute the service instances in the corresponding to-be-executed set in parallel through the thread.
[0082] The plurality of threads in the thread pool are assigned to the plurality of to-be-executed sets in the to-be-executed list, each to-be-executed set corresponds to a thread, and the plurality of threads are executed in parallel, thereby avoiding the problem that a plurality of service instances are executed in series, causing the application to start for a long time.
[0083] The application provides an application starting method. When the application starts, a directed graph is constructed based on the dependency relationship between a plurality of service instances of the application, the directed graph is traversed to obtain a plurality of service instance corresponding to-be-executed lists, and a thread pool is created based on the to-be-executed lists. Then, a corresponding thread is assigned to each to-be-executed set in the to-be-executed list, so that the service instances in the corresponding to-be-executed set are executed in parallel through the plurality of threads. This method assigns a corresponding thread to each to-be-executed set, so that if there is no dependency relationship between the service instances, the service instances without dependency relationship are loaded in parallel, thereby reducing the time length of application startup, and improving the efficiency of application in continuous deployment.
[0084] Figure 2 Flowchart of an application starting method provided by an embodiment of the application Figure 2 As shown in Figure 1 , the embodiment is based on Figure 3 the embodiment, and a possible application starting method is described in detail. The method comprises the following steps.
[0085] S201. Determine the dependency relationship between the plurality of service instances when the application is started.
[0086] The dependency relationship is used to represent the calling relationship between the plurality of service instances.
[0087] In the application startup phase, the application code is scanned, the corresponding plurality of service instances of the application are determined according to the annotation declaration in the code, and then the calling relationship between the plurality of service instances is determined according to the configuration file. The calling relationship includes the execution order of the plurality of service instances. According to the calling relationship, the dependency relationship between the plurality of service instances is determined.
[0088] Optionally, before the application is started, the initialization logic of the service instance of the application is modified to an asynchronous execution mechanism, so that the above-mentioned application supports parallel initialization operation.
[0089] S202. Each service instance is taken as a node, and a directed edge is established between the plurality of nodes according to the dependency relationship; a directed graph is constructed based on the plurality of nodes and the directed edge.
[0090] After obtaining the dependency relationship between the plurality of service instances, each service instance is taken as a node, a directed edge is established between the plurality of nodes according to the dependency relationship, and then a directed graph is constructed based on the plurality of nodes and the directed edge connected between the nodes. For example, for the node n corresponding to the service instance, if there is another node m corresponding to the service instance, the service node m depends on the loading completion of the node n, then a directed edge e is drawn from the node n to the node m.
[0091] Exemplarily, Figure 3 A directed graph provided by an embodiment of the present application. Each service instance is taken as a node, and the nodes A, B, C, and D are obtained. The dependency relationship between the nodes is that C depends on A and B, B depends on A, and D has no dependency relationship. The obtained directed graph is as shown in Figure 3 .
[0092] S203. Traverse the directed graph to determine a plurality of root nodes with an in-degree of 0.
[0093] The root node with an in-degree of 0 is the starting node of each dependency chain in the directed graph.
[0094] S204. Select any root node in the plurality of root nodes, create a corresponding to-be-executed set in the to-be-executed list, add the root node to the to-be-executed set, and update the traversal state of the root node to a traversed state.
[0095] The initial traversal state of all nodes in the directed graph is untraversed, which can be, for example, "0".
[0096] The directed graph is traversed to determine a plurality of root nodes with an in-degree of 0, and the root nodes are starting nodes of a dependency chain in the directed graph. For each root node, a corresponding to-be-executed set is created in the to-be-executed list, and the root node is added to the to-be-executed set.
[0097] For example, the traversal state of the plurality of nodes in the directed graph is: not traversed. A plurality of root nodes with an in-degree of 0 are determined, one of the plurality of root nodes is selected as a traversal starting point, a to-be-executed set is created in the to-be-executed list for the root node, and the root node is added to the to-be-executed set. After the traversal of the root node is completed, the traversal state of the root node is updated to: traversed. As shown in Figure 4 For example, the traversal state of the plurality of nodes in the directed graph is: not traversed. A plurality of root nodes with an in-degree of 0 are determined, one of the plurality of root nodes is selected as a traversal starting point, a to-be-executed set is created in the to-be-executed list for the root node, and the root node is added to the to-be-executed set. After the traversal of the root node is completed, the traversal state of the root node is updated to: traversed. As shown in
[0098] S205, determining whether the root node corresponds to at least one directed edge; in the case that the root node corresponds to at least one directed edge, performing the following step S206; in the case that the root node is not connected to a directed edge, performing the following step S207.
[0099] Determining whether the root node corresponds to at least one directed edge, that is, determining whether there is a successor node after the root node, so as to add all successor nodes in the dependency chain to which the root node belongs to the to-be-executed set corresponding to the root node in sequence according to the indication of the directed edge in the dependency chain by using the method shown in the following step S206, thereby ensuring that the service instances of the existing dependency relationship are executed in sequence and the initialization operation is completed. In addition, in the case that the root node is not connected to a directed edge, it is indicated that the root node is an independent node and can be independently executed.
[0100] The method determines whether there is a successor node of the root node by judging whether the root node is connected to a directed edge, so as to add the successor node of the root node to the to-be-executed set corresponding to the root node, and ensures that the service instance corresponding to each node can successfully complete the initialization operation.
[0101] S206, adding the successor nodes of the root node to the to-be-executed set in sequence according to the direction of each directed edge.
[0102] In the case that the judgment result of the above step S205 indicates that the root node corresponds to at least one directed edge, it is indicated that the root node has at least one successor node, and each successor node is added to the to-be-executed set corresponding to the root node in sequence according to the indication of the directed edge in the dependency chain in which the root node is located. The method more accurately determines the sequence of each node in the to-be-executed set according to the indication of the directed edge, and ensures that each service instance can successfully complete the initialization operation.
[0103] Optionally, the method of adding the successor nodes of the root node to the to-be-executed set in turn according to the directions of the at least one directed edge is provided, and the method comprises: for any one of the at least one directed edge, adding the first successor node pointed by the directed edge to the to-be-executed set behind the root node, and updating the traversal state of the first successor node to the traversed state; taking the first successor node as the current node, determining the at least one current directed edge connected to the current node; for any one of the at least one current directed edge, adding the second successor node corresponding to the current directed edge to the to-be-executed set behind the current node, and updating the traversal state of the second successor node to the traversed state; taking the second successor node as the current node, and repeating the above steps until the current node has no successor node.
[0104] It should be noted that, in the case that the first successor node has no current directed edge, it indicates that the plurality of nodes on the current dependency chain have been added to the to-be-executed set in the dependency order, and then the following step S207 is performed to traverse the dependency chain that has not been traversed.
[0105] For example, L is an empty list used to store the to-be-executed set. When the in-degree of the node n is 0, a set N is created in the list L, and the node n is added to the set N, and the traversal state of the node n in the directed graph is updated to the traversed state. It is determined whether the node n has a directed edge e pointing to the node m, and if yes, the node m is added to the set N and is located behind the node n. In this way, it is determined whether there is a successor node behind the node m, and if yes, the successor node is added to the node m in the set N, and all the nodes in the current dependency chain are in the traversed state.
[0106] It can be understood that the directed graph is stored in the set S, the root node with the in-degree of 0 is determined from the set S, the corresponding to-be-executed set is created in the to-be-executed list, the root node is added to the to-be-executed set, and the root node is deleted from the set S. It is determined whether the root node corresponds to at least one directed edge, and if yes, the successor nodes of the root node are added to the corresponding to-be-executed set in turn according to the directions of the directed edges, and the successor nodes are deleted from the set S.
[0107] S207, any root node with the traversal state of the untraversed state is selected, and the above steps S204 to S206 are repeatedly performed until the traversal states of the plurality of root nodes are all in the traversed state.
[0108] In the case where the determination result of step S205 indicates that the root node is not connected with a directed edge, any root node with an untraversed traversal state is selected from the plurality of root nodes, and the root node is traversed according to the method shown in steps S204 to S206 to add all nodes in the dependency chain in which the root node is located to the corresponding to-be-executed set according to the indication of the directed edge.
[0109] S208, constructing a thread pool according to the number of to-be-executed sets in the to-be-executed list.
[0110] The plurality of to-be-executed sets in the to-be-executed list do not have a dependency relationship and can be executed in parallel, and therefore, a thread pool is constructed based on the number of to-be-executed sets in the to-be-executed list. The size of the thread pool is the same as the number of to-be-executed sets.
[0111] S209, allocating a corresponding thread to each to-be-executed set, and executing the service instances in the corresponding to-be-executed set in parallel through the thread.
[0112] This step S209 is similar to the explanation of step S103 described above, and will not be described here again.
[0113] The application startup method provided in this embodiment determines the dependency relationship between a plurality of service instances when the application is started, takes each service instance as a node, establishes a directed edge between the plurality of nodes according to the dependency relationship, constructs a directed graph based on the plurality of nodes and the directed edge, and further traverses the directed graph to determine a plurality of root nodes with an in-degree of 0, selects any root node from the plurality of root nodes, creates a corresponding to-be-executed set in a to-be-executed list, adds the root node to the to-be-executed set, and updates the traversal state of the root node to traversed. Then, it is determined whether the root node corresponds to at least one directed edge, and in the case where the root node corresponds to at least one directed edge, the successor nodes of the root node are sequentially added to the to-be-executed set according to the direction of each directed edge. After completing the traversal operation of the dependency chain corresponding to the root node, any root node with an untraversed traversal state is selected, and the dependency chain corresponding to the root node is traversed to store the plurality of root nodes belonging to the same dependency chain in a to-be-executed set, thereby facilitating the smooth completion of the initialization operation of each service instance.
[0114] In addition, in the case where the root node is not connected with a directed edge, any root node with an untraversed traversal state is selected, and a corresponding to-be-executed set is created, the root node is stored in the to-be-executed set, and the traversal state of the root node is updated to traversed. Then, the dependency chain in which the root node is located is traversed. This method creates a to-be-executed set for an independent root node, so as to allocate a thread to the to-be-executed set later, thereby realizing the parallel initialization operation of a plurality of to-be-executed sets.
[0115] After the traversal operation on the directed graph is completed and a plurality of to-be-executed sets are obtained, a thread pool is constructed according to the number of to-be-executed sets in the to-be-executed list, a corresponding thread is allocated to each to-be-executed set, and the service instances in the corresponding to-be-executed set are executed in parallel through the thread, so that parallel initialization operations between a plurality of service instances without a dependency relationship are realized, thereby avoiding the problem that all service instances are initialized in a serial execution mechanism, causing a long application startup time.
[0116] Figure 4 A structural schematic diagram of an application startup device provided by the present application is shown in FIG. 1. Figure 5 As shown in FIG. 1, the application startup device 40 provided by the present embodiment includes:
[0117] The construction module 401 is configured to, when the application is started, construct a directed graph based on a dependency relationship between a plurality of service instances of the application.
[0118] The traversal module 402 is configured to traverse the directed graph to obtain a to-be-executed list corresponding to the plurality of service instances.
[0119] The creation module 403 is configured to create a thread pool based on the to-be-executed list, the to-be-executed list including a plurality of to-be-executed sets corresponding to the plurality of service instances.
[0120] The execution module 404 is configured to allocate a corresponding thread to each to-be-executed set and execute the service instances in the corresponding to-be-executed set in parallel through the thread.
[0121] In a possible implementation manner, the device further includes a determination module 405.
[0122] The determination module 405 is configured to determine a dependency relationship between the plurality of service instances, the dependency relationship being used to represent a calling relationship between the plurality of service instances.
[0123] The construction module 401 is further configured to take each service instance as a node and establish a directed edge between the plurality of nodes according to the dependency relationship.
[0124] The construction module 401 is specifically configured to construct the directed graph based on the plurality of nodes and the directed edge.
[0125] In a possible implementation manner, the device further includes a judgment module 406 and an adding module 407.
[0126] The traversal module 402 is specifically configured to traverse the directed graph to determine a plurality of root nodes with an in-degree of 0.
[0127] The creating module 403 is further configured to select any root node from the plurality of root nodes, create a corresponding to-be-executed set in the to-be-executed list, add the root node to the to-be-executed set, and update a traversal state of the root node to a traversed state, where initial traversal states of the plurality of nodes in the directed graph are untraversed.
[0128] The determining module 406 is configured to determine whether the root node corresponds to at least one directed edge.
[0129] The adding module 407 is configured to, in a case where the root node corresponds to at least one directed edge, add, in sequence, successor nodes of the root node to the to-be-executed set according to directions of the directed edges.
[0130] The traversal module 402 is further configured to select any root node with the untraversed state, and repeatedly perform the above steps until the traversal states of the plurality of root nodes are all the traversed states.
[0131] The traversal module 402 is further configured to, in a case where the root node is not connected with a directed edge, select any root node with the untraversed state, and repeatedly perform the above steps until the traversal states of the plurality of root nodes are all the traversed states.
[0132] In a possible implementation, the traversal module 402 is further configured to, for any directed edge from the at least one directed edge, add a first successor node pointed by the directed edge to the back of the root node in the to-be-executed set, and update a traversal state of the first successor node to the traversed state.
[0133] The determining module 405 is further configured to take the first successor node as a current node, and determine at least one current directed edge connected with the current node.
[0134] The traversal module 402 is further configured to, for any current directed edge from the at least one current directed edge, add a second successor node corresponding to the current directed edge to the back of the current node in the to-be-executed set, and update a traversal state of the second successor node to the traversed state, take the second successor node as the current node, and repeatedly perform the above steps until the current node has no successor node.
[0135] In a possible implementation, the constructing module 301 is specifically configured to construct a thread pool according to a quantity of to-be-executed sets in the to-be-executed list, where a size of the thread pool is the same as the quantity of the to-be-executed sets.
[0136] In a possible implementation, the apparatus further includes a modifying module 308.
[0137] The modifying module 308 is configured to modify initialization logic of the service instance of the application to an asynchronous execution mechanism.
[0138] The application starting device provided in the embodiment can execute the method provided in the method embodiment, and has similar implementation principles and technical effects, which will not be repeated here.
[0139] Figure 5 The structure schematic diagram of the electronic device provided in the application is shown in FIG. 1. As shown in the figure, the electronic device 50 provided in the embodiment includes at least one processor 501 and a memory 502. Optionally, the device 50 further includes a communication component 503. The processor 501, the memory 502 and the communication component 503 are connected through a bus 504.
[0140] In the specific implementation process, the at least one processor 501 executes the computer execution instructions stored in the memory 502, so that the at least one processor 501 executes the method described above.
[0141] The specific implementation process of the processor 501 can refer to the method embodiment described above, which has similar implementation principles and technical effects, and will not be repeated here.
[0142] In the above embodiment, it should be understood that the processor can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC) and the like. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the application can be directly embodied as hardware processor execution or executed by a combination of hardware and software modules in the processor.
[0143] The memory can include a random access memory (RAM), and can also include a non-volatile memory (NVM), for example, at least one disk memory.
[0144] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, the bus in the drawings of the present application does not limit to only one bus or one type of bus.
[0145] The present application also provides a computer program product, comprising a computer program, which, when executed by a processor, implements the method described above.
[0146] The present application also provides a computer readable storage medium, which stores computer execution instructions, and when a processor executes the computer execution instructions, the method described above is implemented.
[0147] The readable storage medium described above can be realized by any type of volatile or non-volatile storage device or their combination, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0148] An exemplary readable storage medium is coupled to the processor, so that the processor can read information from the readable storage medium, and can write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the readable storage medium can also exist as discrete components in the device.
[0149] The division of units is only a logical functional division, and in actual implementation, there can be another division manner, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0150] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, i.e., may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment of the present application.
[0151] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.
[0152] If the function is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the part of the prior art or the part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method of each embodiment of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various program code storage media.
[0153] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction related hardware. The aforementioned program can be stored in a computer readable storage medium. The program executes the steps including the above-mentioned method embodiments when executed; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk, and various program code storage media.
[0154] It should be noted that for the above-mentioned method embodiments, in order to simply describe, they are all expressed as a combination of a series of actions, but those skilled in the art should know that the application is not limited by the order of the described actions, because according to the application, certain steps can be performed in other order or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily necessary for the present application.
[0155] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0156] It should be understood that the above-described device embodiments are merely illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units, modules, or components may be combined, or integrated into another system, or some features may be ignored or not executed.
[0157] Furthermore, unless otherwise specified, the functional units / modules in the various embodiments of this application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The integrated units / modules described above can be implemented in hardware or as software program modules.
[0158] When integrated units / modules are implemented in hardware, the hardware can be digital circuits, analog circuits, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor can be any suitable hardware processor, such as a CPU, GPU, FPGA, DSP, and ASIC, etc. Unless otherwise specified, the storage unit can be any suitable magnetic or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc.
[0159] If the integrated units / modules are implemented in the form of software program modules and sold or used as independent products, they can be stored in a computer readable memory. Based on such understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a memory and includes a number of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the embodiments of the method of the present application. The aforementioned memory includes: a U disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0160] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described, however, as long as the combinations of the technical features do not exist contradictory, they should be considered as the scope of the present application.
[0161] Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. The application is intended to cover any variations, uses or adaptations of the application following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice in the art to which the application pertains or can relate. The specification and examples are to be regarded as exemplary only, and the true scope and spirit of the application are indicated by the following claims.
[0162] It should be understood that the application is not limited to the precise construction that has been described above and illustrated in the accompanying drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the application is limited only by the claims that follow.
Claims
1. A method of starting an application, characterized by, The method comprises: constructing a directed graph based on a dependency relationship between a plurality of service instances of the application when the application is started; traversing the directed graph to obtain a plurality of to-be-executed lists corresponding to the service instances, and creating a thread pool based on the to-be-executed lists, wherein the to-be-executed lists comprise a plurality of to-be-executed sets corresponding to the service instances; allocating a corresponding thread to each of the to-be-executed sets, and executing the service instances in the corresponding to-be-executed sets in parallel through the thread.
2. The method of claim 1, wherein, The method comprises: determining a dependency relationship between a plurality of service instances, wherein the dependency relationship is used to represent a calling relationship between the plurality of service instances; regarding each of the service instances as a node, and establishing a directed edge between a plurality of nodes according to the dependency relationship; constructing a directed graph based on the plurality of nodes and the directed edge.
3. The method of claim 1, wherein, The initial state of the to-be-executed list is empty, and the method comprises: traversing the directed graph to determine a plurality of root nodes with an in-degree of 0; selecting any root node in the plurality of root nodes, creating a corresponding to-be-executed set in the to-be-executed list, adding the root node to the to-be-executed set, and updating the traversal state of the root node to traversed, wherein the initial traversal state of a plurality of nodes in the directed graph is untraversed; determining whether the root node corresponds to at least one directed edge; in the case where the root node corresponds to at least one directed edge, sequentially adding successor nodes of the root node to the to-be-executed set according to the directions of the directed edges; selecting any root node with a traversal state of untraversed, and repeatedly performing the above steps until the traversal states of the plurality of root nodes are all traversed; in the case where the root node is not connected to a directed edge, selecting any root node with a traversal state of untraversed, and repeatedly performing the above steps until the traversal states of the plurality of root nodes are all traversed.
4. The method of claim 3, wherein, The method comprises: for any directed edge in the at least one directed edge, adding a first successor node pointed by the directed edge to the root node in the to-be-executed set, and updating the traversal state of the first successor node to traversed; regarding the first successor node as a current node, and determining at least one current directed edge connected to the current node; for any current directed edge in the at least one current directed edge, adding a second successor node corresponding to the current directed edge to the current node in the to-be-executed set, updating the traversal state of the second successor node to traversed, and regarding the second successor node as a current node, and repeatedly performing the above steps until the current node has no successor node.
5. The method of claim 3, wherein, The method comprises: constructing a thread pool according to the number of to-be-executed sets in the to-be-executed list, wherein the size of the thread pool is the same as the number of to-be-executed sets.
6. The method of claim 1, wherein, Before the application is started, the method further comprises: The initialization logic of the service instance of the application is modified as an asynchronous execution mechanism.
7. A starting device for an application, characterized by The application comprises: a construction module, configured to construct a directed graph based on a dependency relationship among a plurality of service instances of an application when the application is started; a traversal module, configured to traverse the directed graph to obtain a plurality of to-be-executed lists corresponding to the service instances; a creation module, configured to create a thread pool based on the to-be-executed lists, wherein the to-be-executed lists comprise a plurality of to-be-executed sets corresponding to the service instances; an execution module, configured to allocate a corresponding thread to each of the to-be-executed sets, and execute the service instances in the corresponding to-be-executed set in parallel through the thread.
8. An electronic device, comprising: The application comprises: a processor, and a memory connected to the processor in communication; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by the processor to implement the method according to any one of claims 1 to 6.
10. A computer program product, characterised in that, The application comprises a computer program, and the computer program is executed by the processor to implement the method according to any one of claims 1 to 6.