Micro-service optimization method and device, medium and electronic equipment

By performing functional point analysis of the program source code of microservices, determining the service type and optimizing the routing policy and virtual machine initialization configuration, the problem of service instability in the microservice architecture is solved, and the system reliability and resource utilization are improved.

CN120216102AActive Publication Date: 2025-06-27HANGZHOU NEWGRAND TECHNOLOGY CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202510695030.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-28
Publication Date
2025-06-27
Estimated Expiration
2045-05-28

AI Technical Summary

Technical Problem

The routing policies and virtual machine initialization configuration in the microservice architecture depend on the experience of technicians and need to be continuously adjusted, resulting in unstable service and affecting system reliability.

Method used

By performing functional point analysis on the program source code of the microservice to optimize, determining the functional point counting elements, accurately identifying core functions and service characteristics, and thus determining the service type. According to the core requirements and performance bottlenecks of the service type, select the most suitable routing strategy and dynamically adjust the virtual machine initialization parameters to achieve accurate matching of service characteristics and hardware resources.

Benefits of technology

It significantly improves the stability and reliability of microservices, improves resource utilization, and reduces the trial and error process of unstable service.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120216102A_ABST
    Figure CN120216102A_ABST
Patent Text Reader

Abstract

The invention discloses a micro-service optimization method and device, a medium and electronic equipment, and the method comprises the steps: carrying out the function point analysis of a to-be-optimized micro-service based on a program source code of the to-be-optimized micro-service, so as to determine a function point counting element of the to-be-optimized micro-service; determining the service type of the micro-service to be optimized based on the function point counting element; and based on the service type, optimizing a routing strategy of the to-be-optimized micro-service and initialization configuration of the virtual machine. By executing the technical scheme provided by the invention, the system performance can be remarkably improved, the system reliability is enhanced, and the resource utilization rate is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of cloud computing and distributed programs, and particularly to a microservice optimization method, device, medium, and electronic device. Background Art

[0002] In the context of Internet Plus, more and more application programs have changed from monolithic application programs to distributed programs. The microservice architecture is a specific implementation mode in distributed programs, which improves the flexibility and scalability of the system by splitting a single application program into multiple microservices.

[0003] In related technologies, the routing strategy and virtual machine initialization configuration in the microservice architecture often rely on the experience of technicians and need to be continuously adjusted according to the system operation situation. This trial-and-error process may lead to service instability and affect the reliability of the system. Summary of the Invention

[0004] This 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 the first aspect of this application, a microservice optimization method is provided. The method includes:

