Distributed project compiling method and device, storage medium and electronic equipment
By distributing compilation tasks to remote builder clusters for parallel processing, the problem of insufficient computing resources in the parallel construction system is solved, the construction and compilation speed is improved, and efficient distributed compilation is achieved.
Patent Information
- Application Number
- CN202410749525.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2024-03-28
- Filing Date
- 2024-06-11
- Publication Date
- 2024-09-27
AI Technical Summary
Insufficient computing resources of the parallel build system cause the build speed to slow down and affect the compilation speed.
By obtaining the source code of the target project from the main builder, converting it into a compilation task, and distributing it to the remote builder cluster for parallel processing, the cluster's parallel processing capabilities are used to expand computing resources and improve compilation speed.
It effectively solves the problem of insufficient computing resources in the parallel build system, improves the build speed and compilation speed, and achieves more efficient distributed compilation.
Smart Images

Figure CN118708185A
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed compilation technology, and in particular to a method, device, storage medium and electronic device for distributed compilation of projects. Background Art
[0002] Distributed compilation refers to a technology that performs parallel compilation operations on multiple computers at the same time to speed up the compilation speed. Distributed compilation is mainly used for large-scale software development and compilation. For example, when a software project needs to be compiled into different versions for multiple platforms, distributed compilation can assign compilation tasks to multiple computer nodes to speed up the compilation speed. In addition, distributed compilation can also be used to process large code bases, such as open source software projects, and compile in cloud computing environments. In short, distributed compilation can improve the efficiency of software development and compilation, and reduce development time and cost. However, since the parallel build system (single machine) needs to run multiple tasks at the same time, if the computing resources, such as CPU and memory, are insufficient, the build speed will be slowed down, thus affecting the compilation speed. Summary of the invention
[0003] The present application provides a method, device, storage medium and electronic device for distributed compilation of projects to solve the technical problem that insufficient computing resources of a parallel construction system slow down the construction speed, thereby affecting the compilation speed.
[0004] In a first aspect, the present application provides a method for distributed compilation projects, comprising: obtaining project source code of a target project from a main builder, and converting the project source code into at least one compilation task; obtaining a remote builder cluster from a registration center, wherein the remote builder cluster includes at least one remote builder that has completed registration in the registration center; distributing the at least one compilation task to each remote builder in the remote builder cluster, so that each remote builder in the remote builder cluster compiles the received compilation task, obtains a corresponding compilation result, and returns it to the main builder; controlling the main builder to summarize each received compilation result to obtain a target compilation result of the target project.
[0005] In a second aspect, the present application provides a device for distributed compilation projects, comprising: a first acquisition module, used to obtain project source code of a target project from a main builder, and convert the above project source code into at least one compilation task; a second acquisition module, used to obtain a remote builder cluster from a registration center, wherein the above remote builder cluster includes at least one remote builder that has completed registration in the above registration center; a distribution module, used to distribute the above at least one compilation task to each remote builder of the above remote builder cluster, so that each remote builder in the above remote builder cluster compiles the received compilation task, obtains the corresponding compilation result, and returns it to the above main builder; a summary module, used to control the above main builder to summarize each received compilation result to obtain the target compilation result of the above target project.
[0006] As an optional example, the above-mentioned device also includes: a broadcast module, which is used to broadcast the service address of the above-mentioned registration center before obtaining the remote builder cluster from the registration center, so that the first remote builder communicates with the above-mentioned registration center once through the above-mentioned service address every target time interval to send the machine address and communication port of the above-mentioned first remote builder to the above-mentioned registration center, wherein the above-mentioned first remote builder is any remote builder among all remote builders that is running and can receive compilation tasks; a saving module, which is used to save the machine address and communication port of the above-mentioned first remote builder in the above-mentioned registration center, and mark the above-mentioned first remote builder as a remote builder that has completed registration.
[0007] As an optional example, the second acquisition module includes: a first acquisition unit, used to acquire the dependency relationship of each compilation task of the at least one compilation task; a processing unit, used to group the compilation tasks with dependencies into a group according to the dependency relationship of each compilation task, and obtain at least one compilation task group; a second acquisition unit, used to acquire the number of task groups of the compilation task group; a third acquisition unit, used to acquire the first builder number of remote builders that have completed registration in the registration center; and a fourth acquisition unit, used to acquire the above-mentioned number of remote builders that have completed registration of the above-mentioned task group from the registration center when the above-mentioned number of first builders is greater than the above-mentioned number of task groups, and obtain the above-mentioned remote builder cluster.
[0008] As an optional example, the second acquisition module includes: a fifth acquisition unit, used to acquire all remote builders that have completed registration from the registration center to obtain the remote builder cluster when the number of the first builders is less than or equal to the number of task groups.
[0009] As an optional example, the distribution module includes: a distribution unit, configured to distribute the at least one compilation task group to each remote builder of the remote builder cluster when the number of second builders in the remote builder cluster is equal to the number of task groups.
[0010] As an optional example, the distribution unit includes: a processing subunit, used to take each compilation task group of at least one compilation task group as a current compilation task group, and perform the following operations on the current compilation task group: when the number of compilation tasks in the current compilation task group is greater than one, determine the compilation order of each compilation task according to the dependency relationship of each compilation task of the current compilation task group; according to the compilation order, send the first compilation task to the remote builder corresponding to the current compilation task group, and after the remote builder corresponding to the current compilation task group completes the compilation of the first compilation task and returns the first compilation result corresponding to the first compilation task to the main builder, send the second compilation task to the remote builder corresponding to the current compilation task group until all compilation tasks of the current compilation task group are compiled, wherein the second compilation task is the next compilation task of the first compilation task in the compilation order.
[0011] As an optional example, the distribution unit includes: a first distribution sub-unit, used to distribute the second number of builders in the at least one compilation task group to each remote builder in the remote builder cluster when the number of second builders in the remote builder cluster is less than the number of task groups; a second distribution sub-unit, used to distribute the first compilation task group in the at least one compilation task group to the second remote builder when the second remote builder completes the compilation of the corresponding compilation task group, until all compilation task groups in the at least one compilation task group complete the compilation, wherein the second remote builder is any remote builder in the remote builder cluster, and the first compilation task group is any compilation task group in the at least one compilation task group that has not been distributed.
[0012] In a third aspect, the present application provides a storage medium storing a computer program, wherein the computer program executes the above-mentioned method of distributed compilation project when executed by a processor.
[0013] In a fourth aspect, the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the above-mentioned method of distributed compilation project through the computer program.
[0014] In an embodiment of the present application, a method is adopted in which the project source code of the target project is obtained from the main builder, and the above project source code is converted into at least one compilation task; a remote builder cluster is obtained from a registration center, wherein the above remote builder cluster includes at least one remote builder that has completed registration in the above registration center; the above at least one compilation task is distributed to each remote builder of the above remote builder cluster, so that each remote builder in the above remote builder cluster compiles the received compilation task, obtains the corresponding compilation result, and returns it to the above main builder; and the above main builder is controlled to summarize each received compilation result to obtain the target compilation result of the above target project. Since in the above method, the multi-core parallel compilation method on a single builder is extended to the cluster, the system will convert the project source code of the target project of the main builder into at least one compilation task, and distribute the compilation tasks to different remote builders, and use the parallel processing capabilities of the cluster to execute these compilation tasks simultaneously, thereby achieving the purpose of expanding the computing resources of the construction system and improving the compilation speed, thereby solving the technical problem that the parallel construction system is insufficient in computing resources, resulting in a slow construction speed, thereby affecting the compilation speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0016] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0017] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0018] Figure 1 is a flowchart of an optional method for distributed compilation of projects according to an embodiment of the present application;
[0019] Figure 2 It is an overall architecture diagram of an optional distributed compilation project method according to an embodiment of the present application;
[0020] Figure 3 It is a data interaction structure diagram of a main builder and a remote builder of an optional distributed compilation project method according to an embodiment of the present application;
[0021] Figure 4 is a schematic diagram of the structure of an optional device for distributed compilation of projects according to an embodiment of the present application;
[0022] Figure 5 is a schematic diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0024] The disclosure below provides many different embodiments or examples to realize the different structures of the present application. In order to simplify the disclosure of the present application, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present application. In addition, the present application can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0025] According to a first aspect of an embodiment of the present application, a method for distributed compilation of a project is provided, optionally, as follows: Figure 1 As shown, the above method includes:
[0026] S102, obtaining a project source code of a target project from a main builder, and converting the project source code into at least one compilation task;
[0027] S104, obtaining a remote builder cluster from a registration center, wherein the remote builder cluster includes at least one remote builder that has completed registration in the registration center;
[0028] S106, distributing at least one compilation task to each remote builder in the remote builder cluster, so that each remote builder in the remote builder cluster compiles the received compilation task, obtains a corresponding compilation result, and returns it to the main builder;
[0029] S108, controlling the main builder to summarize each received compilation result to obtain a target compilation result of the target project.
[0030] Optionally, in order to improve the compilation speed of distributed compilation, there are many methods in the prior art, for example, faster computer hardware can be used, such as a faster CPU, a larger memory or a faster hard disk. Optimized compilers and compilation options can also be used. In addition, parallel compilation technology can also be used to speed up the compilation process using a multi-threaded compiler. In this embodiment, the C++ project uses the parallel compilation technology combined with CMake (Cross-Platform Makefile Generator, an open source cross-platform build system generation tool) and Ninja (an open source build system tool). When CMake and Ninja are used in combination, their respective functions are different. CMake is a cross-platform build system generator that can automatically generate build systems for various platforms, such as Makefile (a file for defining and managing the build process of a software project), Visual Studio (for developing various types of applications) projects, etc. CMake can automatically generate a build system based on project configuration and dependencies, thereby simplifying the build process. Ninja is a fast parallel build system that can build multiple targets in parallel, thereby improving the build speed. Ninja can be built based on the build system generated by CMake, or it can be built directly using Ninja files. Therefore, when using CMake and Ninja in combination, CMake is responsible for generating the build system, while Ninja is responsible for building targets in parallel, thereby increasing the build speed.
[0031] Optionally, in this embodiment, based on the open source project Ninja, the original Ninja is a local build system. After the transformation, the actual part of the compilation task in the Ninja local build process can be sent to the remote node for execution. The machine of the main builder needs to save the complete project source code of the target project. Figure 2As shown in the overall architecture diagram, the project source code of the target project is obtained from the main builder, and the project source code is converted into at least one compilation task, including compilation task a, compilation task b and compilation task c. The compilation task refers to converting the source code into a file that can be compiled and executed on the remote server. Then, the information of the remote builder cluster is obtained from the registration center. The remote builder cluster includes remote builder 1, remote builder 2 and remote builder 3. The registration center is a centralized service for storing and managing the information of each remote builder in the construction system. Distribute at least one compilation task to each remote builder in the remote builder cluster. For example, distribute compilation task a to remote builder 1 in the remote builder cluster, distribute compilation task b to remote builder 2 in the remote builder cluster, and distribute compilation task c to remote builder 3 in the remote builder cluster. After receiving the distributed compilation tasks, each remote builder in the remote builder cluster performs compilation operations, obtains corresponding compilation results, and returns them to the main builder. For example, after receiving the distributed compilation task a, remote builder 1 performs compilation operations and obtains corresponding compilation result A. After receiving the distributed compilation task b, remote builder 2 performs compilation operations and obtains corresponding compilation result B. After receiving the distributed compilation task c, remote builder 3 performs compilation operations and obtains corresponding compilation result C. Finally, the main builder summarizes all the compilation results received and obtains the target compilation result of the target project. During the data interaction process between the main builder and the remote builder, such as Figure 3 As shown in the figure, the PP-*.cpp file is a file generated after preprocessing the project source code file, which can be compiled on the remote builder. The main builder converts the project source code file into a PP-*.cpp file and transmits it to the remote builder through the network. The remote builder compiles the PP-*.cpp file to obtain the compiled result *.obj file, and finally returns it to the main builder through the network. Through the collaborative work of the remote builder cluster, the project construction process is accelerated and optimized, so that stable performance improvement can be achieved. Through remote collaboration, cross-host distributed compilation is performed, which effectively improves the compilation speed of distributed compilation.
[0032] Optionally, in this embodiment, the multi-core parallel compilation method on a single builder is extended to the cluster. The system converts the project source code of the target project of the main builder into at least one compilation task, distributes the compilation tasks to different remote builders, and uses the parallel processing capabilities of the cluster to execute these compilation tasks simultaneously, thereby achieving the purpose of expanding the computing resources of the build system and improving the compilation speed, thereby solving the technical problem of insufficient computing resources in the parallel build system, resulting in a slower build speed, which in turn affects the compilation speed.
[0033] As an optional example, before obtaining the remote builder cluster from the registry, the above method further includes:
[0034] Broadcasting the service address of the registration center, so that the first remote builder communicates with the registration center once through the service address every target time interval, so as to send the machine address and communication port of the first remote builder to the registration center, wherein the first remote builder is any remote builder among all remote builders that is running and can receive compilation tasks;
[0035] The machine address and communication port of the first remote builder are stored in the registration center, and the first remote builder is marked as a remote builder that has completed registration.
[0036] Optionally, in this embodiment, the registration center is a centralized service for managing the registration information of the remote builder, and the service address is the network location of the registration center, which is used for the remote builder to communicate with the registration center. Before obtaining the remote builder cluster from the registration center, the registration center is started and kept running, exposing a service address of the http protocol to the outside. When the remote builder is started, it will first communicate with the registration center through this http protocol to inform its own machine address, communication port and other information. During the operation, the remote builder will communicate with the registration center at a certain target time interval to indicate that it is running normally and can receive compilation tasks. Once the registration center receives the information of the remote builder and successfully saves the machine address and communication port of the remote builder, it will mark the remote builder as a state of completed registration. As a result, the information of all remote builders that have completed registration is recorded in the registration center database. Therefore, when distributing compilation tasks, the main builder will query the registration center to see which remote builders are available. After finding out, it can distribute the compilation tasks to all registered remote builders, which helps the builders in the system to work together. The main builder can effectively distribute compilation tasks to registered remote builders, which helps to improve the efficiency of the entire build process.
[0037] As an optional example, getting a remote builder cluster from the registry includes:
[0038] Obtaining dependencies of each compilation task of at least one compilation task;
[0039] According to the dependency relationship of each compilation task, the compilation tasks with the dependency relationship are divided into a group to obtain at least one compilation task group;
[0040] Get the number of task groups of the compilation task group;
[0041] Get the first builder number of the remote builder that has completed registration in the registration center;
[0042] When the number of first builders is greater than the number of task groups, remote builders that have completed registration and have the same number of task groups are obtained from the registration center to obtain a remote builder cluster.
[0043] Optionally, in the present embodiment, each compilation task usually depends on the output of some source files or other tasks, and according to the dependency of each compilation task, the tasks with dependency are divided into a group. Such grouping can help the system to process the concurrent execution of tasks more effectively, because the tasks with dependency may not be compiled in parallel, and the task can be distributed only after the preceding task is completed (the criterion for completion is to receive the compilation result). After grouping, at least one compilation task group is obtained, the number of task groups is obtained to determine how many groups of compilation tasks can be compiled in parallel, the number of remote builders that have completed registration is obtained from the registration center, and then the number of registered remote builders is compared to see whether it is greater than the number of task groups. If so, it means that there are enough remote builders in the registration center to process compilation tasks in parallel, so, when the number of first builders is greater than the number of task groups, the number of remote builders that have completed registration equal to the number of task groups is obtained from the registration center to obtain a remote builder cluster.
[0044] As an optional example, getting a remote builder cluster from the registry includes:
[0045] When the number of first builders is less than or equal to the number of task groups, all remote builders that have completed registration are obtained from the registration center to obtain a remote builder cluster.
[0046] Optionally, in this embodiment, the number of task groups is obtained to determine how many groups of compilation tasks can be compiled in parallel, the number of remote builders that have completed registration is obtained from the registration center, and then the number of registered remote builders is compared to see whether it is greater than the number of task groups. If not, it means that there are not enough remote builders in the registration center to process compilation tasks in parallel, then, when the number of first builders is less than or equal to the number of task groups, all remote builders that have completed registration are obtained from the registration center to obtain a remote builder cluster.
[0047] As an optional example, distributing at least one compilation task to each remote builder of the remote builder cluster includes:
[0048] When the number of second builders in the remote builder cluster is equal to the number of task groups, at least one compilation task group is distributed to each remote builder in the remote builder cluster.
[0049] Optionally, in this embodiment, when the number of remote builders in the remote builder cluster is equal to the number of task groups, it means that there are enough remote builders in the remote builder cluster that can process compilation tasks in parallel, then at least one compilation task group is distributed to each remote builder in the remote builder cluster, so that each remote builder in the remote builder cluster processes the corresponding compilation tasks in parallel.
[0050] As an optional example, distributing at least one compilation task group to each remote builder of the remote builder cluster includes:
[0051] Each of the at least one compilation task group is used as the current compilation task group, and the following operations are performed on the current compilation task group:
[0052] When the number of compiling tasks in the current compiling task group is greater than one, determining the compiling order of each compiling task according to the dependency relationship of each compiling task in the current compiling task group;
[0053] According to the compilation order, the first compilation task is sent to the remote builder corresponding to the current compilation task group, and after the remote builder corresponding to the current compilation task group completes the compilation of the first compilation task and returns the first compilation result corresponding to the first compilation task to the main builder, the second compilation task is sent to the remote builder corresponding to the current compilation task group until all compilation tasks of the current compilation task group are compiled, wherein the second compilation task is the next compilation task of the first compilation task in the compilation order.
[0054] Optionally, in this embodiment, after distributing a compilation task group to a remote builder, for example, distributing compilation task group A to remote builder 1, if the number of compilation tasks in compilation task group A is greater than one, for example, compilation task group A includes compilation task a, compilation task b and compilation task c, then compilation task a is sent to remote builder 1, and after remote builder 1 completes the compilation of compilation task a and returns the compilation result A corresponding to compilation task a to the main builder, compilation task b is sent to remote builder 1, until all compilation tasks in compilation task group A are compiled and the corresponding compilation results are returned.
[0055] As an optional example, distributing at least one compilation task to each remote builder of the remote builder cluster includes:
[0056] In a case where the number of second builders in the remote builder cluster is less than the number of task groups, distributing the second number of builders in at least one compilation task group to each remote builder in the remote builder cluster;
[0057] When the second remote builder completes the compilation of the corresponding compilation task group, the first compilation task group in at least one compilation task group is distributed to the second remote builder until all compilation task groups in at least one compilation task group have completed the compilation, wherein the second remote builder is any remote builder in the remote builder cluster, and the first compilation task group is any one of the at least one compilation task groups that has not been distributed.
[0058] Optionally, in this embodiment, when the number of remote builders in the remote builder cluster is less than the number of task groups, it means that there are not enough remote builders in the remote builder cluster to process compilation tasks in parallel. For example, the remote builder cluster includes remote builder 1 and remote builder 2, and the compilation task groups include compilation task group A, compilation task group B and compilation task group C. Compilation task group A is distributed to remote builder 1, and compilation task group B is distributed to remote builder 2. If remote builder 1 completes the compilation of compilation task group A before remote builder 2, compilation task group C is sent to remote builder 1 until all compilation task groups complete the compilation.
[0059] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0060] According to another aspect of the embodiment of the present application, a device for distributed compilation of projects is also provided, such as Figure 4 As shown, including:
[0061] A first acquisition module 402 is used to acquire the project source code of the target project from the main builder, and convert the project source code into at least one compilation task;
[0062] A second acquisition module 404 is used to acquire a remote builder cluster from a registration center, wherein the remote builder cluster includes at least one remote builder that has completed registration in the registration center;
[0063] A distribution module 406, configured to distribute at least one compilation task to each remote builder in the remote builder cluster, so that each remote builder in the remote builder cluster compiles the received compilation task, obtains a corresponding compilation result, and returns it to the main builder;
[0064] The summarizing module 408 is used to control the main builder to summarize each received compilation result to obtain the target compilation result of the target project.
[0065] Optionally, in order to improve the compilation speed of distributed compilation, there are many methods in the prior art, for example, faster computer hardware can be used, such as a faster CPU, a larger memory or a faster hard disk. Optimized compilers and compilation options can also be used. In addition, parallel compilation technology can also be used to speed up the compilation process using a multi-threaded compiler. In this embodiment, the C++ project uses the parallel compilation technology combined with CMake (Cross-Platform Makefile Generator, an open source cross-platform build system generation tool) and Ninja (an open source build system tool). When CMake and Ninja are used in combination, their respective functions are different. CMake is a cross-platform build system generator that can automatically generate build systems for various platforms, such as Makefile (a file for defining and managing the build process of a software project), Visual Studio (for developing various types of applications) projects, etc. CMake can automatically generate a build system based on project configuration and dependencies, thereby simplifying the build process. Ninja is a fast parallel build system that can build multiple targets in parallel, thereby improving the build speed. Ninja can be built based on the build system generated by CMake, or it can be built directly using Ninja files. Therefore, when using CMake and Ninja in combination, CMake is responsible for generating the build system, while Ninja is responsible for building targets in parallel, thereby increasing the build speed.
[0066] Optionally, in this embodiment, based on the open source project Ninja, the original Ninja is a local build system. After the transformation, the actual part of the compilation task in the Ninja local build process can be sent to the remote node for execution. The machine of the main builder needs to save the complete project source code of the target project. Figure 2As shown, the project source code of the target project is obtained from the main builder, and the project source code is converted into at least one compilation task, including compilation task a, compilation task b and compilation task c. The compilation task refers to converting the source code into a file that can be compiled and executed on the remote server. Then, the information of the remote builder cluster is obtained from the registration center. The remote builder cluster includes remote builder 1, remote builder 2 and remote builder 3. The registration center is a centralized service for storing and managing the information of each remote builder in the construction system. Distribute at least one compilation task to each remote builder in the remote builder cluster. For example, distribute compilation task a to remote builder 1 in the remote builder cluster, distribute compilation task b to remote builder 2 in the remote builder cluster, and distribute compilation task c to remote builder 3 in the remote builder cluster. After receiving the distributed compilation tasks, each remote builder in the remote builder cluster performs compilation operations, obtains corresponding compilation results, and returns them to the main builder. For example, after receiving the distributed compilation task a, remote builder 1 performs compilation operations and obtains corresponding compilation result A. After receiving the distributed compilation task b, remote builder 2 performs compilation operations and obtains corresponding compilation result B. After receiving the distributed compilation task c, remote builder 3 performs compilation operations and obtains corresponding compilation result C. Finally, the main builder summarizes all the compilation results received and obtains the target compilation result of the target project. During the data interaction process between the main builder and the remote builder, such as Figure 3 As shown in the figure, the PP-*.cpp file is a file generated after preprocessing the project source code file, which can be compiled on the remote builder. The main builder converts the project source code file into a PP-*.cpp file and transmits it to the remote builder through the network. The remote builder compiles the PP-*.cpp file to obtain the compiled result *.obj file, and finally returns it to the main builder through the network. Through the collaborative work of the remote builder cluster, the project construction process is accelerated and optimized, so that stable performance improvement can be achieved. Through remote collaboration, cross-host distributed compilation is performed, which effectively improves the compilation speed of distributed compilation.
[0067] Optionally, in this embodiment, the multi-core parallel compilation method on a single builder is extended to the cluster. The system converts the project source code of the target project of the main builder into at least one compilation task, distributes the compilation tasks to different remote builders, and uses the parallel processing capabilities of the cluster to execute these compilation tasks simultaneously, thereby achieving the purpose of expanding the computing resources of the build system and improving the compilation speed, thereby solving the technical problem of insufficient computing resources in the parallel build system, resulting in a slower build speed, which in turn affects the compilation speed.
[0068] As an optional example, the above device further includes:
[0069] A broadcast module, used for broadcasting the service address of the registration center before obtaining the remote builder cluster from the registration center, so that the first remote builder communicates with the registration center once through the service address every target time interval, so as to send the machine address and communication port of the first remote builder to the registration center, wherein the first remote builder is any remote builder among all remote builders that is running and can receive compilation tasks;
[0070] The saving module is used to save the machine address and communication port of the first remote builder in the registration center, and mark the first remote builder as a remote builder that has completed registration.
[0071] Optionally, in this embodiment, the registration center is a centralized service for managing the registration information of the remote builder, and the service address is the network location of the registration center, which is used for the remote builder to communicate with the registration center. Before obtaining the remote builder cluster from the registration center, the registration center is started and kept running, exposing a service address of the http protocol to the outside. When the remote builder is started, it will first communicate with the registration center through this http protocol to inform its own machine address, communication port and other information. During the operation, the remote builder will communicate with the registration center at a certain target time interval to indicate that it is running normally and can receive compilation tasks. Once the registration center receives the information of the remote builder and successfully saves the machine address and communication port of the remote builder, it will mark the remote builder as a state of completed registration. As a result, the information of all remote builders that have completed registration is recorded in the registration center database. Therefore, when distributing compilation tasks, the main builder will query the registration center to see which remote builders are available. After finding out, it can distribute the compilation tasks to all registered remote builders, which helps the builders in the system to work together. The main builder can effectively distribute compilation tasks to registered remote builders, which helps to improve the efficiency of the entire build process.
[0072] As an optional example, the second acquisition module includes:
[0073] A first acquisition unit, used to acquire a dependency relationship of each compilation task of at least one compilation task;
[0074] A processing unit, configured to group the compilation tasks having dependencies into a group according to the dependencies of each compilation task, so as to obtain at least one compilation task group;
[0075] A second acquisition unit is used to acquire the number of task groups of the compilation task group;
[0076] A third obtaining unit is used to obtain the number of first builders of remote builders that have completed registration in the registration center;
[0077] The fourth acquisition unit is used to acquire the remote builders that have completed registration in the same number as the task group from the registration center to obtain a remote builder cluster when the number of first builders is greater than the number of task groups.
[0078] Optionally, in the present embodiment, each compilation task usually depends on the output of some source files or other tasks, and according to the dependency of each compilation task, the tasks with dependency are divided into a group. Such grouping can help the system to process the concurrent execution of tasks more effectively, because the tasks with dependency may not be compiled in parallel, and the task can be distributed only after the preceding task is completed (the criterion for completion is to receive the compilation result). After grouping, at least one compilation task group is obtained, the number of task groups is obtained to determine how many groups of compilation tasks can be compiled in parallel, the number of remote builders that have completed registration is obtained from the registration center, and then the number of registered remote builders is compared to see whether it is greater than the number of task groups. If so, it means that there are enough remote builders in the registration center to process compilation tasks in parallel, so, when the number of first builders is greater than the number of task groups, the number of remote builders that have completed registration equal to the number of task groups is obtained from the registration center to obtain a remote builder cluster.
[0079] As an optional example, the second acquisition module includes:
[0080] The fifth acquisition unit is used to acquire all remote builders that have completed registration from the registration center to obtain a remote builder cluster when the number of first builders is less than or equal to the number of task groups.
[0081] Optionally, in this embodiment, the number of task groups is obtained to determine how many groups of compilation tasks can be compiled in parallel, the number of remote builders that have completed registration is obtained from the registration center, and then the number of registered remote builders is compared to see whether it is greater than the number of task groups. If not, it means that there are not enough remote builders in the registration center to process compilation tasks in parallel, then, when the number of first builders is less than or equal to the number of task groups, all remote builders that have completed registration are obtained from the registration center to obtain a remote builder cluster.
[0082] As an optional example, the distribution module includes:
[0083] The distribution unit is used to distribute at least one compilation task group to each remote builder of the remote builder cluster when the number of second builders in the remote builder cluster is equal to the number of task groups.
[0084] Optionally, in this embodiment, when the number of remote builders in the remote builder cluster is equal to the number of task groups, it means that there are enough remote builders in the remote builder cluster that can process compilation tasks in parallel, then at least one compilation task group is distributed to each remote builder in the remote builder cluster, so that each remote builder in the remote builder cluster processes the corresponding compilation tasks in parallel.
[0085] As an optional example, the distribution unit includes:
[0086] The processing subunit is used to take each of the at least one compiling task group as a current compiling task group, and perform the following operations on the current compiling task group:
[0087] When the number of compiling tasks in the current compiling task group is greater than one, determining the compiling order of each compiling task according to the dependency relationship of each compiling task in the current compiling task group;
[0088] According to the compilation order, the first compilation task is sent to the remote builder corresponding to the current compilation task group, and after the remote builder corresponding to the current compilation task group completes the compilation of the first compilation task and returns the first compilation result corresponding to the first compilation task to the main builder, the second compilation task is sent to the remote builder corresponding to the current compilation task group until all compilation tasks of the current compilation task group are compiled, wherein the second compilation task is the next compilation task of the first compilation task in the compilation order.
[0089] Optionally, in this embodiment, after distributing a compilation task group to a remote builder, for example, distributing compilation task group A to remote builder 1, if the number of compilation tasks in compilation task group A is greater than one, for example, compilation task group A includes compilation task a, compilation task b and compilation task c, then compilation task a is sent to remote builder 1, and after remote builder 1 completes the compilation of compilation task a and returns the compilation result A corresponding to compilation task a to the main builder, compilation task b is sent to remote builder 1, until all compilation tasks in compilation task group A are compiled and the corresponding compilation results are returned.
[0090] As an optional example, the distribution unit includes:
[0091] A first distribution subunit is used to distribute the second number of builders in at least one compilation task group to each remote builder in the remote builder cluster when the number of second builders in the remote builder cluster is less than the number of task groups;
[0092] The second distribution sub-unit is used to distribute the first compilation task group in at least one compilation task group to the second remote builder when the second remote builder completes the compilation of the corresponding compilation task group, until all the compilation task groups in at least one compilation task group have completed the compilation, wherein the second remote builder is any remote builder in the remote builder cluster, and the first compilation task group is any one of the at least one compilation task groups that has not been distributed.
[0093] Optionally, in this embodiment, when the number of remote builders in the remote builder cluster is less than the number of task groups, it means that there are not enough remote builders in the remote builder cluster to process compilation tasks in parallel. For example, the remote builder cluster includes remote builder 1 and remote builder 2, and the compilation task groups include compilation task group A, compilation task group B and compilation task group C. Compilation task group A is distributed to remote builder 1, and compilation task group B is distributed to remote builder 2. If remote builder 1 completes the compilation of compilation task group A before remote builder 2, compilation task group C is sent to remote builder 1 until all compilation task groups complete the compilation.
[0094] For other examples of this embodiment, please refer to the above examples and will not be repeated here.
[0095] Figure 5 is a schematic diagram of an optional electronic device according to an embodiment of the present application, such as Figure 5 As shown, it includes a processor 502, a communication interface 504, a memory 506 and a communication bus 508, wherein the processor 502, the communication interface 504 and the memory 506 communicate with each other through the communication bus 508, wherein,
[0096] Memory 506, used for storing computer programs;
[0097] The processor 502 is used to execute the computer program stored in the memory 506 to implement the following steps:
[0098] Get the project source code of the target project from the main builder and convert the project source code into at least one compilation task;
[0099] Acquire a remote builder cluster from a registration center, wherein the remote builder cluster includes at least one remote builder that has completed registration in the registration center;
[0100] Distribute at least one compilation task to each remote builder in the remote builder cluster, so that each remote builder in the remote builder cluster compiles the received compilation task, obtains a corresponding compilation result, and returns it to the main builder;
[0101] The main builder is controlled to summarize each compilation result received to obtain the target compilation result of the target project.
[0102] Optionally, in this embodiment, the communication bus may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 The communication interface is used for communication between the above electronic device and other devices.
[0103] The memory may include RAM, or may include non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0104] As an example, the memory 506 may include, but is not limited to, the first acquisition module 402, the second acquisition module 404, the distribution module 406, and the aggregation module 408 in the apparatus for the distributed compilation project. In addition, other module units in the apparatus for the distributed compilation project may also be included but are not limited to, which will not be described in detail in this example.
[0105] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0106] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0107] It can be understood by those skilled in the art that Figure 5The structure shown is for illustration only. The device for implementing the above-mentioned distributed compilation project method may be a terminal device, which may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, and other terminal devices. Figure 5 The structure of the electronic device is not limited. For example, the electronic device may also include Figure 5 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 5 Different configurations shown.
[0108] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, which can include: a flash drive, ROM, RAM, a magnetic disk or an optical disk, etc.
[0109] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method for distributed compilation of projects are executed.
[0110] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.
[0111] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0112] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
[0113] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0114] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0115] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0116] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0117] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for distributed compilation of projects, It is characterized in that include: Obtain project source code of the target project from the main builder, and convert the project source code into at least one compilation task; Acquire a remote builder cluster from a registration center, wherein the remote builder cluster includes at least one remote builder that has completed registration in the registration center; Distributing the at least one compilation task to each remote builder of the remote builder cluster, so that each remote builder in the remote builder cluster compiles the received compilation task, obtains a corresponding compilation result, and returns it to the main builder; The main builder is controlled to summarize each received compilation result to obtain a target compilation result of the target project.
2. The method according to claim 1, It is characterized in that Before obtaining the remote builder cluster from the registration center, the method further includes: Broadcasting the service address of the registration center, so that the first remote builder communicates with the registration center once through the service address at each target time interval, so as to send the machine address and communication port of the first remote builder to the registration center, wherein the first remote builder is any remote builder among all remote builders that is running and can receive compilation tasks; The machine address and communication port of the first remote builder are stored in the registration center, and the first remote builder is marked as a remote builder that has completed registration.
3. The method according to claim 1, It is characterized in that The step of obtaining a remote builder cluster from a registration center includes: Obtaining a dependency relationship of each compilation task of the at least one compilation task; According to the dependency relationship of each compilation task, the compilation tasks with the dependency relationship are divided into a group to obtain at least one compilation task group; Obtain the number of task groups of the compilation task group; Obtaining the number of first builders of remote builders that have completed registration in the registration center; In the case that the number of the first builders is greater than the number of the task groups, the remote builders that have completed registration and the number of the task groups are acquired from the registration center to obtain the remote builder cluster.
4. The method according to claim 3, It is characterized in that The step of obtaining a remote builder cluster from a registration center includes: In the case that the number of the first builders is less than or equal to the number of the task groups, all remote builders that have completed registration are acquired from the registration center to obtain the remote builder cluster.
5. The method according to claim 3, It is characterized in that The distributing the at least one compilation task to each remote builder of the remote builder cluster comprises: In a case where the number of second builders in the remote builder cluster is equal to the number of task groups, the at least one compilation task group is distributed to each remote builder in the remote builder cluster.
6. The method according to claim 5, It is characterized in that The step of distributing the at least one compilation task group to each remote builder of the remote builder cluster comprises: Each of the at least one compiling task group is used as a current compiling task group, and the following operations are performed on the current compiling task group: When the number of compiling tasks in the current compiling task group is greater than one, determining a compiling order of each compiling task according to a dependency relationship of each compiling task in the current compiling task group; According to the compilation order, the first compilation task is sent to the remote builder corresponding to the current compilation task group, and after the remote builder corresponding to the current compilation task group completes the compilation of the first compilation task and returns the first compilation result corresponding to the first compilation task to the main builder, the second compilation task is sent to the remote builder corresponding to the current compilation task group until all the compilation tasks of the current compilation task group are completed, wherein the second compilation task is the next compilation task of the first compilation task in the compilation order.
7. The method according to claim 4, It is characterized in that The distributing the at least one compilation task to each remote builder of the remote builder cluster comprises: In a case where the number of second builders in the remote builder cluster is less than the number of task groups, distributing the second number of builders in the at least one compilation task group to each remote builder in the remote builder cluster; When the second remote builder completes the compilation of the corresponding compilation task group, the first compilation task group in the at least one compilation task group is distributed to the second remote builder until all the compilation task groups in the at least one compilation task group have completed the compilation, wherein the second remote builder is any remote builder in the remote builder cluster, and the first compilation task group is any one of the at least one compilation task group that has not been distributed.
8. A device for distributed compilation of projects, It is characterized in that include: A first acquisition module, configured to acquire a project source code of a target project from a main builder, and convert the project source code into at least one compilation task; A second acquisition module is used to acquire a remote builder cluster from a registration center, wherein the remote builder cluster includes at least one remote builder that has completed registration in the registration center; A distribution module, used for distributing the at least one compilation task to each remote builder of the remote builder cluster, so that each remote builder in the remote builder cluster compiles the received compilation task, obtains a corresponding compilation result, and returns it to the main builder; The summary module is used to control the main builder to summarize each received compilation result to obtain the target compilation result of the target project.
9. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is executed.
10. An electronic device comprising a memory and a processor, It is characterized in that A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.
