Microservice optimization method, device, medium and electronic device
Through the analysis of the program source code of microservices, determining the functional point counting elements and service types, optimizing the routing policy and virtual machine initialization configuration, the problem of system instability in the microservice architecture is solved, and the system stability and resource utilization are improved.
Patent Information
- Application Number
- CN202510695030.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-28
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2045-05-28
AI Technical Summary
Routing policies and virtual machine initialization configuration in the microservice architecture rely on the experience of technicians, resulting in system instability and affect reliability.
By performing functional point analysis on the program source code of optimized microservices, determining the functional point counting elements and service types, optimizing routing policies and virtual machine initialization configuration, and achieving accurate matching of service characteristics and hardware resources.
Significantly improve system stability and reliability, improve resource utilization, and reduce system instability and resource waste.
Smart Images

Figure CN120216102B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the fields of cloud computing and distributed programming, and in particular to a microservice optimization method, device, medium, and electronic device. Background Art
[0002] In the context of the Internet+ era, more and more applications are transitioning from monolithic applications to distributed programs. Microservices architecture is a specific implementation model for distributed programs. It improves system flexibility and scalability by splitting a single application into multiple microservices.
[0003] In related technologies, routing strategies and virtual machine initialization configurations in microservice architectures often rely on the experience of technical personnel and need to be continuously adjusted according to the system operation status. This trial-and-error process may cause service instability and affect system reliability. Summary of the Invention
[0004] The present application provides a microservice optimization method, device, medium, and electronic device, which can achieve the purpose of improving the stability and reliability of microservices.
[0005] According to a first aspect of the present application, a microservice optimization method is provided, the method comprising:
[0006] Performing function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized to determine a function point count element of the microservice to be optimized;
[0007] Determining the service type of the microservice to be optimized based on the function point count element;
[0008] Based on the service type, the routing strategy and virtual machine initialization configuration of the microservice to be optimized are optimized.
[0009] According to a second aspect of the present application, a microservice optimization device is provided, comprising:
[0010] a function point count element determination module, configured to obtain a program source code of a microservice to be optimized, and perform function point analysis on the microservice to be optimized based on the program source code to determine a function point count element of the microservice to be optimized;
[0011] A service type determination module, configured to determine the service type of the microservice to be optimized based on the function point count element;
[0012] The microservice optimization module is used to optimize the routing strategy and virtual machine initialization configuration of the microservice to be optimized based on the service type.
[0013] According to a third aspect of the present invention, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the microservice optimization method as described in the embodiment of the present application.
[0014] According to a fourth aspect of the present invention, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the microservice optimization method as described in the embodiment of the present application is implemented.
[0015] According to a fifth aspect of the present application, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the microservice optimization method as described in the embodiment of the present application.
[0016] The technical solution of the embodiment of the present application performs function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized, determines the function point counting elements of the microservice to be optimized, and can accurately identify the core functions and service characteristics of the microservice to be optimized, thereby determining the service type of the microservice to be optimized; by analyzing the core requirements and performance bottlenecks of the service type, the most suitable routing strategy is selected; according to the different requirements of the service type combined with the hardware configuration information, the virtual machine initialization parameters are dynamically adjusted to achieve accurate matching of service characteristics and hardware resources, which can significantly improve system stability and reliability and improve resource utilization.
[0017] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0019] Figure 1 This is a flowchart of the microservice optimization method provided according to Example 1;
[0020] Figure 2 This is a flowchart of the microservice optimization method provided in Example 2;
[0021] Figure 3 This is a flowchart of the microservice optimization method provided in Example 3;
[0022] Figure 4This is a schematic diagram of the structure of the microservice optimization device provided in Example 4 of the present application;
[0023] Figure 5 This is a structural diagram of an electronic device provided in Example 5 of the present application. DETAILED DESCRIPTION
[0024] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0025] It should be noted that the terms "first", "second", "target" and "candidate" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0026] Example 1
[0027] Figure 1 This is a flowchart of the microservice optimization method provided in Example 1. This embodiment is applicable to the situation where the routing strategy and virtual machine initialization configuration of microservices are optimized in a microservice architecture. The method can be executed by a microservice optimization device, which is implemented in the form of hardware and / or software and can be integrated into the electronic device running this system.
[0028] like Figure 1 As shown, the method includes:
[0029] S110: Perform function point analysis on the microservice to be optimized based on a program source code of the microservice to be optimized to determine a function point count element of the microservice to be optimized.
[0030] S120: Determine the service type of the microservice to be optimized based on the function point count element.
[0031] S130: Based on the service type, optimize the routing strategy and virtual machine initialization configuration of the microservice to be optimized.
[0032] Microservices to be optimized are those whose routing policies and virtual machine initialization configurations require optimization. Function point analysis of the microservices to be optimized involves measuring the logical view of the microservices to be optimized and analyzing the achievable functions of the microservices from an external business perspective of user needs. The logical view describes the functional requirements and behavior of the microservices to be optimized and serves as the design foundation for the program source code. Specific modules in the program source code typically correspond to function points in the logical view. The program source code describes the logic and functionality of the microservices to be optimized using a programming language, defining their functions, behaviors, and execution methods. The program source code is used to perform function point analysis on the microservices to be optimized.
[0033] By performing function point analysis on the microservice to be optimized, you can determine the function point count elements of the microservice to be optimized. Function point count elements are the core components of function point analysis used to quantify the functionality of the microservice to be optimized. Optional function point count elements include ILF (Internal Logical Files), EIF (External Interface Files), EI (External Inputs), EQ (External Queries), and EO (External Outputs).
[0034] Function Point Count elements have different representations and proportions for different service types. By analyzing these elements, you can determine the service type of the microservice to be optimized. Optional service types for optimized microservices include: write-heavy read-less, write-less read-heavy, and external dependency.
[0035] When the service type of the microservice to be optimized is determined, the routing strategy and virtual machine initialization configuration of the microservice to be optimized are optimized based on the service type.
[0036] Optimizing the routing strategy for a microservice based on its service type is essentially an optimization design based on service characteristics and potential bottlenecks. By analyzing the core requirements and performance bottlenecks of a service type and selecting the most appropriate routing strategy, system stability and reliability can be effectively improved.
[0037] The virtual machine initialization configuration of the microservice to be optimized is optimized based on the service type of the microservice to be optimized. The core is to dynamically adjust the virtual machine initialization parameters according to the different requirements of the service type and the hardware configuration information. It is mainly to accurately match the service characteristics with the hardware resources, aiming to optimize performance, improve resource utilization and ensure system stability.
[0038] The technical solution of the embodiment of the present application performs function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized, determines the function point counting elements of the microservice to be optimized, and can accurately identify the core functions and service characteristics of the microservice to be optimized, thereby determining the service type of the microservice to be optimized; by analyzing the core requirements and performance bottlenecks of the service type, the most suitable routing strategy is selected; according to the different requirements of the service type combined with the hardware configuration information, the virtual machine initialization parameters are dynamically adjusted to achieve accurate matching of service characteristics and hardware resources, which can significantly improve system stability and reliability and improve resource utilization.
[0039] In an optional embodiment, before performing function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized, the method further includes: obtaining a class path directory and a source code directory of the microservice to be optimized, and obtaining class files under the class path directory based on the class path directory; generating a source code path of the microservice to be optimized based on the metadata of the class files and the source code directory; and obtaining the program source code of the microservice to be optimized based on the source code path.
[0040] The classpath (cph) directory specifies the path the VM should search when loading class files. The source directory (src) stores the source code files of the microservice to be optimized. Class files are typically stored in the classpath directory and are the foundation for VM operation. Once the classpath directory is determined, the class files stored there are retrieved.
[0041] Once the class file is identified, the class file's metadata is obtained. The class file's metadata describes the class itself. Optionally, the class file's metadata includes the package name, class name, class annotation, method name, and method annotation.
[0042] Optionally, the source code path of the microservice to be optimized is generated based on the source code path and the package and class names of the class files. The source code path is the key directory for storing source code files, typically organized according to a package structure. Based on the source code path, the program source code of the microservice to be optimized can be loaded from memory.
[0043] The above technical solution provides a practical program source code acquisition solution for obtaining the program source code of the microservice to be optimized, and provides data support and technical support for functional point analysis of the microservice to be optimized based on the program source code.
[0044] Example 2
[0045] Figure 2 This is a flow chart of a microservice optimization method according to Example 2. This embodiment further optimizes the above embodiment.
[0046] like Figure 2 As shown, the method includes:
[0047] S210: Perform method segmentation on the program source code of the microservice to be optimized to obtain at least two method units.
[0048] A method unit is a basic unit in the program source code that implements a specific function. The program source code includes at least two method units. Method units are obtained by performing method segmentation on the program source code of the microservice to be optimized.
[0049] S220: Determine, based on the key identifier in the method unit, a function type corresponding to the method unit in function point analysis.
[0050] The key identifier is used to identify the starting point of the method unit's functional logic and define the method unit's functional type. Based on the key identifier, the corresponding functional type of the method unit in function point analysis can be determined.
[0051] Optionally, the function type includes transaction function and data function. For example, the key identifiers may be Action, Controller, and @RestController. Action generally corresponds to transaction function, while Controller and @RestController correspond to both data function and transaction function.
[0052] S230: Based on the function type and the operation content of the method unit, perform function point analysis on the microservice to be optimized to determine a function point count element of the microservice to be optimized.
[0053] Method units typically implement complete business logic and data operations through the service layer and data access layer (DAL). Optionally, the service layer and data access layer associated with the method unit are penetrated layer by layer. Throughout the penetration process, function point analysis is performed on the service layer and data access layer to determine the function point count elements of the microservice to be optimized.
[0054] S240: Determine the service type of the microservice to be optimized based on the function point count element.
[0055] S250: Based on the service type, optimize the routing strategy and virtual machine initialization configuration of the microservice to be optimized.
[0056] The technical solution of the embodiment of the present application obtains at least two method units by performing method segmentation on the program source code of the microservice to be optimized. Based on the key identifier in the method unit, the function type corresponding to the method unit in the function point analysis is determined. Based on the function type and the operation content of the method unit, a function point analysis is performed on the microservice to be optimized to determine the function point counting elements of the microservice to be optimized, providing a practical function point analysis solution that can be used to determine the function point counting elements of the microservice to be optimized, ensuring the accuracy of the function point counting elements. It provides data support and technical support for the subsequent determination of the service type of the optimized microservice based on the function point counting elements.
[0057] In an optional embodiment, the function point analysis of the microservice to be optimized is performed based on the function type and the operation content of the method unit to determine the function point counting element of the microservice to be optimized, including: if the function type is a data function and the method unit includes a file path creation operation, then the number of external interface file processing times is determined based on the number of file path creation times; if the function type is a data function and the method unit includes a database access operation, then the number of internal logic file processing times is determined based on the number of accesses to structured databases and unstructured databases in the method unit; if the function type is a transaction function and the method unit includes a transaction ... external interface file processing times is determined based on the number of external interface file processing times. If the unit includes processing operations for external event instructions, the number of external inputs is determined based on the number of calls to the message middleware in the method unit; if the function type is a transaction function and the method unit includes data acquisition operations on the server or memory, the number of external queries is determined based on the number of data acquisitions; if the function type is a transaction function and the method unit includes data submission operations on the server, the number of external outputs is determined based on the number of data submissions; based on the number of external interface file processing times, the number of internal logic file processing times, the number of external inputs, the number of external queries and the number of external outputs, the function point counting elements of the microservice to be optimized are determined.
[0058] Function point counting elements that belong to data functions include ILF and EIF, and those that belong to transaction functions include EI, EQ, and EO.
[0059] If the function type is a data function and the method unit includes an API usage for a file package, this indicates that the method unit includes a file path creation operation. The number of file path creations is counted to determine the number of external interface file (EIF) processing operations.
[0060] The function type is a data function, and the method unit includes database access operations. Optionally, the database access operations include add, delete, modify, and query operations on structured or unstructured databases. Count the number of accesses to the structured and unstructured databases to determine the number of internal logical file (ILF) processing times.
[0061] If the function type is a transaction function and the method unit includes processing operations for external event instructions, the number of external inputs (EIs) is determined based on the number of calls to the APIs of messaging middleware such as RabbitMQ, Kafka, ActiveMQ, and RocketMQ in the method unit.
[0062] If the function type is a transaction function and the method unit includes a data acquisition operation on the server or memory, such as calling a Redis and including an HTTP get request code, the number of external queries (EQ) is determined based on the number of data acquisition times.
[0063] If the function type is a transaction function and the method unit includes a data submission operation to the server, such as calling a code including an HTTP post request, the number of external outputs (EOs) is determined based on the number of data submissions.
[0064] Based on the number of external interface file processing times, internal logic file processing times, external input times, external query times, and external output times, the function point counting elements of the microservice to be optimized are determined.
[0065] The above technical solution provides a practical solution for determining function point counting elements, and provides data and technical support for the subsequent determination of service types for optimized microservices based on function point counting elements.
[0066] Example 3
[0067] Figure 3 This is a flow chart of a microservice optimization method according to Example 3. This embodiment is further optimized based on the above embodiment.
[0068] like Figure 3 As shown, the method includes:
[0069] S310: Perform function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized to determine a function point count element of the microservice to be optimized.
[0070] S320: Determine the read / write mode and the dependency type based on the function point count element.
[0071] Optionally, the function point count elements include: ILF, EIF, EI, EQ, and EO. The read / write model and dependency type can be determined based on the quantity distribution of each type of function point count element.
[0072] S330: Determine the service type of the microservice to be optimized based on the read / write mode and the dependency type.
[0073] Optional microservice types to be optimized include: read-heavy, write-less, read-less, write-heavy, and external dependency. Read-write patterns can be used to determine the read-write ratio, while dependency types can be used to determine the degree of reliance on external systems.
[0074] If the proportion of read operations is higher than that of write operations, the service type of the microservice to be optimized is determined to be read-heavy and write-less. If the proportion of write operations is higher than that of read operations in the read-write mode, the service type of the microservice to be optimized is determined to be write-heavy and read-less. If the microservice has a high degree of dependence on external systems, the service type of the microservice to be optimized is determined to be externally dependent.
[0075] S340: Based on the service type, optimize the routing strategy and virtual machine initialization configuration of the microservice to be optimized.
[0076] The technical solution of the embodiment of the present application determines the function point count elements of the microservice to be optimized by performing function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized. Based on the function point count elements, the read and write modes and dependency types are determined respectively. Based on the read and write modes and dependency types, the service type of the microservice to be optimized is determined, providing a practical service type determination solution, which is used to select the most suitable routing strategy for subsequent analysis of the core requirements and performance bottlenecks of the service type; according to the different requirements of the service type combined with the hardware configuration information, the virtual machine initialization parameters are dynamically adjusted to achieve a precise match between service characteristics and hardware resources, providing technical support and data support.
[0077] In an optional embodiment, the service type of the microservice to be optimized is determined based on the read-write mode and the dependency type, including: if the number of external queries is greater than a first preset ratio of the sum of the external interface file processing number, the internal logic file processing number, the external input number, and the external output number, determining that the service type of the microservice to be optimized is more read and less write; if the sum of the external input number and the internal logic file processing number is greater than a second preset ratio of the sum of the external query number, the external interface file processing number, and the external output number, determining that the service type of the microservice to be optimized is more write and less read; if the sum of the external output number and the external interface file processing number is greater than a third preset ratio of the sum of the external query number, the external input number, and the internal logic file processing number, determining that the service type of the microservice to be optimized is external dependency.
[0078] EQ (External Query) primarily reads data from memory or servers and does not involve data modification or complex calculations. If the number of EQs is significantly higher than the first preset ratio of the sum of the number of EIs, EOs, ILFs, and EIFs, this indicates that the microservice being optimized primarily functions as a data query, preferring to obtain information rather than modify data. Therefore, the service type of the microservice being optimized is determined to be read-heavy and write-less. The first preset ratio is determined based on actual business needs, and its specific value is not limited here. For example, the first preset ratio is 70%.
[0079] EI (external input) involves calling the message middleware to input data or send instructions to the system. ILF (internal logical file) refers to data that needs to be maintained within the system and supports add, delete, modify, and query operations on structured or unstructured databases. If the sum of the EI and ILF counts exceeds the second preset ratio of the sum of the EIF, EQ, and EO counts, it indicates that the primary function of the microservice to be optimized is data maintenance and update, and the service type of the microservice to be optimized is determined to be write-intensive and read-less. The second preset ratio is determined based on actual business needs, and its specific value is not limited here. For example, the second preset ratio is 60%.
[0080] EO (External Output) involves submitting data to the server; EIF (External Interface File) involves creating a file path. If the sum of EO and EIF is greater than the third preset ratio of the sum of EQ, EI, and ILF, it indicates that the microservice being optimized has a high degree of dependence on external data or external systems. The service type of the microservice being optimized is determined to be externally dependent. The third preset ratio is determined based on actual business needs and its specific value is not limited here. For example, the third preset ratio is 40%.
[0081] The above technical solution provides a reliable service type determination solution. It determines the read and write mode and dependency type of the microservice to be optimized based on the quantity distribution of various function point counting elements, and then determines the service type of the microservice to be optimized. It provides data support and technical support for optimizing the routing strategy and virtual machine initialization configuration of the microservice to be optimized based on the service type.
[0082] In an optional embodiment, based on the service type, the virtual machine initialization configuration of the microservice to be optimized is optimized, including: when the microservice to be optimized is started, obtaining the hardware configuration information of the server; if the service type of the microservice to be optimized is write-more and read-less or externally dependent, determining the number of virtual machine threads based on the number of central processing unit cores in the hardware configuration information; if the service type of the microservice to be optimized is read-more and write-less, determining the number of service instances, virtual machine memory and garbage collection type based on the memory size in the hardware configuration information.
[0083] The server's hardware configuration information includes at least the number of central processing unit (CPU) cores and memory size. After obtaining this hardware configuration information, initializing the virtual machine configuration based on the service type of the microservice to be optimized can improve the compatibility of the microservice to be optimized with business requirements.
[0084] Write-heavy, read-less scenarios involve a large number of write operations, and external dependencies require frequent calls to external services, requiring high CPU processing power and efficient concurrent processing capabilities. The number of virtual machine threads is set based on the number of CPU cores. Optionally, if the CPU has 4 cores, set the number of virtual machine threads to 2000. If the CPU has more than 4 cores, use 4 cores as the baseline for determining the number of virtual machine threads. Allocating virtual machine threads based on the number of CPU cores avoids wasting or overloading CPU resources, ensuring efficient processing of write operations and external calls, and improving system responsiveness.
[0085] Reading more and writing less involves a large number of read operations, which requires higher memory capacity and garbage collection efficiency. Determine the number of service instances, virtual machine memory, and garbage collection type based on the memory size in the hardware configuration information. Optionally, if the memory in the hardware configuration information is less than 8G, determine the number of service instances to be 1, and the virtual machine memory to be 80% of the memory; if the memory in the hardware configuration information is greater than 8G, obtain 80% of the memory in the hardware configuration information and divide the memory into equal parts of no more than 6G to determine the number of service instances and virtual machine memory; if the memory in the hardware configuration information is less than 4G, determine the garbage collection type to be cms; if the memory in the hardware configuration information is greater than 4G, determine the garbage collection type to be G1. Doing so can improve memory utilization, reduce the impact of garbage collection on system performance, improve the response speed of read operations, and avoid system crashes or performance degradation due to insufficient memory.
[0086] The above technical solution dynamically adjusts the virtual machine initialization configuration according to the service type of the microservice to be optimized, which can maximize hardware utilization and improve the stability and reliability of the system.
[0087] In an optional embodiment, based on the service type, the routing strategy of the microservice to be optimized is optimized, including: if the service type of the microservice to be optimized is external dependency, the response time weighted sum of minimum connections is used as the routing strategy of the microservice to be optimized; if the service type of the microservice to be optimized is more writes and less reads, the polling strategy is used as the routing strategy of the microservice to be optimized; if the service type of the microservice to be optimized is more reads and less writes, the random strategy is used as the routing strategy of the microservice to be optimized.
[0088] For microservices with external dependencies, focus on dynamic adjustment of response time and number of connections. For microservices with more writes and less reads, focus on load balancing. For microservices with more reads and less writes, focus on resource utilization and hot issues.
[0089] When the service type is externally dependent, using response time weighting as the routing strategy for the optimized microservice dynamically assigns weights based on the response time of the microservice instance, allowing microservice instances with shorter response times to receive more requests. Using minimum connections as the routing strategy distributes requests to the microservice instance with the fewest connections, ensuring load balancing. This can optimize response time, as external dependencies often involve calling third-party services, which can have erratic response times. Response time weighting prioritizes microservice instances with faster responses, improving user experience. It also prevents certain microservice instances from becoming performance bottlenecks due to excessive connections, ensuring system stability.
[0090] When the service type is write-heavy and read-less, using a round-robin strategy as the routing strategy for the microservice being optimized can distribute requests sequentially to all available microservice instances, ensuring that each microservice instance shares the load evenly. This is because write-heavy and read-less services typically involve a large number of write operations. The polling strategy can evenly distribute requests, preventing performance degradation of some microservice instances due to excessive write pressure.
[0091] When the service type is read-heavy and write-sparse, using a random strategy as the routing strategy for the microservice being optimized can randomly assign requests to available microservice instances, ensuring that each microservice instance has an equal chance of processing requests. This is because read-heavy and write-sparse services typically involve a large number of read operations. The random strategy can prevent certain instances from becoming hotspots due to frequent reads, thereby improving overall performance. The random strategy can fully utilize the resources of all microservice instances, preventing some instances from being idle.
[0092] In an optional embodiment, a project management plug-in is defined and a triggering method for running the project management plug-in is set. The project management plug-in is then configured in the project management configuration of the microservice to be optimized. Optionally, the triggering method for running the project management plug-in is set to run the project management plug-in in response to detecting a code packaging operation for the microservice to be optimized. Exemplarily, the type of the project management plug-in can be a Maven plug-in, and the project management plug-in is identified using maven-ngc-plugin. In response to detecting a code packaging operation such as deploy and install for the microservice to be optimized, the maven-ngc-plugin is run.
[0093] During the operation of maven-NGC-plugin, a code indicator container is created for the microservice to be optimized through maven-NGC-plugin, wherein the code indicator container includes a characteristic value area and a counting area. During the operation of maven-NGC-plugin, the class files under the class path directory are obtained, the class files under the class directory path are loaded and iterated, the metadata of the class files such as package name, class name, class annotation, method name, method annotation, etc. are obtained, and the metadata of the class files are stored in the characteristic value area of the code indicator container. Based on the metadata of the class files and the source code directory, maven-NGC-plugin generates the source code path of the microservice to be optimized. Then, based on the source code path, the program source code of the microservice to be optimized is loaded into memory, the program source code is segmented into methods, and the segmented method units are stored in the characteristic value area of the code indicator container.
[0094] Next, key identifiers are extracted from the method units in the feature value area and stored in the count area of the code metric container. Function point analysis is performed on the microservice to be optimized based on the key identifiers to determine the function point count elements of the microservice to be optimized. These function point count elements include ILF, EIF, EI, EQ, and EO. The function point count elements corresponding to the key identifiers are summarized and, based on these function point count elements, the service type of the microservice to be optimized is determined.
[0095] The above technical solution defines a project management plug-in and uses it to create a code metrics container for the microservice to be optimized. The code metrics container stores class file metadata and method units derived from source code segmentation in its feature value area, and stores key identifiers in its count area. This provides a practical solution for determining the service type of the microservice to be optimized.
[0096] Example 4
[0097] Figure 4 This is a structural diagram of the microservice optimization device provided in Example 4 of the present application. This embodiment can be applied to the situation where the routing strategy and virtual machine initialization configuration of microservices are optimized in a microservice architecture. The device can be implemented by software and / or hardware and can be integrated into electronic devices such as smart terminals.
[0098] like Figure 4 As shown, the device may include:
[0099] A function point count element determination module 410 is configured to perform function point analysis on the microservice to be optimized based on its program source code to determine a function point count element of the microservice to be optimized;
[0100] A service type determination module 420 is configured to determine the service type of the microservice to be optimized based on the function point count element;
[0101] The microservice optimization module 430 is configured to optimize the routing strategy and virtual machine initialization configuration of the microservice to be optimized based on the service type.
[0102] The technical solution of the embodiment of the present application performs function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized, determines the function point counting elements of the microservice to be optimized, and can accurately identify the core functions and service characteristics of the microservice to be optimized, thereby determining the service type of the microservice to be optimized; by analyzing the core requirements and performance bottlenecks of the service type, the most suitable routing strategy is selected; according to the different requirements of the service type combined with the hardware configuration information, the virtual machine initialization parameters are dynamically adjusted to achieve accurate matching of service characteristics and hardware resources, which can significantly improve system stability and reliability and improve resource utilization.
[0103] Optionally, the function point count element determination module 410 includes: a method splitting submodule, used to perform method splitting on the program source code of the microservice to be optimized to obtain at least two method units; a function type determination submodule, used to determine the function type corresponding to the method unit in the function point analysis based on the key identifier in the method unit; and a function point count element determination submodule, used to perform function point analysis on the microservice to be optimized based on the function type and the operation content of the method unit to determine the function point count element of the microservice to be optimized.
[0104] Optionally, the function point counting element determination submodule includes: an external interface file processing times determination unit, which is used to determine the external interface file processing times based on the file path creation times if the function type is a data function and the method unit includes a file path creation operation; an internal logic file processing times determination unit, which is used to determine the internal logic file processing times based on the number of accesses to structured databases and unstructured databases in the method unit if the function type is a data function and the method unit includes a database access operation; an external input times determination unit, which is used to determine the internal logic file processing times based on the number of accesses to structured databases and unstructured databases in the method unit if the function type is a transaction function and the method unit includes an external event instruction processing operation. The number of external inputs is determined by the number of calls to the message middleware in the method unit; the external query number determination unit is used to determine the number of external queries based on the number of data acquisitions if the function type is a transaction function and the method unit includes a data acquisition operation on the server or memory; the external output number determination unit is used to determine the number of external outputs based on the number of data submissions if the function type is a transaction function and the method unit includes a data submission operation on the server; the function point counting element determination unit is used to determine the function point counting element of the microservice to be optimized based on the number of external interface file processing times, the number of internal logic file processing times, the external input times, the external query times and the external output times.
[0105] Optionally, the service type determination module 420 includes: a function ratio determination sub-module, which is used to determine the read and write mode and dependency type based on the function point counting element; and a service type determination sub-module, which is used to determine the service type of the microservice to be optimized based on the read and write mode and dependency type.
[0106] Optionally, the service type determination submodule includes: a first service type determination unit, which is used to determine that the service type of the microservice to be optimized is more read and less write if the number of external queries is greater than a first preset ratio of the sum of the number of external interface file processing times, the number of internal logic file processing times, the number of external input times and the number of external output times; a second service type determination unit, which is used to determine that the service type of the microservice to be optimized is more write and less read if the sum of the number of external input times and the number of internal logic file processing times is greater than a second preset ratio of the sum of the number of external queries, the number of external interface file processing times and the number of external outputs; and a third service type determination unit, which is used to determine that the service type of the microservice to be optimized is externally dependent if the sum of the number of external outputs and the number of external interface file processing times is greater than a third preset ratio of the sum of the number of external queries, the number of external inputs and the number of internal logic file processing times.
[0107] Optionally, the microservice optimization module includes: a first routing strategy determination submodule, which is used to use the response time weighted sum and minimum connection as the routing strategy of the microservice to be optimized if the service type of the microservice to be optimized is external dependency; a second routing strategy determination submodule, which is used to use the polling strategy as the routing strategy of the microservice to be optimized if the service type of the microservice to be optimized is more writes and less reads; and a third routing strategy determination submodule, which is used to use the random strategy as the routing strategy of the microservice to be optimized if the service type of the microservice to be optimized is more reads and less writes.
[0108] Optionally, the microservice optimization module includes: a hardware configuration acquisition submodule, used to obtain the hardware configuration information of the server when the microservice to be optimized is started; a first virtual machine initialization configuration determination submodule, used to determine the number of virtual machine threads based on the number of central processing unit cores in the hardware configuration information if the service type of the microservice to be optimized is write-more and read-less or externally dependent; a second virtual machine initialization configuration determination submodule, used to determine the number of service instances, virtual machine memory and garbage collection type based on the memory size in the hardware configuration information if the service type of the microservice to be optimized is read-more and write-less.
[0109] Optionally, the device also includes: a class file acquisition module, which is used to obtain the class path directory and source code directory of the microservice to be optimized before performing function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized, and obtain the class files under the class path directory based on the class path directory; a source code path generation module, which is used to generate the source code path of the microservice to be optimized based on the metadata of the class file and the source code directory; and a source code acquisition module, which is used to obtain the program source code of the microservice to be optimized based on the source code path.
[0110] The microservice optimization device provided in the embodiment of the invention can execute the microservice optimization method provided in any embodiment of the present application, and has the corresponding performance modules and beneficial effects for executing the microservice optimization method.
[0111] Example 5
[0112] According to embodiments of the present application, the present application also provides an electronic device, a readable storage medium, and a computer program product.
[0113] Figure 5The following diagram illustrates the structure of an electronic device 510 that can be used to implement an embodiment. The electronic device 510 includes at least one processor 511 and memory, such as a read-only memory (ROM) 512 and a random access memory (RAM) 513, communicatively connected to the at least one processor 511. The memory stores computer programs executable by the at least one processor. The processor 511 can perform various appropriate actions and processes based on the computer programs stored in the ROM 512 or loaded from a storage unit 518 into the RAM 513. The RAM 513 can also store various programs and data required for the operation of the electronic device 510. The processor 511, ROM 512, and RAM 513 are interconnected via a bus 514. An input / output (I / O) interface 515 is also connected to the bus 514.
[0114] Multiple components in the electronic device 510 are connected to the I / O interface 515, including an input unit 516, such as a keyboard, a mouse, etc.; an output unit 517, such as various types of displays, speakers, etc.; a storage unit 518, such as a magnetic disk, an optical disk, etc.; and a communication unit 519, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 519 allows the electronic device 510 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0115] Processor 511 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of processor 511 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors that run machine learning model algorithms, digital signal processors (DSPs), and any other suitable processor, controller, microcontroller, etc. Processor 511 executes the various methods and processes described above, such as the microservice optimization method.
[0116] In some embodiments, the microservice optimization method can be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as storage unit 518. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 510 via ROM 512 and / or communication unit 519. When the computer program is loaded into RAM 513 and executed by processor 511, one or more steps of the microservice optimization method described above can be performed. Alternatively, in other embodiments, processor 511 can be configured to execute the microservice optimization method in any other suitable manner (e.g., via firmware).
[0117] Various embodiments of the systems and techniques described above can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0118] Computer programs for implementing the methods of the present application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable microservice optimization device, so that when executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer programs can be executed entirely on the machine, partially on the machine, as a standalone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0119] In the context of the present application, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or apparatus. A computer-readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or apparatus, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0120] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device that has: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0121] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a microservices optimization server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected via any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0122] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.
[0123] The present application also discloses a computer program product comprising a computer program that, when executed by a processor, implements the microservice optimization method provided in any of the embodiments of the present application. This program product and the microservice optimization method disclosed in each embodiment of the present application share the same inventive concept and are therefore not described in detail here.
[0124] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this application can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of this application can be achieved. This is not limited herein.
[0125] The above specific embodiments do not constitute a limitation on the scope of protection of this application. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application shall be included within the scope of protection of this application.
Claims
1. A microservice optimization method, characterized in that: The method comprises: Performing function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized to determine a function point count element of the microservice to be optimized; Determining the service type of the microservice to be optimized based on the function point count element; Based on the service type, optimize the routing strategy and virtual machine initialization configuration of the microservice to be optimized; The determining of the service type of the microservice to be optimized based on the function point count element includes: determining a read / write mode and a dependency type based on the function point count element; determining the service type of the microservice to be optimized based on the read / write mode or the dependency type; the read / write mode and the dependency type are determined based on the quantity distribution of various function point count elements; Among them, based on the service type, the virtual machine initialization configuration of the microservice to be optimized is optimized, including: when the microservice to be optimized is started, the hardware configuration information of the server is obtained; if the service type of the microservice to be optimized is write-more and read-less or externally dependent, the number of virtual machine threads is determined based on the number of central processing unit cores in the hardware configuration information; if the service type of the microservice to be optimized is read-more and write-less, the number of service instances, virtual machine memory and garbage collection type are determined based on the memory size in the hardware configuration information.
2. The method according to claim 1, characterized in that The performing function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized to determine the function point count element of the microservice to be optimized includes: Performing method segmentation on the program source code of the microservice to be optimized to obtain at least two method units; wherein the method unit implements complete business logic and data operations through the service layer and the data access layer; the method unit is the basic unit that implements a specific function in the program source code; Determining, based on the key identifier in the method unit, a function type corresponding to the method unit in function point analysis; Based on the function type and the operation content of the method unit, a function point analysis is performed on the microservice to be optimized to determine a function point count element of the microservice to be optimized.
3. The method according to claim 2, characterized in that The performing function point analysis on the microservice to be optimized based on the function type and the operation content of the method unit to determine a function point count element of the microservice to be optimized includes: If the function type is a data function and the method unit includes a file path creation operation, then determining the external interface file processing times based on the file path creation times; If the function type is a data function and the method unit includes a database access operation, then determining the number of internal logical file processing times based on the number of accesses to the structured database and the unstructured database in the method unit; If the function type is a transaction function and the method unit includes a processing operation of an external event instruction, determining the number of external inputs based on the number of calls to the message middleware in the method unit; If the function type is a transaction function and the method unit includes a data acquisition operation on a server or a memory, determining the number of external queries based on the number of data acquisitions; If the function type is a transaction function and the method unit includes a data submission operation to the server, determining the external output number based on the data submission number; Based on the external interface file processing times, the internal logic file processing times, the external input times, the external query times, and the external output times, a function point count element of the microservice to be optimized is determined.
4. The method according to claim 1, wherein Determining the service type of the microservice to be optimized based on the read / write mode or dependency type includes: If the number of external queries is greater than a first preset ratio of the sum of the number of external interface file processing times, the number of internal logic file processing times, the number of external input times, and the number of external output times, it is determined that the service type of the microservice to be optimized is read-more and write-less; If the sum of the external input times and the internal logic file processing times is greater than a second preset ratio of the sum of the external query times, the external interface file processing times, and the external output times, it is determined that the service type of the microservice to be optimized is more writes than reads; If the sum of the external output times and the external interface file processing times is greater than a third preset ratio of the sum of the external query times, the external input times and the internal logic file processing times, it is determined that the service type of the microservice to be optimized is external dependency.
5. The method according to claim 1, wherein Based on the service type, the routing strategy of the microservice to be optimized is optimized, including: If the service type of the microservice to be optimized is external dependency, the response time weighted and minimum connection are used as the routing strategy of the microservice to be optimized; If the service type of the microservice to be optimized is more writes than reads, the polling strategy is used as the routing strategy of the microservice to be optimized; If the service type of the microservice to be optimized is more read than write, the random strategy is used as the routing strategy of the microservice to be optimized.
6. The method according to claim 1, characterized in that Before performing function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized, the method further includes: Obtain the class path directory and source code directory of the microservice to be optimized, and obtain the class files under the class path directory based on the class path directory; Generate a source code path of the microservice to be optimized based on the metadata of the class file and the source code directory; Based on the source code path, the program source code of the microservice to be optimized is obtained.
7. A microservice optimization device, characterized in that: The device comprises: a function point count element determination module, configured to perform function point analysis on the microservice to be optimized based on the program source code of the microservice to be optimized, so as to determine the function point count element of the microservice to be optimized; A service type determination module, configured to determine the service type of the microservice to be optimized based on the function point count element; A microservice optimization module, configured to optimize the routing strategy and virtual machine initialization configuration of the microservice to be optimized based on the service type; The service type determination module includes: a function ratio determination submodule for determining a read / write mode and a dependency type based on the function point count element; a service type determination submodule for determining the service type of the microservice to be optimized based on the read / write mode or the dependency type; the read / write model and the dependency type are determined based on the quantity distribution of various function point count elements; The microservice optimization module includes: a hardware configuration acquisition submodule, which is used to obtain the hardware configuration information of the server when the microservice to be optimized is started; a first virtual machine initialization configuration determination submodule, which is used to determine the number of virtual machine threads based on the number of central processing unit cores in the hardware configuration information if the service type of the microservice to be optimized is write-more-read-less or externally dependent; and a second virtual machine initialization configuration determination submodule, which is used to determine the number of service instances, virtual machine memory, and garbage collection type based on the memory size in the hardware configuration information if the service type of the microservice to be optimized is read-more-write-less.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the microservice optimization method according to any one of claims 1 to 6 is implemented.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein: When the processor executes the computer program, the microservice optimization method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Route selection method, network equipment and computer readable medium
CN116684493A
Software scale measurement method and system based on NLP
CN117055842A