[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 the function point counting elements of the microservice to be optimized;

[0007] Determining the service type of the microservice to be optimized based on the function point counting elements;

[0008] Optimizing the routing strategy and virtual machine initialization configuration of the microservice to be optimized based on the service type.

[0009] According to the second aspect of this application, a microservice optimization device is provided. The device includes:

[0010] A function point counting element determination module, configured to obtain the program source code of the microservice to be optimized, and perform function point analysis on the microservice to be optimized based on the program source code to determine the function point counting elements 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 counting elements;

[0012] 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.

[0013] According to a third aspect of the present invention, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it 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, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements the microservice optimization method as described in the embodiment of the present application.

[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, and when the computer program is executed by a processor, it 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 analyzes the function points of 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, can accurately identify the core functions and service characteristics of the microservice to be optimized, and thus determines the service type of the microservice to be optimized; by analyzing the core requirements and performance bottlenecks of the service type, selects the most suitable routing strategy; dynamically adjusts the virtual machine initialization parameters according to the different requirements of the service type in combination with the hardware configuration information to achieve an accurate match between the service characteristics and the hardware resources, which can significantly improve the system stability and reliability and improve the resource utilization rate.

[0017] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present application, nor is it used 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 will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0019] Figure 1 is a flowchart of the microservice optimization method provided in Embodiment 1;

[0020] Figure 2 is a flowchart of the microservice optimization method provided in Embodiment 2;

[0021] Figure 3 is a flowchart of the microservice optimization method provided in Embodiment 3;

[0022] Figure 4It is a schematic structural diagram of the microservice optimization device provided in the fourth embodiment of the present application;

[0023] Figure 5 It is a schematic structural diagram of an electronic device provided in the fifth embodiment of the present application. Detailed implementation manners

[0024] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present 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 do not have to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances 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 "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products, or devices.

[0026] Embodiment 1

[0027] Figure 1 It is a flowchart of the microservice optimization method provided according to Embodiment 1. This embodiment is applicable to the situation of optimizing the routing strategy and virtual machine initialization configuration of microservices in a microservice architecture. This method can be executed by a microservice optimization device, and the microservice optimization device is implemented in the form of hardware and / or software and can be integrated into an electronic device running this system.

[0028] As Figure 1 shown, the method includes:

[0029] S110. Perform 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 counting elements of the microservice to be optimized.

[0030] S120. Determine the service type of the microservice to be optimized based on the function point counting elements.

[0031] S130. Optimize the routing policy and virtual machine initialization configuration of the microservice to be optimized based on the service type.

[0032] Among them, the microservice to be optimized refers to the microservice whose routing policy and virtual machine initialization configuration need to be optimized. Conducting a functional point analysis on the microservice to be optimized means analyzing the functions that the microservice to be optimized can achieve from the external business perspective of user requirements by measuring the logical view of the microservice to be optimized. Among them, the logical view describes the functional requirements and behaviors of the microservice to be optimized and is the design basis of the program source code. Specific modules in the program source code usually correspond to the functional points in the logical view. The program source code describes the logic and functions of the microservice to be optimized through programming languages, defining the functions, behaviors, and execution methods of the microservice to be optimized. The program source code is used to conduct a functional point analysis on the microservice to be optimized.

[0033] By conducting a functional point analysis on the microservice to be optimized, the functional point counting elements of the microservice to be optimized can be determined. Among them, the functional point counting elements are the core components used to quantify the functions of the microservice to be optimized in the functional point analysis. Optionally, the functional point counting elements include ILF (Internal Logical Files), EIF (External Interface Files), EI (External Inputs), EQ (External Queries), and EO (External Outputs).

[0034] The functional point counting elements have different forms and proportions in different service types. By analyzing the functional point counting elements, the service type of the microservice to be optimized can be determined. Optionally, the service types of the microservice to be optimized include: write-intensive and read-sparse, write-sparse and read-intensive, and external dependencies.

[0035] When the service type of the microservice to be optimized is determined, optimize the routing policy and virtual machine initialization configuration of the microservice to be optimized specifically according to the service type.

[0036] Optimizing the routing policy of the microservice to be optimized 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 the service type and selecting the most suitable routing policy, the stability and reliability of the system can be effectively improved.

[0037] Optimize the virtual machine initialization configuration of the microservice to be optimized based on the service type of the microservice to be optimized. The core lies in dynamically adjusting the virtual machine initialization parameters according to the different requirements of the service type in combination with the hardware configuration information, mainly for the precise matching of service characteristics and hardware resources, aiming to optimize performance, improve resource utilization, and ensure system stability.

[0038] The technical solution of the embodiment of this application analyzes the function points of 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, can accurately identify the core functions and service characteristics of the microservice to be optimized, and thus determines the service type of the microservice to be optimized; by analyzing the core requirements and performance bottlenecks of the service type, selects the most suitable routing strategy; dynamically adjusts the virtual machine initialization parameters according to the different requirements of the service type in combination with the hardware configuration information, realizes the precise matching of service characteristics and hardware resources, and can significantly improve the system stability and reliability and improve resource utilization.

[0039] In an optional embodiment, before analyzing the function points of the microservice to be optimized based on the program source code of the microservice to be optimized, the method further includes: obtaining the class path directory and source code directory of the microservice to be optimized, and obtaining the class files under the class path directory based on the class path directory; generating the source code path of the microservice to be optimized based on the metadata of the class files and the source code directory; obtaining the program source code of the microservice to be optimized based on the source code path.

[0040] Among them, the class path directory (calsspath, cph) is used to specify the path that the virtual machine should search when loading class files. The source code directory (source directory, src) is used to store the source code files of the microservice to be optimized. Class files are usually stored in the class path directory, and class files are the basis for the virtual machine to run. When the class path directory is determined, obtain the class files stored in the class path directory.

[0041] When the class files are determined, obtain the metadata of the class files. The metadata of the class files is data used to describe the information of the class itself. Optionally, the metadata of the class files includes: package name, class name, class annotation, method name, and method annotation.

[0042] Optionally, generate the source code path of the microservice to be optimized based on the source code path, the package name, and the class name of the class files. Among them, the source code path is the key directory for storing source code files, usually organized according to the 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 acquiring the program source code of the microservice to be optimized, providing data support and technical support for the function point analysis of the microservice to be optimized based on the program source code.

[0044] Embodiment 2

[0045] Figure 2 It is a flowchart of the microservice optimization method provided according to Embodiment 2. This embodiment is further optimized on the basis of the above embodiment.

[0046] As Figure 2 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] Among them, a method unit is the basic unit that implements a specific function in the program source code. The program source code includes at least two method units. The method units are obtained by performing method segmentation on the program source code of the microservice to be optimized.

