A method for measuring coupling degree of microservices based on clustering algorithm
By using a clustering-based microservice coupling evaluation method, an upgrade matrix and coupling vector are generated. The K-means algorithm is then used to classify microservices, solving the problem of lagging evaluation of microservice coupling relationships in ultra-large platforms and achieving efficient and continuous architecture optimization and governance.
Patent Information
- Application Number
- CN202411847422.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2044-12-16
AI Technical Summary
Existing technologies struggle to quickly and timely assess and manage the coupling relationships among hundreds or even thousands of microservices in ultra-large distributed digital platforms, leading to delays in architecture assessment and impacting system stability and rapid iteration.
A clustering-based approach is adopted, which generates a microservice upgrade matrix, calculates the coupling degree vector, classifies microservices using the K-means clustering algorithm, and sets a coupling degree threshold to measure and manage the coupling degree of microservices.
It enables efficient and continuous evaluation and optimization of microservice architecture, reduces coupling, improves system stability and flexibility, and supports rapid iteration.
Smart Images

Figure CN119806999B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of software system architecture design, and particularly relates to a method for measuring microservice coupling degree based on a clustering algorithm. BACKGROUND
[0002] With the rapid development and wide application of cloud computing, especially cloud native technologies represented by microservices, containerization and DevOps, digital platforms are becoming larger and larger, showing characteristics of super-large, distributed, high reliability, rapid iteration, etc. At the same time, software system architecture is becoming more and more complex. The service-oriented concept has become the main design pattern of modern digital applications and platforms. Although the main goal of microservices is high decoupling, there are still various coupling relationships between microservices, such as communication coupling, data coupling, service dependency, etc. For super-large digital platforms and software systems, the number of microservices is increasing, and with the development of business, microservices are also rapidly iterating and changing, and the relationship between microservices is complex, which brings great risks to the stable operation of the system.
[0003] The high cohesion and low coupling principle of software module design is embodied in the cloud native field, and the industry has proposed many methods in architecture governance and service governance, such as service registration and discovery, unified communication protocol (RESTful API, etc.) and data format (JSON, etc.), middleware (message middleware, etc.), and technical strategies such as dependency analysis (combing the relationship between modules. Through dependency graph, show which modules depend on other modules, and the strength and direction of the dependency), code analysis (use static code analysis tools to detect dependencies and coupling degree in the code), and symbiotic analysis (analyze the symbiotic type in the code, which can evaluate the coupling degree between modules). However, these technical strategies and analysis methods require in-depth research on the code, or a clear understanding of the full link and dependency relationship of each function, and the implementation cost and complexity are high.
[0004] For large software systems composed of hundreds or even thousands of microservices, and there are multiple versions and multiple distributed clusters of microservices, and there are many complex situations such as independent research and development and cooperation introduction of microservices, how to measure and evaluate the relationship between microservices from the whole or macroscopic, including which microservices have high coupling, which microservices have low coupling, which microservices have closer relationship and which microservices have more distant relationship, how to better evaluate and promote the governance of large-scale microservices through regular measurement, so as to maintain a large software system while maintaining rapid and flexible iteration, is a key problem faced by the evolution and development of software architecture of super-large distributed digital platforms.
[0005] For a super large digital platform such as a video network with hundreds or even thousands of microservices, there is currently a lack of rapid and timely architecture evaluation methods, and architecture evaluation is only performed when a failure or architecture audit occurs, and the lagging evaluation method leads to an increase in entropy or corruption of the software architecture, and the challenges of measuring and governing large-scale microservices in the software architecture of a super large distributed digital platform need to be addressed. SUMMARY
[0006] In view of the deficiencies of the prior art, the purpose of the present application is to provide a method for measuring the coupling degree of microservices based on a clustering algorithm, which realizes efficient and continuous evaluation of microservice architecture.
[0007] The present application provides a method for measuring the coupling degree of microservices based on a clustering algorithm, comprising:
[0008] S1, obtaining the microservice upgrade situation in the statistical period, and generating a microservice upgrade matrix;
[0009] S2, forming a microservice coupling degree vector according to the microservice upgrade matrix, comprising: for the upgrade data of each microservice, using a weighted statistical method to respectively calculate the coupling degree of the microservice with itself and other microservices, and constructing the coupling degree vector of the microservice with the calculated coupling degrees; and the coupling graph vectors of all microservices constitute a microservice coupling degree matrix;
[0010] S3, using the microservice coupling degree matrix as data, using a clustering algorithm to perform clustering operation on the data in the microservice coupling degree matrix, and classifying each microservice according to the coupling degree between the microservices;
[0011] S4, measuring the microservice coupling degree, and according to the measurement result of the microservice coupling degree, taking corresponding service governance methods to analyze and improve the microservices.
[0012] Further, in S1, the update and upgrade situation of each microservice in the statistical period is counted, and a list of all microservices is obtained; the number corresponding to each upgrade of each microservice and the number of microservices upgraded simultaneously is added by 1 to form a microservice upgrade matrix.
[0013] Further, in S2, the coupling degree of each microservice with itself is 1.
[0014] Further, in S2, the calculation method of the coupling degree of microservice i and microservice j is:
[0015] The coupling degree of microservice i and microservice j = (G i,j + G j,i ) / (G i + G j );
[0016] Wherein, Gi,j the number of times of upgrading microservice i when microservice j is upgraded; G j,i the number of times of upgrading microservice j when microservice i is upgraded; G i the number of times of upgrading microservice i; G j the number of times of upgrading microservice j; i and j are serial numbers of microservices.
[0017] Further, in S3, for each microservice, the coupling degree between the microservice and other microservices in the same category is high, and the coupling degree between the microservice and microservices in different categories is low.
[0018] Further, in S3, a K-means clustering algorithm is used to perform clustering operation on all microservices.
[0019] Further, in S4, the coupling degree of the microservice is measured, including: setting a coupling degree threshold, and regarding a microservice greater than or equal to the coupling degree threshold as a tightly coupled microservice.
[0020] Further, in S4, the coupling degree of the microservice is measured, including: after obtaining the clustering operation result of the microservice, designing an architecture layer and a domain division mode according to the classification of the microservice by the clustering algorithm.
[0021] Further, in S4, the service governance method includes: a technical strategy, dependency analysis, and code analysis.
[0022] Further, in S4, the coupling degree of the microservice is periodically evaluated to determine whether optimization or reduction is needed, and the microservice is governed according to the evaluation result.
[0023] The present application has the following advantages:
[0024] (1) The present application is based on the coupling degree value of the microservice and the clustering label of the microservice, and then uses the current service governance method to optimize the microservice, reduce the coupling degree between the microservices, or enhance the cohesion of the same type of microservice.
[0025] (2) After each upgrade, the method of the present application can be used to iteratively realize rapid evaluation, providing a feasible and effective method for efficient and continuous evaluation of the architecture.
[0026] (3) The method of the present application plays an important role in the microservice governance capability and continuous optimization of the architecture of the whole system of the video interconnection. BRIEF DESCRIPTION OF DRAWINGS
[0027] The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and together with the description serve to explain the principles of the application. In the drawings:
[0028] Figure 1 A flow chart of a method for measuring the coupling degree of microservices based on a clustering algorithm according to an embodiment of the application;
[0029] Figure 2 A schematic diagram of a microservice upgrade matrix according to an embodiment of the application;
[0030] Figure 3 A schematic diagram of a microservice coupling degree matrix according to an embodiment of the application;
[0031] Figure 4 A schematic diagram of a microservice coupling degree measurement principle according to an embodiment of the application. DETAILED DESCRIPTION
[0032] In order to make the personnel in the art better understand the technical solutions in the embodiments of the application, the technical solutions of the application will be described clearly and completely in conjunction with the drawings below. Obviously, the described embodiments are part of the embodiments of the application, rather than all the embodiments. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the application. Based on the embodiments of the application, all other embodiments obtained by those of ordinary skill in the art without creative labor should fall within the scope of the application.
[0033] In addition, in the following description, the description of well-known structures and techniques is omitted to avoid unnecessary confusion of the concepts disclosed in the application.
[0034] In the description of the present application, it should be noted that, unless otherwise explicitly specified and limited, the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer" and the like indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the devices or elements referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation on the present application. In addition, the terms "first", "second", "third" are only for descriptive purposes and cannot be understood as indicating or implying relative importance. The terms "mounting", "connection", "connection" should be broadly understood, for example, it can be fixed connection, or detachable connection, or integrally connected; it can be mechanical connection, or electrical connection; it can be directly connected, or indirectly connected through an intermediate medium, or the communication between two elements. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.
[0035] The exemplary embodiments will be described in detail herein, with examples shown in the drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Rather, they are merely examples of methods and systems consistent with some aspects of the present application as detailed in the appended claims.
[0036] The following describes the technical terms related to the present application:
[0037] Software architecture: refers to the top-level structure design and organization of a software system, which defines the main components of the software system, the relationship between the components, the interaction between the components and the environment, and the principles and guidelines guiding these designs and interactions.
[0038] Microservices: a software architecture design pattern that breaks down large applications into a series of small, autonomous service units that can be independently developed, deployed, scaled and maintained, with services communicating with each other through lightweight communication mechanisms. The core idea of microservices architecture is to decouple the functionality of an application so that each service focuses on completing a specific business function or task.
[0039] Coupling: high cohesion and low coupling is an important principle in software architecture design, coupling refers to the degree of interdependence between different modules (or components, services). Low coupling means that the dependency relationship between modules is as simple as possible, and each module can be modified, upgraded or replaced relatively independently without causing too much impact on other modules.
[0040] DevOps: Development and Operations, is a collection of culture, practice and tools aimed at improving software quality and service reliability through automating processes, improving team collaboration and accelerating software delivery speed.
[0041] Clustering algorithm: Clustering algorithm is an important field in data mining and machine learning, which aims to divide samples in a dataset into multiple classes or clusters according to certain similarity measurement standards, so that samples in the same cluster are as similar as possible, while samples in different clusters are as different as possible, typical such as K-means algorithm, etc.
[0042] As shown in Figure 1 , the present application proposes a method for measuring the coupling degree of microservices based on clustering algorithm, comprising the following steps:
[0043] S1, obtaining the microservice upgrade situation in the statistical period, generating the microservice upgrade matrix.
[0044] The update and upgrade of each microservice in the statistical period are counted, and a list of all microservices is obtained; each upgrade of each microservice and the number of microservices upgraded simultaneously are added by 1 to form a microservice upgrade matrix.
[0045] Specifically, according to the DevOps process, the update and upgrade of each microservice in the statistical period are counted, and a list of all microservices is obtained; for each microservice, each upgrade and the number of microservices upgraded simultaneously are added by 1 to form a microservice upgrade matrix.
[0046] In the embodiments of the present application, the statistical period can be one year or half a year, which is set by the user as needed.
[0047] The following Figure 2 , taking four microservices as an example to explain the microservice upgrade matrix.
[0048] First, the upgrade of each microservice in the statistical period is counted to form a microservice upgrade matrix.
[0049] Microservice 1 is upgraded 5 times, and microservices 2, 3 and 4 are upgraded 4 times, 5 times and 2 times respectively, represented as (4, 5, 2); 5
[0050] Microservice 2 is upgraded 10 times, and microservices 1, 3 and 4 are upgraded 4 times, 6 times and 4 times respectively, represented as (4, 6, 4); 10
[0051] Microservice 3 is upgraded 8 times, while microservice 1, microservice 2 and microservice 4 are upgraded 5 times, 6 times and 6 times respectively, which is expressed as (5, 6, 8 , 6).
[0052] Microservice 4 is upgraded 6 times, while microservice 1, microservice 2 and microservice 3 are upgraded 2 times, 4 times and 6 times respectively, which is expressed as (2, 4, 6, 6 )
[0053] As shown in the above statistical microservice upgrade matrix. The two values of B1 and A2 mean the number of times that microservice 1 and microservice 2 are upgraded simultaneously, which is equal, so the microservice upgrade matrix is a symmetric matrix based on the diagonal line. Figure 2
[0054] S2, according to the microservice upgrade matrix, forms a microservice coupling degree vector, including: for the upgrade data of each microservice, using a weighted statistical method, the coupling degrees of the microservice with itself and other microservices are calculated respectively, and the calculated coupling degrees form the coupling degree vector of the microservice; the coupling degree vectors of all microservices form a microservice coupling degree matrix.
[0055] In this step, for the upgrade data of each microservice, a simple weighted statistical method is used to calculate the microservice coupling degree value, and the numerical combination of each row forms a high-dimensional vector, and the dimension is the total number of microservices, which is used as a microservice coupling degree vector.
[0056] Specifically, according to the microblog upgrade matrix, the coupling degrees between each microservice are calculated. In order to reduce the influence of different upgrade times of each microservice, the application adopts a simple weighted statistical method. The simple weighted statistical method is used to calculate the microservice coupling degree value, including:
[0057] (1) The coupling degree of each microservice with itself is 1.
[0058] (2) The calculation method of the coupling degree of microservice i and microservice j is:
[0059] The coupling degree of microservice i and microservice j = (G i,j + G j,i ) / (G i + G j )(1)
[0060] Wherein, G i,j is the number of times that microservice j is upgraded when microservice i is upgraded; G j,i is the number of times that microservice i is upgraded when microservice j is upgraded; G i is the number of times that microservice i is upgraded; G j is the number of times that microservice j is upgraded; i and j are the serial numbers of microservices.
[0061] Reference is made below Figure 3 to illustrate the microservice coupling degree vector with 4 microservices as an example.
[0062] Microservice 2 is upgraded 4 times when microservice 1 is upgraded 5 times, and microservice 1 is upgraded 4 times when microservice 2 is upgraded 10 times, so the coupling degree between microservice 1 and microservice 2 is calculated by formula (1) as follows:
[0063] The coupling degree of microservice 1 and microservice 2 = (the number of times microservice 2 is upgraded when microservice 1 is upgraded + the number of times microservice 1 is upgraded when microservice 2 is upgraded) / (the number of times microservice 1 is upgraded + the number of times microservice 2 is upgraded).
[0064] The calculated coupling degree of microservice 1 and microservice 2 = (4+4) / (5+10) = 0.533, rounded to 3 decimal places. Similarly, the coupling degree matrix of all microservices is obtained as shown in Table 1. Figure 3
[0065] The coupling degree vector of microservice 1 is (1.000, 0.533, 0.769, 0.364), the coupling degree vector of microservice 2 is (0.533, 1.000, 0.667, 0.500), the coupling degree vector of microservice 3 is (0.769, 0.667, 1.000, 0.857), and the coupling degree vector of microservice 4 is (0.364, 0.500, 0.857, 1.000), etc.
[0066] S3, using the microservice coupling degree matrix as data, the clustering algorithm is used to cluster the data in the microservice coupling degree matrix, and each microservice is classified according to the coupling degree between microservices.
[0067] For each microservice, the coupling degree between the microservice and other microservices in the same classification is high, and the coupling degree between the microservice and microservices in different classifications is low.
[0068] K-means clustering is the most widely used clustering algorithm due to its simplicity and efficiency. Given a set of data points and the number of clusters K, the K-means algorithm repeatedly divides the data into K clusters according to the distance function, where K is a hyperparameter specified according to the classification requirements. In this step, the K-means algorithm in the scikit-learn library of Python is used to cluster all microservices.
[0069] Using the K-means algorithm, the clustering algorithm is operated on all microservice coupling vectors, the number of classifications is set according to the situation, and the classification corresponding to each microservice is obtained. The coupling degree between microservices in the same classification is tight, and the coupling degree between microservices in different classifications is low.
[0070] Specifically, the Figure 3 The microservice coupling degree matrix in the above is taken as a data set, and the classification K is set to 2, that is, the microservices are divided into two categories. The label output by the K-means is used to output the label of each microservice, and the labels of the microservices with close coupling degrees are the same and are classified into the same category.
[0071] Taking the above four microservices as an example, the output label is [0, 1, 0, 0], that is, microservice 1, microservice 3 and microservice 4 are of the label 0 category, which represents that the coupling degrees among the above microservices are high, and microservice 2 is of the label 1 category, which represents that the coupling degree with the microservice of the label 0 is low.
[0072] S4, the microservice coupling degree is measured, and according to the measurement result of the microservice coupling degree, a corresponding service management method is adopted to analyze and improve the microservice.
[0073] Reference Figure 4 The microservice coupling degree is measured, including two modes: setting a coupling degree threshold and clustering operation.
[0074] (1) Setting a coupling degree threshold
[0075] Specifically, after obtaining the microservice coupling degree matrix, a coupling degree threshold is set, and the microservices greater than or equal to the coupling degree threshold are taken as the tightly coupled microservices.
[0076] It should be noted that the coupling degree threshold ranges from 0 to 1, representing the proportion of the simultaneous upgrade association times of different microservices, and the smaller the value, the lower the coupling degree, and vice versa. Considering factors such as contingency, it is recommended to take a value greater than 0.5, which is set according to the actual upgrade situation in the application, for example, 0.7.
[0077] In the embodiment of the present application, the coupling degree threshold can be 0.7, which can be dynamically adjusted according to the actual situation. The Figure 3 The microservice coupling degree matrix in the above is taken as a data set, and the classification K is set to 2, that is, the microservices are divided into two categories. The label output by the K-means is used to output the label of each microservice, and the labels of the microservices with close coupling degrees are the same and are classified into the same category.
[0078] (2) Clustering operation
[0079] After obtaining the clustering operation result of the microservice, the architecture layer and the field domain mode are designed according to the classification of the microservice by the clustering algorithm. That is, for the category of the microservice K-means, it can be used as an important reference for guiding the architecture layering and field design. The K value of the K-means is taken as the number of layers of the architecture or the number of fields, and the microservices with the same classification value are set in the same layer of the architecture or the same field.
[0080] Specifically, after obtaining the microservice K-means clustering result, the label output value of the clustering algorithm is output. Taking the above four microservices as an example, the output label is [0, 1, 0, 0], which indicates that microservice 1, microservice 3 and microservice 4 are the same class of tight coupling, and therefore in the architecture design, the layered or domain method can be considered to be used, and the microservices with the same label are set in the same layer or the same domain, as an important reference for guiding the architecture domain design.
[0081] According to the coupling degree measurement described above, the corresponding service governance method is adopted to analyze and improve the microservice.
[0082] In the embodiments of the present application, the service governance method includes: technical strategy, dependency analysis and code analysis.
[0083] In addition, the coupling degree of the microservice is periodically evaluated to determine whether it is optimized or reduced, and the microservice is governed according to the evaluation result.
[0084] It should be noted that the more the number of microservice upgrades during the statistics period, the less the accidental influence on the microservices that are upgraded at the same time by chance and indeed have no coupling or dependency relationship. However, the statistical data can be manually processed when it is determined that there is no obvious coupling or dependency relationship.
[0085] In summary, the method for measuring the coupling degree of microservices based on the clustering algorithm of the present application generates a microservice upgrade matrix according to the microservice upgrade recorded by the DevOps process, forms a microservice coupling degree vector according to the matrix, and calculates the microservice coupling degree vector through the K-means clustering algorithm. Based on the coupling degree measurement of the microservice, a feasible and effective method is provided for efficient and continuous evaluation of the microservice architecture.
[0086] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present application, and not to limit them. Although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can modify the technical solutions recorded in the foregoing embodiments, or make equivalent substitutions for some technical features; and these modifications or substitutions do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. Any changes or substitutions that can be easily thought of by those skilled in the art within the technical scope disclosed by the present application should be covered within the protection scope of the present application.
Claims
1. A method for measuring microservice coupling based on clustering algorithm, characterized in that, include: S1, obtain the microservice upgrade status during the statistical period and generate a microservice upgrade matrix; The update and upgrade status of each microservice during the statistical period is statistically analyzed to obtain a list of all microservices. Each upgrade of a microservice is incremented by 1 along with the number of microservices upgraded simultaneously, forming a microservice upgrade matrix; S2, Based on the microservice upgrade matrix, a microservice coupling vector is formed, including: For the upgrade data of each microservice, a weighted statistical method is used to calculate the coupling degree between the microservice and itself and other microservices, and the calculated coupling degrees are used to form the coupling degree vector of the microservice; The coupling graph vectors of all microservices form the microservice coupling matrix. The coupling degree between microservice i and microservice j is calculated as follows: The coupling degree between microservice i and microservice j = (G i,j +G j,i ) / (G i +G j ); Among them, G i,j The number of times microservice j is upgraded when microservice i is upgraded; G j,i The number of times microservice i is upgraded when microservice j is upgraded; G i Number of upgrades for microservices; G j The number of times microservice j has been upgraded; i and j are the sequence numbers of the microservice. S3, using the microservice coupling degree matrix as data combination, a clustering algorithm is used to perform clustering operations on the data in the microservice coupling degree matrix, and each microservice is classified according to the coupling degree between microservices; S4. Measure the coupling degree of microservices, and based on the measurement results, adopt corresponding service governance methods to analyze and improve the microservices; the measurement of microservice coupling degree includes: after obtaining the clustering operation results of microservices, designing architecture layering and domain division methods based on the classification of microservices according to the clustering algorithm.
2. The method for measuring microservice coupling based on clustering algorithm according to claim 1, characterized in that, In S2, each microservice has a coupling degree of 1 with itself.
3. The method for measuring microservice coupling based on clustering algorithm according to claim 1, characterized in that, In S3, for each microservice, the coupling between the microservice and other microservices in the same category is high, while the coupling between the microservice and microservices in different categories is low.
4. The method for measuring microservice coupling based on clustering algorithm according to claim 1, characterized in that, In S3, the K-means clustering algorithm is used to perform clustering operations on all microservices.
5. The method for measuring microservice coupling based on clustering algorithm according to claim 1, characterized in that, In S4, the measurement of microservice coupling also includes: setting a coupling threshold, and classifying microservices that are greater than or equal to the coupling threshold as tightly coupled microservices.
6. The method for measuring microservice coupling based on clustering algorithm according to claim 1, characterized in that, In S4, the service governance methods include: technical strategy, dependency analysis, and code analysis.
7. The method for measuring microservice coupling based on clustering algorithm according to claim 1, characterized in that, In S4, the coupling of microservices is evaluated periodically to determine whether there is any optimization or reduction, and microservices are governed based on the evaluation results.
Citation Information
Patent Citations
Feature extraction method, device and server, and computer readable memory medium
CN109412882A
Micro-service architecture for electric power measurement and implementation method thereof
CN110636108A