[0049] S220. Based on the key identifiers in the method units, determine the function types corresponding to the method units in the function point analysis.

[0050] Among them, the key identifier is used to identify the starting point of the function logic of the method unit and define the function type of the method unit. Based on the key identifier, the function types corresponding to the method units in the function point analysis can be determined.

[0051] Optionally, the function types include transaction functions and data functions. Exemplarily, the key identifiers can be Action, Controller, and @RestController, etc. Action generally corresponds to transaction functions, and Controller and @RestController correspond to both data functions and transaction functions.

[0052] S230. Based on the function types and the operation content of the method units, perform function point analysis on the microservice to be optimized to determine the function point counting elements of the microservice to be optimized.

[0053] The method units usually implement the complete business logic and data operations through the service layer and the data access layer (Data Access Layer, DAL). Optionally, perform layer-by-layer penetration on the associated service layer and data access layer in the method units, and perform function point analysis on the service layer and the data access layer during the entire penetration process to determine the function point counting elements of the microservice to be optimized.

[0054] S240. Determine the service type of the microservice to be optimized based on the function point counting elements.

[0055] S250. Optimize the routing policy and virtual machine initialization configuration of the microservice to be optimized based on the service type.

[0056] The technical solution of the embodiment of the present application divides the program source code of the microservice to be optimized to obtain at least two method units. Based on the key identifiers in the method units, determine the function types corresponding to the method units in the function point analysis. Based on the function types and the operation contents of the method units, perform function point analysis 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 subsequent determination of the service type of the optimized microservice based on the function point counting elements.

[0057] In an optional embodiment, 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 the function point counting elements 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, determine the number of external interface file processing times based on the number of file path creations; if the function type is a data function and the method unit includes a database access operation, determine the number of internal logical file processing times based on the access times to the structured database and unstructured database in the method unit; if the function type is a transaction function and the method unit includes an external event instruction processing operation, determine 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 the server or memory, determine the number of external queries based on the data acquisition times; if the function type is a transaction function and the method unit includes a data submission operation to the server, determine the number of external outputs based on the data submission times; determine the function point counting elements of the microservice to be optimized based on the number of external interface file processing times, the number of internal logical file processing times, the number of external inputs, the number of external queries, and the number of external outputs.

[0058] The function point counting elements belonging to the data function include ILF and EIF, and those belonging to the transaction function include EI, EQ, and EO.

[0059] When the function type is a data function and the method unit includes the use of the API of the file package, it indicates that the method unit includes a file path creation operation. Count the number of file path creations to determine the number of external interface file (EIF) processing times.

[0060] The function type is a data function and the method unit includes database access operations. Optionally, the database access operations include operations for adding, deleting, modifying, and querying structured or unstructured databases. Count the number of accesses to structured and unstructured databases and 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, then determine the number of external inputs (EI) based on the number of calls to message middleware APIs 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 data acquisition operations for a server or memory, such as calling code for redis and including http get requests, then determine the number of external queries (EQ) based on the number of data acquisitions.

[0063] If the function type is a transaction function and the method unit includes data submission operations for a server, such as calling code including http post requests, then determine the number of external outputs (EO) based on the number of data submissions.

[0064] Based on the number of external interface file processing times, internal logical file processing times, external input times, external query times, and external output times, determine the function point counting elements of the microservice to be optimized.

[0065] The above technical solution provides a practical function point counting element determination solution, providing data support and technical support for subsequent determination of the service type of the optimized microservice based on the function point counting elements.

[0066] Embodiment III

[0067] Figure 3 is a flowchart of the microservice optimization method provided in Embodiment III. This embodiment is further optimized on the basis of the above embodiment.

[0068] As Figure 3 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 the function point counting elements of the microservice to be optimized.

[0070] S320. Based on the function point counting elements, determine the read / write mode and dependency type respectively.

[0071] Optionally, the function point counting elements include: ILF, EIF, EI, EQ, and EO. The read-write model and dependency type can be determined based on the quantity distribution of various function point counting elements.

[0072] S330. Determine the service type of the to-be-optimized microservice based on the read-write mode and dependency type.

[0073] Optionally, the service types of the to-be-optimized microservices include: more reads than writes, more writes than reads, and external dependencies. The read-write ratio can be determined based on the read-write mode, and the degree of dependence on external systems can be determined based on the dependency type.

[0074] If the proportion of read operations is higher than that of write operations, determine the service type of the to-be-optimized microservice as more reads than writes; if the proportion of write operations in the read-write mode is higher than that of read operations, determine the service type of the to-be-optimized microservice as more writes than reads. If the degree of dependence on external systems is high, determine the service type of the to-be-optimized microservice as external dependencies.

[0075] S340. Optimize the routing strategy and virtual machine initialization configuration of the to-be-optimized microservice based on the service type.

[0076] The technical solution of the embodiment of the present application analyzes the function points of the to-be-optimized microservice based on the program source code of the to-be-optimized microservice to determine the function point counting elements of the to-be-optimized microservice. Based on the function point counting elements, the read-write mode and dependency type are respectively determined. Based on the read-write mode and dependency type, the service type of the to-be-optimized microservice is determined, providing a practical service type determination scheme, analyzing the core requirements and performance bottlenecks of the service type for subsequent selection of the most suitable routing strategy; dynamically adjusting the virtual machine initialization parameters according to the different requirements of the service type in combination with the hardware configuration information to achieve the precise matching of service characteristics and hardware resources, providing technical support and data support.

[0077] In an optional embodiment, the determining the service type of the to-be-optimized microservice based on the read-write mode and dependency type includes: if the number of external queries is greater than the first preset ratio of the sum of the number of external interface file processing times, internal logical file processing times, external input times, and external output times, determine the service type of the to-be-optimized microservice as more reads than writes; if the sum of the external input times and the internal logical file processing times is greater than the second preset ratio of the sum of the number of external queries, external interface file processing times, and external output times, determine the service type of the to-be-optimized microservice as more writes than reads; if the sum of the external output times and the external interface file processing times is greater than the third preset ratio of the sum of the number of external queries, external input times, and internal logical file processing times, then determine the service type of the to-be-optimized microservice as external dependencies.

[0078] The main function of EQ (External Query) is to read data from memory or servers, without involving data modification or complex calculations. If the number of EQs is significantly higher than the first preset ratio of the sum of the numbers of EI, EO, ILF, and EIF, it indicates that the main function of the microservice to be optimized is data query, and it is more inclined to obtain information rather than modify data. It is determined that the service type of the microservice to be optimized is read-heavy and write-light. Among them, the first preset ratio is determined according to the actual business requirements, and its specific value is not limited here. Exemplarily, the first preset ratio is 70%.

[0079] EI (External Input) involves calling the message middleware to input data or send instructions to the system, and ILF (Internal Logical File) is the data that needs to be maintained within the system, supporting operations such as adding, deleting, modifying, and querying structured or unstructured databases. If the sum of the numbers of EI and ILF is higher than the second preset ratio of the sum of the numbers of EIF, EQ, and EO, it indicates that the main function of the microservice to be optimized is data maintenance and update. It is determined that the service type of the microservice to be optimized is write-heavy and read-light. Among them, the second preset ratio is determined according to the actual business requirements, and its specific value is not limited here. Exemplarily, the second preset ratio is 60%.

[0080] EO (External Output) involves operations of submitting data to the server; EIF (External Interface File) involves operations of creating file paths. If the sum of the numbers of EO and EIF is greater than the third preset ratio of the sum of EQ, EI, and ILF, it indicates that the microservice to be optimized has a strong dependence on external data or external systems. It is determined that the service type of the microservice to be optimized is external dependence. Among them, the third preset ratio is determined according to the actual business requirements, and its specific value is not limited here. Exemplarily, the third preset ratio is 40%.

[0081] The above technical solution provides a practical and reliable service type determination solution, determines the read-write mode and dependence type of the microservice to be optimized according to the quantity distribution of various functional point counting elements, and then determines the service type of the microservice to be optimized, providing 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, optimizing the virtual machine initialization configuration of the microservice to be optimized based on the service type includes: when the microservice to be optimized starts, obtaining the hardware configuration information of the server; if the service type of the microservice to be optimized is write-heavy and read-light or external dependence, 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-heavy and write-light, determining the number of service instances, virtual machine memory, and garbage collection type based on the memory size in the hardware configuration information.

[0083] Among them, the hardware configuration information of the server at least includes: the number of central processing unit (CPU) cores and the memory size. After obtaining the hardware configuration information, initializing the virtual machine configuration according to the service type of the microservice to be optimized can improve the adaptability of the microservice to be optimized to the business requirements.

[0084] Write more and read less involves a large number of write operations. The external dependency type needs to frequently call external services and requires high CPU processing power and efficient concurrent processing capabilities. Set the number of virtual machine threads according to the number of CPU cores. Optionally, if the number of CPU cores is 4, set the number of virtual machine threads to 2000. If the number of CPU cores is greater than 4, determine the number of virtual machine threads based on 4 cores as the benchmark. Allocating the number of virtual machine threads based on the number of CPU cores can avoid waste or overload of CPU resources, ensure that write operations and external calls can be processed efficiently, and improve the system response speed.

[0085] Read more and write less involves a large number of read operations and requires a high 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 equally divide it with a memory not greater 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. This 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 caused by insufficient memory.

[0086] The above technical solution can dynamically adjust the virtual machine initialization configuration according to the service type of the microservice to be optimized, maximize hardware utilization, and improve the stability and reliability of the system.

[0087] In an optional embodiment, optimize the routing policy of the microservice to be optimized based on the service type, including: if the service type of the microservice to be optimized is an external dependency, use the weighted sum of response time and the minimum connection as the routing policy of the microservice to be optimized; if the service type of the microservice to be optimized is write more and read less, use the polling policy as the routing policy of the microservice to be optimized; if the service type of the microservice to be optimized is read more and write less, use the random policy as the routing policy of the microservice to be optimized.

[0088] The microservices to be optimized with the service type of external dependency focus on the dynamic adjustment of response time and connection count. The microservices to be optimized with the service type of more writes than reads focus on load balancing. The microservices to be optimized with the service type of more reads than writes focus on resource utilization and hot spot issues.

[0089] In the case where the service type is external dependency, using response time weighting as the routing strategy for the microservices to be optimized can dynamically allocate weights based on the response time of microservice instances. The microservice instance with a shorter response time will receive more requests. Using the minimum connection as the routing strategy can distribute requests to the microservice instance with the fewest current connections, ensuring load balancing. This can optimize the response time because external dependencies usually involve calling third-party services and the response time may be unstable. Response time weighting can preferentially select microservice instances with fast responses, enhancing the user experience. It can also prevent some microservice instances from becoming performance bottlenecks due to excessive connection counts, ensuring system stability.

[0090] In the case where the service type is more writes than reads, using the polling strategy as the routing strategy for the microservices to be optimized can distribute requests to all available microservice instances in sequence, ensuring that each microservice instance evenly shares the load. This is because more writes than reads usually involve a large number of write operations, and the polling strategy can evenly distribute requests, avoiding performance degradation of some microservice instances due to excessive write pressure.

[0091] In the case where the service type is more reads than writes, using the random strategy as the routing strategy for the microservices to be optimized can randomly distribute requests to available microservice instances, ensuring that each microservice instance has the same probability of processing requests. This is because more reads than writes usually involve a large number of read operations, and the random strategy can avoid some instances becoming hot spots due to frequent reads, improving the overall performance. The random strategy can make full use of the resources of all microservice instances and avoid some instances being idle.

[0092] In an optional embodiment, define a project management plugin and set the running trigger mode of the project management plugin. Then, configure the project management plugin in the project management configuration of the microservices to be optimized. Optionally, set the running trigger mode of the project management plugin to run the project management plugin in response to detecting a code packaging operation for the microservices to be optimized. Exemplarily, the type of the project management plugin can be a Maven plugin, and use maven-NGC-plugin to identify the project management plugin. When detecting code packaging operations such as deploy and install for the microservices to be optimized, run maven-NGC-plugin.

[0093] During the operation of the maven-NGC-plugin, a code metric container is created for the microservice to be optimized through the maven-NGC-plugin. Among them, the code metric container includes an eigenvalue area and a counting area. During the operation of the maven-NGC-plugin, class files under the classpath directory are obtained, and the class files under the class directory path are loaded and iterated to obtain metadata of the class files such as package names, class names, class annotations, method names, method annotations, etc., and the metadata of the class files is stored in the eigenvalue area of the code metric container. Based on the metadata of the class files and the source code directory, the 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 split by methods, and the obtained method units are stored in the eigenvalue area of the code metric container.

[0094] Then, key identifiers are extracted from the method units in the eigenvalue area, and the obtained key identifiers are stored in the counting 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 counting elements of the microservice to be optimized. Among them, the function point counting elements include ILF, EIF, EI, EQ, and EO. The function point counting elements corresponding to the key identifiers are summarized, and the service type of the microservice to be optimized is determined based on the function point counting elements.

[0095] In the above technical solution, by defining a project management plugin, a code metric container is created for the microservice to be optimized through the project management plugin. The metadata of the class files and the method units obtained by splitting the program source code are stored in the eigenvalue area of the code metric container, and the key identifiers are stored in the counting area of the code metric container. A practical solution is provided for determining the service type of the microservice to be optimized.

[0096] Example 4

[0097] Figure 4 FIG. 13 is a schematic structural diagram of a microservice optimization device provided in Example 4 of the present application. This embodiment is applicable to the situation of optimizing the routing strategy and virtual machine initialization configuration of microservices 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] As Figure 4 shown, the device may include:

[0099] A function point counting element determination module 410, configured to perform 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 counting elements of the microservice to be optimized;

[0100] A service type determination module 420, configured to determine the service type of the microservice to be optimized based on the function point counting elements;

[0101] A microservice optimization module 430, configured to optimize the routing policy 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, can accurately identify the core functions and service characteristics of the microservice to be optimized, and thus determines the service type of the microservice to be optimized; by analyzing the core requirements and performance bottlenecks of the service type, selects the most suitable routing policy; dynamically adjusts the virtual machine initialization parameters according to the different requirements of the service type in combination with the hardware configuration information, realizes the precise matching of service characteristics and hardware resources, and can significantly improve the system stability, reliability and resource utilization rate.

[0103] Optionally, the function point counting element determination module 410 includes: a method segmentation sub-module, configured to segment the program source code of the microservice to be optimized to obtain at least two method units; a function type determination sub-module, configured to determine the function type corresponding to the method unit in the function point analysis based on the key identifiers in the method unit; a function point counting element determination sub-module, configured 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 counting elements of the microservice to be optimized.

[0104] Optionally, the function point counting element determination sub-module includes: an external interface file processing times determination unit, configured to, if the function type is a data function and the method unit includes a file path creation operation, determine the external interface file processing times based on the number of file path creations; an internal logic file processing times determination unit, configured to, if the function type is a data function and the method unit includes a database access operation, determine the internal logic file processing times based on the number of accesses to structured and unstructured databases in the method unit; an external input times determination unit, configured to, if the function type is a transaction function and the method unit includes an external event instruction processing operation, determine the external input times based on the number of calls to the message middleware in the method unit; an external query times determination unit, configured to, if the function type is a transaction function and the method unit includes a data acquisition operation on a server or in memory, determine the external query times based on the data acquisition times; an external output times determination unit, configured to, if the function type is a transaction function and the method unit includes a data submission operation to a server, determine the external output times based on the data submission times; a function point counting element determination unit, configured to determine the function point counting element of the to-be-optimized microservice 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.

[0105] Optionally, the service type determination module 420 includes: a function ratio determination sub-module, configured to respectively determine a read-write mode and a dependency type based on the function point counting element; a service type determination sub-module, configured to determine the service type of the to-be-optimized microservice based on the read-write mode and the dependency type.

[0106] Optionally, the service type determination sub-module includes: a first service type determination unit, configured to determine that the service type of the to-be-optimized microservice is read-heavy write-light if the external query times are greater than a first preset ratio of the sum of the external interface file processing times, the internal logic file processing times, the external input times, and the external output times; a second service type determination unit, configured to determine that the service type of the to-be-optimized microservice is write-heavy read-light 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; a third service type determination unit, configured to determine that the service type of the to-be-optimized microservice is externally dependent 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.

[0107] Optionally, the microservice optimization module includes: a first routing policy determination sub-module, configured to, if the service type of the microservice to be optimized is an external dependency, use the minimum connection of the weighted sum of response times as the routing policy of the microservice to be optimized; a second routing policy determination sub-module, configured to, if the service type of the microservice to be optimized is write-intensive and read-sparse, use the polling policy as the routing policy of the microservice to be optimized; a third routing policy determination sub-module, configured to, if the service type of the microservice to be optimized is read-intensive and write-sparse, use the random policy as the routing policy of the microservice to be optimized.

[0108] Optionally, the microservice optimization module includes: a hardware configuration acquisition sub-module, configured to acquire the hardware configuration information of the server when the microservice to be optimized is started; a first virtual machine initialization configuration determination sub-module, configured to, if the service type of the microservice to be optimized is write-intensive and read-sparse or an external dependency, determine the number of virtual machine threads based on the number of central processing unit cores in the hardware configuration information; a second virtual machine initialization configuration determination sub-module, configured to, if the service type of the microservice to be optimized is read-intensive and write-sparse, determine the number of service instances, the virtual machine memory, and the garbage collection type based on the memory size in the hardware configuration information.

[0109] Optionally, the apparatus further includes: a class file acquisition module, configured to acquire the class path directory and the 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 acquire the class files under the class path directory based on the class path directory; a source code path generation module, configured to generate the source code path of the microservice to be optimized based on the metadata of the class files and the source code directory; a source code acquisition module, configured to acquire the program source code of the microservice to be optimized based on the source code path.

[0110] The microservice optimization apparatus provided by the embodiments of the invention can execute the microservice optimization method provided by any embodiment of the present application, and has the corresponding performance modules and beneficial effects for executing the microservice optimization method.

[0111] Embodiment Five

[0112] According to the 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 schematic structural diagram of an electronic device 510 of an embodiment that can be used for implementation is shown. The electronic device 510 includes at least one processor 511 and a memory communicatively connected to the at least one processor 511, such as a read-only memory (ROM) 512, a random access memory (RAM) 513, etc. Among them, the memory stores a computer program executable by the at least one processor. The processor 511 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 512 or the computer program loaded from the storage unit 518 into the random access memory (RAM) 513. In the RAM 513, various programs and data required for the operation of the electronic device 510 can also be stored. The processor 511, the ROM 512, and the RAM 513 are connected to each other through a bus 514. The 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 disc, 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 through a computer network such as the Internet and / or various telecommunication networks.

[0115] The processor 511 can be various general and / or special processing components with processing and computing capabilities. Some examples of the processor 511 include but are not limited to a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The 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, which is tangibly contained in a computer-readable storage medium, such as the storage unit 518. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 510 via the ROM 512 and / or the communication unit 519. When the computer program is loaded into the RAM 513 and executed by the processor 511, one or more steps of the microservice optimization method described above can be executed. Alternatively, in other embodiments, the processor 511 can be configured to execute the microservice optimization method in any other appropriate manner (for example, by means of firmware).

[0117] The various embodiments of the systems and techniques described above in this specification can be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGA), application specific integrated circuits (ASIC), application specific standard products (ASSP), systems-on-chip (SOC), complex programmable logic devices (CPLD), 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 interpretable on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor that receives data and instructions from, and transmits data and instructions to, a storage system, at least one input device, and at least one output device.

[0118] The computer programs for implementing the methods of this 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, special purpose computer, or other programmable micro-service optimization device so that the computer programs, when executed by the processor, cause the functions / operations specified in the flowchart and / or block diagram to be implemented. The computer programs can be executed entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine, or entirely on the remote machine or server.

[0119] In the context of this application, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, the computer-readable storage medium can be a machine-readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, 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 disc 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 having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and a pointing device (e.g., a mouse or a trackball) through which the user can provide input to the electronic device. Other kinds 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 including backend components (e.g., as a microservice optimization server), or a computing system including middleware components (e.g., an application server), or a computing system including frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system including any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected to each other by digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include: local area network (LAN), wide area network (WAN), blockchain network, and the Internet.

[0122] The computing system can include a client and a server. The client and the server are generally far from each other and typically interact through a communication network. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system and solves the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS services.

[0123] The embodiments of the present application also disclose a computer program product, which includes a computer program that, when executed by a processor, implements the microservice optimization method provided in any embodiment of the present application. This program product belongs to the same inventive concept as the microservice optimization methods disclosed in the embodiments of the present application, and thus will not be elaborated herein.

[0124] It should be understood that various forms of the processes shown above can be used, with steps reordered, added, or deleted. For example, the steps recited in the present application can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present application can be achieved, and no limitation is made herein.

[0125] The above specific embodiments do not constitute a limitation on the protection scope of the present application. Those skilled in the art should understand that various modifications, combinations, sub - combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principle of the present application shall be included within the protection scope of the present application.

Claims

1. A microservice optimization method, characterized in that, The method includes: 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 counting elements of the microservice to be optimized; Determining the service type of the microservice to be optimized based on the function point counting elements; Optimizing the routing strategy and virtual machine initialization configuration of the microservice to be optimized based on the service type.

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 counting elements of the microservice to be optimized includes: Splitting the program source code of the microservice to be optimized to obtain at least two method units; Determining the function type corresponding to the method unit in function point analysis based on the key identifiers in the method unit; 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 the function point counting elements of the microservice to be optimized.

3. The method according to claim 2, wherein 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 the function point counting elements of the microservice to be optimized includes: If the function type is a data function and the method unit includes an operation for creating a file path, determining the number of external interface file processing times based on the number of times of creating the file path; If the function type is a data function and the method unit includes an operation for accessing a database, 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 an operation for processing an external event instruction, determining the number of external input times 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 an operation for obtaining data from a server or memory, determining the number of external query times based on the number of data acquisition times; If the function type is a transaction function and the method unit includes an operation for submitting data to a server, determining the number of external output times based on the number of data submission times; Determining the function point counting elements of the microservice to be optimized based on the number of external interface file processing times, the number of internal logical file processing times, the number of external input times, the number of external query times, and the number of external output times.

4. The method according to claim 1, characterized in that, The determining the service type of the microservice to be optimized based on the function point counting elements includes: Respectively determining the read-write mode and the dependency type based on the function point counting elements; Determining the service type of the microservice to be optimized based on the read-write mode and the dependency type.

5. The method according to claim 4, characterized in that The determining the service type of the microservice to be optimized based on the read-write mode and the dependency type includes: If the number of external query times is greater than the first preset ratio of the sum of the number of external interface file processing times, the number of internal logical file processing times, the number of external input times, and the number of external output times, determining that the service type of the microservice to be optimized is read more and written less; 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 query times, the number of external interface file processing times, and the number of external output times, determine that the service type of the microservice to be optimized is write-intensive and read-sparse; If the sum of the number of external output times and the number of external interface file processing times is greater than a third preset ratio of the sum of the number of external query times, the number of external input times, and the number of internal logic file processing times, then determine that the service type of the microservice to be optimized is externally dependent.

6. The method according to claim 1, wherein Based on the service type, optimize the routing policy of the microservice to be optimized, including: If the service type of the microservice to be optimized is externally dependent, then use the weighted sum of response time and the minimum connection as the routing policy of the microservice to be optimized; If the service type of the microservice to be optimized is write-intensive and read-sparse, then use the polling policy as the routing policy of the microservice to be optimized; If the service type of the microservice to be optimized is read-intensive and write-sparse, then use the random policy as the routing policy of the microservice to be optimized.

7. The method according to claim 1, wherein Based on the service type, optimize the virtual machine initialization configuration of the microservice to be optimized, including: When the microservice to be optimized starts, obtain the hardware configuration information of the server; If the service type of the microservice to be optimized is write-intensive and read-sparse or externally dependent, 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 read-intensive and write-sparse, determine the number of service instances, the virtual machine memory, and the garbage collection type based on the memory size in the hardware configuration information.

8. 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 the 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 the source code path of the microservice to be optimized based on the metadata of the class files and the source code directory; Obtain the program source code of the microservice to be optimized based on the source code path.

9. A microservice optimization device, characterized in that, The device includes: A function point counting 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 to determine the function point counting elements 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 counting elements; A microservice optimization module, configured to optimize the routing policy and the virtual machine initialization configuration of the microservice to be optimized based on the service type.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the microservice optimization method according to any one of claims 1-8.

11. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the microservice optimization method according to any one of claims 1-8.

Citation Information

Patent Citations

  • Micro-service dynamic scaling and migration method and device

    CN112988398A

  • Route selection method, network equipment and computer readable medium

    CN116684493A

  • Software scale measurement method and system based on NLP

    CN117055842A

  • Node scheduling method, device and equipment based on network element micro-service, medium and product

    CN118803066A

  • System and method for optimized generation of microservices

    US20240192932A1