Microservice-oriented network flow distribution method
By setting microservice priorities and building a network traffic prediction model, the problem of uneven traffic distribution in existing technologies is solved, enabling intelligent scheduling and timely adjustment of network resources, thereby improving the performance and reliability of microservices.
Patent Information
- Application Number
- CN202411140121.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2024-12-10
AI Technical Summary
Existing traffic allocation strategies fail to fully utilize historical traffic records for intelligent scheduling, lack intelligent and automated traffic prediction and management mechanisms, and cannot make timely adjustments and optimizations based on constantly changing real-time data, resulting in uneven distribution of network resources and affecting the performance and reliability of microservices.
By setting the priority order of microservices, a network traffic prediction model is built, the model is trained using a training dataset, and a network traffic limiting strategy is formulated based on the prediction results, including weight calculation, data preprocessing, and quantum particle swarm optimization algorithm to optimize the limiting strategy.
It enables intelligent scheduling of network broadband resources, which can adjust network traffic in a timely manner, optimize network resource allocation, and improve the response time of microservices and system stability.
Smart Images

Figure CN119109835A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer science and technology, and in particular, relates to a network traffic distribution method for microservices. Background Art
[0002] Microservice architecture decomposes a large monolithic application into multiple small, independent service units, with advantages such as superior maintainability, excellent scalability, high development efficiency, and support for continuous delivery and deployment. However, as the number of services increases, different services may compete for limited network bandwidth, resulting in uneven network resource allocation and extended response time for key services due to insufficient network resources. Unbalanced network bandwidth allocation between services may also affect overall performance. In extreme cases, resource contention may cause some services to fail to operate normally or even cause service interruptions.
[0003] However, the existing traffic allocation strategy fails to make full use of historical traffic records to intelligently schedule network broadband resources, lacks intelligent and automated traffic prediction and management mechanisms, and cannot make timely adjustments and optimize allocations based on constantly changing real-time data.
[0004] Therefore, how to solve the problems existing in the above-mentioned prior art is the focus of current research. Summary of the invention
[0005] The main technical problem solved by the present invention is to provide a network traffic distribution method for microservices, which solves the problems of existing traffic distribution strategies, such as failure to make full use of historical traffic records to intelligently schedule network broadband resources, lack of intelligent and automated traffic prediction and management mechanisms, and inability to make timely adjustments and optimize distribution according to constantly changing real-time data.
[0006] In order to solve the above technical problems, a technical solution adopted by the present invention is to provide a network traffic distribution method for microservices, the method comprising:
[0007] Step 1: Set the priority order of each microservice according to the content of each microservice.
[0008] Step 2: Obtain traffic data and preprocess the traffic data to obtain training data sets and test data sets.
[0009] Step three: construct a network traffic prediction model and use the training data set to train the network traffic prediction model.
[0010] Step 4: Input the test data set into the trained network traffic prediction model to obtain the prediction results.
[0011] Step 5: According to the prediction results and the priority order of each microservice, formulate a corresponding network traffic limiting strategy for each microservice.
[0012] In some embodiments, the priority order of each microservice is set according to the content of each microservice, and the method is: calculate the weight of each microservice; calculate the weight ratio of each microservice according to the weight of each microservice; obtain the priority order of each microservice according to the weight ratio of each microservice.
[0013] In some embodiments, the weight W of each microservice is calculated i , the calculation method is:
[0014] W i =ω F ·F i +ω D ·D i +ω E ·E i ;
[0015] Calculate the weight proportion w of each microservice according to the weight of each microservice i , the calculation method is:
[0016]
[0017] According to the weight proportion of each microservice, the priority order H of each microservice is obtained i , the calculation method is:
[0018] H i =F×W i ×ρ;
[0019] Among them, ω F represents the historical traffic weight F of the i-th microservice i The weight coefficient, ω D Denotes the dependency weight D of the i-th microservice i The weight coefficient, ω E Represents the interaction weight E of the i-th microservice i The weight coefficient, W i represents the weight of the i-th microservice, represents the sum of the weights of all microservices, M represents the total number of microservices, F represents the total traffic that can be allocated by the system, and ρ represents the traffic adjustment factor.
[0020] In some embodiments, traffic data is obtained and preprocessed to obtain a training data set and a test data set, including the steps of:
[0021] The flow data of each link between routers and nodes is obtained according to the packet encapsulation tool to form the original data set.
[0022] The original data set is standardized and format converted to obtain a standard data set.
[0023] The standard data set is split into training data set and test data set.
[0024] In some embodiments, the network traffic prediction model includes an input module, a prediction module, a linear regression module and a current limiting strategy module connected in sequence; the input module is used to input traffic data; the prediction module is used to predict the traffic of each microservice based on the traffic data, and output the initial data to the linear regression module; the linear regression module is used to normalize the initial data to obtain normalized data; the current limiting strategy module formulates a corresponding network traffic limiting strategy based on the normalized data.
[0025] In some embodiments, constructing a network traffic prediction model and using a training data set to train the network traffic prediction model also includes: optimizing the network traffic prediction model.
[0026] In some embodiments, optimizing the network traffic prediction model includes:
[0027] The first step is to randomly initialize the position ψ of each particle in the quantum particle group r , the method is:
[0028]
[0029] Among them, |explore> and |exploit> represent the search state and the exploitation state respectively, and r represents the particle index;
[0030] The second step is to perform quantum rotation gate operation on each particle to obtain the quantum rotation result U θ , the method is:
[0031]
[0032] Where θ represents the rotation angle;
[0033] The third step is to update the position of the particle according to the quantum rotation result, the method is:
[0034] ψ r '=U θ ψ r ;
[0035] Among them, ψ r ' represents the updated position of the particle;
[0036] The fourth step is to update the network parameters of the network traffic prediction model according to the updated particle positions. The method is:
[0037] v'r =ωvr+c1e1(pbest-ψ'r)+c2e2(gbest-ψ'r);
[0039] ψ r ”=ψ r '+v' r ;
[0040] Among them, ω represents the inertia weight, v r represents the velocity of the particle, p best represents the best historical position of the particle, c1 and c2 represent acceleration coefficients, e1 and e2 are random numbers in the interval [0,1], and g best represents the global optimal position in the quantum particle group, v' r represents the updated particle velocity, ψ' r 'Indicates the position of the particle after updating again;
[0041] Step 5: Repeat the above steps to iteratively train the network traffic prediction model until the optimal solution is output.
[0042] In some embodiments, the steps are also included: applying a network traffic limiting strategy to obtain application data; and dynamically adjusting the network traffic limiting strategy based on the application data.
[0043] In some embodiments, before applying the network traffic limiting strategy step, it includes: adding limiting implementation dependency, creating limiting identifier, configuring limiting rate; performing a refresh test on the interface requesting network traffic limiting, and applying the network traffic limiting strategy when the refresh frequency meets the set conditions.
[0044] Beneficial effects: The present application discloses a network traffic allocation method for microservices, wherein the method comprises the following steps: setting the priority order of each microservice according to the content of each microservice; obtaining traffic data, and preprocessing the traffic data to obtain a training data set and a test data set; constructing a network traffic prediction model, and using the training data set to train the network traffic prediction model; inputting the test data set into the trained network traffic prediction model to obtain a prediction result; and formulating a corresponding network traffic limiting strategy for each microservice according to the prediction result and the priority order of each microservice. The method of the present application utilizes traffic data and a network traffic prediction model, and can make timely adjustments to the constantly changing network data, thereby realizing intelligent scheduling of network broadband resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 A flowchart of an embodiment of a microservice-oriented network traffic distribution method of the present application is given;
[0046] Figure 2A schematic diagram of the structure of an embodiment of a network traffic prediction model in this application is given;
[0047] Figure 3 A schematic diagram of the framework of an embodiment of an electronic device of the present application is provided;
[0048] Figure 4 A schematic diagram of a computer-readable storage medium according to an embodiment of the present invention is provided. DETAILED DESCRIPTION
[0049] In order to facilitate the understanding of the present invention, the present invention is described in more detail below in conjunction with the accompanying drawings and specific embodiments. Preferred embodiments of the present invention are provided in the accompanying drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described in this specification. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive.
[0050] It should be noted that, unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used in this specification includes any and all combinations of one or more related listed items.
[0051] It should be noted that the "microservices" referred to in this application are to split an application into multiple services, which can run independently and each service will occupy network resources. "Microservice architecture" refers to the use of multiple microservices to develop a single application, each microservice runs in its own process and uses lightweight mechanisms to communicate; these services are built based on business capabilities and can be independently deployed through automated deployment mechanisms. These services are implemented in different programming languages and different data storage technologies, and maintain minimal centralized management.
[0052] Figure 1 A flowchart of an embodiment of a microservice-oriented network traffic distribution method of the present application is shown, including the steps of:
[0053] Step 1 S1, setting the priority order of each microservice according to the content of each microservice.
[0054] Step 2 S2, obtaining traffic data, and preprocessing the traffic data to obtain a training data set and a test data set.
[0055] Step 3 S3, construct a network traffic prediction model, and use the training data set to train the network traffic prediction model.
[0056] Step 4 S4, input the test data set into the trained network traffic prediction model to obtain the prediction result.
[0057] Step five S5, according to the prediction results and the priority order of each microservice, formulate a corresponding network traffic limiting strategy for each microservice.
[0058] The method of the present application utilizes traffic data and a network traffic prediction model to achieve prediction of network requests and network traffic allocation, can make timely adjustments to the constantly changing network data, and achieve intelligent scheduling of network broadband resources.
[0059] Specifically, for step 1 S1, the content of each microservice includes: service, server, service flow and the calling relationship between services. Specifically, define the category of each service, including service number, service type, service priority and server number; among them, the service number is the number used to uniquely identify each microservice; the service type is a classification identifier used to distinguish different types of services; the service priority (from large to small) is the basis for microservice operation and flow adjustment; the server number is the number of the server where a certain microservice is located.
[0060] Specifically, define the specific information of the server, including: server number, service quantity, network card status and port number; among them, the server number is used to uniquely identify each server; the service quantity is used to record the actual number of microservices running on each server; the network card status records the status and performance indicators of the server network interface, which affects the inflow and outflow of network traffic; the port number is used to record the port number of the server.
[0061] Specifically, the information that defines service traffic includes: time, service ID, service type, and traffic information; among them, time is used to record the timestamp of traffic data; service ID is an identifier used to record the source of traffic; service type is a classification identifier used to distinguish different types of services; traffic information is used to record the service data traffic passing through the router, in kilobytes (KB).
[0062] Specifically, the information that defines the calling relationship between services includes initiator information, receiver information, routing status, and delay information; among them, the initiator information is used to record the initiator of the service call; the receiver information is used to record the receiver of the service call; the routing status is used to record the routing path of the service call, including the protocol and port used; the delay information is used to record the network delay of the service call.
[0063] In some embodiments, the priority order of each microservice is set according to the content of each microservice, and the method is: calculating the weight of each microservice; calculating the weight ratio of each microservice according to the weight of each microservice; and obtaining the priority order of each microservice according to the weight ratio of each microservice. By setting the priority order of each microservice, it can be used to subsequently optimize the network traffic prediction model, so that the network traffic flow limiting strategy is more in line with user needs.
[0064] Specifically, the weight of each microservice can be obtained by calculating the weights of historical traffic, microservice dependencies, and microservice interactions.
[0065] Specifically, the historical traffic weight is calculated as follows:
[0066]
[0067] Among them, F i represents the historical traffic weight of the i-th microservice, V L,i(t) It represents the flow value at time t, and T represents the length of the time window.
[0068] The dependency weight of a microservice is calculated as follows:
[0069] D i =∑ k∈S X k ;
[0070] Among them, D i represents the dependency weight of the i-th microservice, X k represents the calculated weight of the kth dependent service, and S represents the set of dependent services.
[0071] The interaction weight of microservices is calculated as follows:
[0072] E i =∑ k∈C Y j,k ;
[0073] Among them, E i represents the interaction weight of the i-th microservice, Y j,k represents the interaction frequency between microservice j and microservice k, and C represents the set of interacting services.
[0074] Therefore, the weight of each microservice is W i The calculation method is:
[0075] W i =ω F ·F i +ω D ·D i +ω E ·Ei ;
[0076] Among them, ω F represents the historical traffic weight F of the i-th microservice i The weight coefficient, ω D Denotes the dependency weight D of the i-th microservice i The weight coefficient, ω E Represents the interaction weight E of the i-th microservice i The weight coefficient of .
[0077] Specifically, according to the weights of each microservice calculated above, the weight proportion w of each microservice is calculated. i , the calculation method is:
[0078]
[0079] Among them, W i represents the weight of the i-th microservice, represents the sum of the weights of all microservices, and M represents the total number of microservices.
[0080] According to the weight ratio of each microservice above, the priority order H of each microservice can be obtained. i , the calculation method is:
[0081] H i =F×W i ×ρ;
[0082] Among them, F represents the total flow that the system can allocate, W i represents the weight of the i-th microservice, and ρ represents the traffic adjustment factor, which is the adjustment ratio dynamically calculated according to the current system status and the network traffic prediction model.
[0083] In some embodiments, the weight proportion of each microservice and the priority order of each microservice calculated above are used as a posteriori knowledge and integrated into the network traffic prediction model. The network traffic prediction model is modified using a posteriori knowledge to improve the accuracy of traffic prediction; and the network parameters of the network traffic prediction model are adjusted according to the importance of each microservice and the priority of traffic allocation, and the network traffic limiting strategy is optimized.
[0084] In some embodiments, in step 2 S2, traffic data is obtained, and the traffic data is preprocessed to obtain a training data set and a test data set, including:
[0085] The flow data of each link between routers and nodes is obtained according to the packet packaging tool to form an original data set; the original data set is standardized and formatted to obtain a standard data set; the standard data set is split to obtain a training data set and a test data set respectively.
[0086] For example, the wireshake packet capture tool can be used to obtain traffic data of each link between routers and nodes. The traffic data includes information such as traffic size, time, service number, and service type. Based on this traffic data, a comprehensive traffic view can be obtained to form an original data set.
[0087] Furthermore, the original data set is standardized and format converted to facilitate the subsequent training of the network traffic prediction model. The format conversion method is: create an array array = [], save the original data set in XML format to the above array by setting the path of the file where the original data set is located, parse the data and use the to_csv function to output the array as a CSV file. After the original data set is format converted, it is standardized to eliminate the differences between the traffic data so that the traffic data is at the same level before the network traffic prediction model is trained. The standardization process involves calculating the average traffic and standard deviation corresponding to each traffic data point, and then dividing the data point by its standard deviation. Furthermore, the standard data set is split into a training data set and a test data set respectively. The method is as follows: use the n_0 to n_10 digits as features and the n_11 digit as a label; cyclically accumulate x and use the n_x digit to the n_(x+10) digit as features and the n_(x+11) digit as a label; finally, return the features of the x_train training data set, the label of the y_train training data set, the features of the x_test test data set, and the label of the y_test test data set.
[0088] In some embodiments, in combination Figure 2 The network traffic prediction model includes an input module 21, a prediction module 22, a linear regression module 23 and a flow limiting strategy module 24 connected in sequence; the input module 21 includes multiple input layers 210 for inputting traffic data; the prediction module 22 may include multiple, for example, Z, modules for performing traffic prediction on each microservice according to the traffic data and outputting the initial data to the linear regression module 23, each prediction module 22 includes multiple LSTM layers 220; the linear regression module 23 is used to normalize the initial data to obtain normalized data; the flow limiting strategy module 24 formulates a corresponding network traffic flow limiting strategy according to the normalized data.
[0089] In some embodiments, constructing a network traffic prediction model also includes constructing an evaluation function (Evaluation Function, EF) of the network traffic prediction model. The goals of constructing the evaluation function include minimizing traffic variance and maximizing time accuracy. By comprehensively considering and analyzing the two goals and setting corresponding weights, a comprehensive measurement standard is formed.
[0090] In some embodiments, the flow variance is calculated as follows: First, define a set of observation values X = {X1, X2, ..., X B}, the set of observations represents the network traffic data collected at a specific time interval; then, the mean of these observations is calculated Furthermore, the sample variance calculation method is used to measure the volatility of network traffic. The variance value obtained by the calculation method of the above sample method can quantify the degree of discreteness of network traffic data. The smaller the variance value, the more stable the network traffic changes, and the larger the variance value, the more volatile the network traffic changes.
[0091] Specifically, the mean of the observed values The calculation method is:
[0092]
[0093] Where B represents the number of observations, X l ∈X, l∈B.
[0094] Specifically, the sample variance s 2 The calculation method is:
[0095]
[0096] In some embodiments, in order to quantitatively evaluate the time accuracy of network traffic prediction, the mean absolute percentage error (MAPE) is used to measure the difference between the predicted traffic value and the actual predicted value.
[0097] Specifically, the calculation method of absolute percentage error is:
[0098]
[0099] Among them, N1 represents the total number of observed time points, A t represents the actual flow value at time t, Represents the predicted flow value at time t.
[0100] Furthermore, the calculation method of the time accuracy TA is:
[0101]
[0102] From the above calculation method, it can be seen that the time accuracy TA is proportional to the inverse of MAPE (%). When MAPE (%) approaches 1, it means that the time accuracy is maximized; when MAPE (%) is larger, it means that the time accuracy is lower; in this way, the goal of minimizing MAPE (%) can be converted into the goal of maximizing time accuracy.
[0103] In some embodiments, by measuring the difference PAD between the actual network traffic distribution and the priority of the microservice, the responsiveness and fairness of the traffic distribution system to services of different priorities can be reflected. The calculation method is:
[0104]
[0105] Among them, AS i represents the actual network traffic obtained by the i-th microservice, PS i Represents the network traffic received according to the priority of the microservice.
[0106] Furthermore, the calculation method of the above evaluation function is:
[0107] EF = α × TV + β × TA + γ × PAD;
[0108] Among them, α, β, and γ are all weight coefficients, which are used to adjust the importance of different indicators in the evaluation function. The selection of weight coefficients is determined according to the actual network operation and management needs; TV (Traffic Variance) represents the measurement of traffic variance, which reflects the stability of traffic fluctuations. A smaller traffic variance measurement value means more stable traffic; TA (Temporal Accuracy) is a measure of time accuracy, which reflects the proximity between the time point of predicted traffic and the time point of actual traffic occurrence. A higher time accuracy measurement value means a better prediction time match.
[0109] In some embodiments, when training a network traffic prediction model based on a training data set, the training data set is first loaded in batches, so that the same batch of data jointly determines the gradient direction, the direction is not easy to deviate, and the randomness of the gradient direction is reduced; on the other hand, because the number of samples in the same batch of data is much smaller than that of the entire training data set, the amount of calculation is also greatly reduced, shortening the single training time.
[0110] In some embodiments, a method for training a network traffic prediction model comprises the steps of:
[0111] The first step is to create an ArgumentParser object, add parameters and parse them, and set a set of feature number lag to a. For example, a can be 12, which means that for each time step in the network traffic prediction model, the data of the 12 time steps before this time step are used as features to predict the value of the current time step. "Time step" refers to the number of consecutive observation points input into the network traffic prediction model.
[0112] In the second step, after multiple debugging, the number of samples is finally set to n (for example, 256), and the number of training times is set to m (for example, 600); the data processing function is called to obtain the features of the x_train training data set and the labels of the y_train training data set.
[0113] The third step is to transform the x_train training data set into a three-dimensional array of one column and set the parameters of the network traffic prediction model.
[0114] Step 4: Initialize the network traffic prediction model, add a prediction module, set return_sequences = True, and output h at each time step. t Specifically, return_sequences is a Boolean value that controls the output type of the LSTM layer. When return_sequences is True, the LSTM layer will output a hidden state h at each time step. t When return_sequences = False is set, the LSTM layer only outputs the hidden state h in the last time step. t .
[0115] The fifth step is to input the output results of the prediction module into the linear regression module for training.
[0116] Step 6: Obtain a complete network traffic prediction model, input the x_test test data set, and obtain the prediction results.
[0117] The seventh step is to formulate corresponding network traffic limiting strategies for each microservice based on the prediction results and the priority order of each microservice.
[0118] In some embodiments, a network traffic prediction model is constructed, and the network traffic prediction model is trained using a training data set, further comprising: optimizing the network traffic prediction model. Optimizing the network traffic prediction model can achieve the effect of reducing the prediction error. Exemplarily, the method used in this application is a quantum particle swarm optimization (QPSO) algorithm. The QPSO algorithm is an optimization algorithm that simulates the foraging behavior of a flock of birds. It introduces the concept of quantum computing on the basis of traditional particle swarm optimization. The QPSO algorithm uses the state of quantum bits to represent the position and speed of particles, and updates the particle position through a quantum revolving gate to search for the optimal solution.
[0119] In some embodiments, optimizing a network traffic prediction model includes the steps of: randomly initializing the position of each particle in a quantum particle group; performing a quantum rotating gate operation on each particle to obtain a quantum rotation result; updating the position of the particle according to the quantum rotation result; updating the network parameters of the network traffic prediction model according to the updated position of the particle; and repeating the above steps to iteratively train the network traffic prediction model until an optimal solution is output.
[0120] In some embodiments, the position of each particle in the quantum particle group is randomly initialized by:
[0121]
[0122] Among them, |explore> and |exploit> represent the search state and exploitation state respectively, and r represents the particle index.
[0123] In some embodiments, a quantum rotation gate operation is performed on each particle to obtain a quantum rotation result U θ , the calculation method is:
[0124]
[0125] Among them, θ represents the rotation angle, which controls the transition of the particle between the search state and the utilization state.
[0126] In some embodiments, the position of the particle is updated according to the quantum rotation result by:
[0127] First, determine whether the particle maintains the current position (i.e., the utilization state) or jumps to a new position (i.e., the search state). The determination method is:
[0128]
[0129] Among them, p means jumping to a new position, 1-p means keeping the current position, and p is calculated based on the superposition probability of the quantum state.
[0130] Furthermore, the position of the particle is updated by:
[0131] ψ r '=U θ ψ r ;
[0132] Among them, ψ r 'Indicates the updated position of the particle.
[0133] In some embodiments, the network parameters of the network traffic prediction model are updated according to the updated particle positions, by:
[0134] v' r=ωvr+c1e1(pbest-ψr')+c2e2(gbest-ψr');
[0136] ψ r ”=ψ r '+v' r ;
[0137] Among them, ω represents the inertia weight, v r represents the velocity of the particle, ψ r ' represents the updated position of the particle, p best represents the best historical position of the particle, c1 and c2 represent acceleration coefficients, e1 and e2 are random numbers in the interval [0,1], and g best represents the global optimal position in the quantum particle group, v' r represents the updated particle velocity, ψ r " represents the position of the particle after being updated again. It should be noted that the particle speed maps the weight of the network traffic prediction model, and the particle position maps the bias of the network traffic prediction model.
[0138] In some embodiments, the above-mentioned network traffic distribution method for microservices further includes the steps of: applying a network traffic limiting strategy to obtain application data; and dynamically adjusting the network traffic limiting strategy based on the application data.
[0139] For example, a token bucket algorithm can be used to formulate a corresponding network traffic limiting strategy. The token bucket algorithm not only allows a certain degree of burst network traffic, but also prevents system overload by limiting the average request rate. At the same time, in order to more effectively respond to the ever-changing network traffic pattern, the system will dynamically adjust the limiting parameters based on real-time feedback and the prediction results of the network traffic prediction model. The limiting parameters include the filling rate and bucket capacity of the token bucket, which can reflect the system's processing capacity and traffic trends in real time.
[0140] In some embodiments, before applying the network traffic limiting strategy step, it includes: adding limiting implementation dependency, creating limiting identifier, configuring limiting rate; performing a refresh test on the interface requesting network traffic limiting, and applying the network traffic limiting strategy when the refresh frequency meets the set conditions.
[0141] In the microservice architecture, the current limiting configuration is set in the microservice gateway (such as Spring Cloud Gateway), using the RequestRateLimiterGatewayFilterFactory class in combination with Redis to implement token bucket current limiting. Redis is a powerful in-memory data structure storage used as a database, cache, and message broker. In addition, in order to ensure the effectiveness of the current limiting strategy, a feedback loop mechanism can be established. This feedback loop mechanism continuously monitors the current limiting effect and system performance. Once performance degradation or potential service instability risks are detected, the system will adjust the current limiting parameters based on the feedback data to optimize the overall service performance.
[0142] Specifically, add a current limiting implementation dependency, you can add a current limiting implementation dependency based on Redis; create a current limiting identifier, because current limiting usually depends on a certain parameter value as a reference for current limiting, for example: each IP can only be accessed twice per second, at this time, the IP is used as a reference, and an object based on IP current limiting is created. The object needs to implement the interface KeyResolver. Because the current limiting is based on the IP, the instance of IpKeyResolver needs to be handed over to the Spring container for management, and it can be directly placed under the startup class; configure the current limiting rate, which can be configured by adding RequestRateLimiter to the core configuration file. In the above configuration file, the current limiting filter of RequestRateLimiter is configured. The current limiting filter needs to be configured with three parameters: burstCapacity The total capacity of the token bucket, replenishRate The average filling rate of the token bucket per second, and key-resolver The name of the Bean object of the resolver of the key used for current limiting.
[0143] After the above configuration is successful, the interface requesting network traffic limiting is refreshed and tested. When the refresh frequency meets the set conditions, the network traffic limiting strategy is applied. For example, when the refresh frequency exceeds 2 times / s, a 429 error status code is responded, which means that the limiting strategy is successfully implemented.
[0144] Combination Figure 3 The present application also provides an electronic device, including a processor 32 and a memory 31, wherein the memory 31 stores a computer program that can be executed by the processor, and when the computer program is executed by the processor 32, any one of the above-mentioned methods for streamline generation is implemented.
[0145] Specifically, the memory 31 is used to store computer programs or data. The memory 31 can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc.
[0146] The processor 32 is used to read / write data or computer programs stored in the memory 31 and execute corresponding functions. For example, when the computer program stored in the memory 31 is executed by the processor 32, the method for streamline generation provided in the embodiment of the present application can be implemented.
[0147] Combination Figure 4 The present application also provides a computer-readable storage medium 40 on which program instructions 401 are stored. The program instructions 401 are used to implement any of the above-mentioned methods for streamline generation.
[0148] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0149] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0150] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0151] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0152] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0153] In summary, the present application discloses a network traffic allocation method for microservices, wherein the method includes the steps of: setting the priority order of each microservice according to the content of each microservice; obtaining traffic data, and preprocessing the traffic data to obtain a training data set and a test data set; building a network traffic prediction model, and using the training data set to train the network traffic prediction model; inputting the test data set into the trained network traffic prediction model to obtain a prediction result; and formulating a corresponding network traffic limiting strategy for each microservice according to the prediction result and the priority order of each microservice. The method of the present application utilizes traffic data and a network traffic prediction model, and can make timely adjustments to the constantly changing network data, thereby realizing intelligent scheduling of network broadband resources.
[0154] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structural transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A network traffic distribution method for microservices, characterized in that: include: Step 1: Set the priority order of each microservice according to its content; Step 2: Obtain traffic data and preprocess the traffic data to obtain a training data set and a test data set; Step 3: construct a network traffic prediction model, and use the training data set to train the network traffic prediction model; Step 4: input the test data set into the trained network traffic prediction model to obtain a prediction result; Step 5: According to the prediction results and the priority order of each microservice, a corresponding network traffic limiting strategy is formulated for each microservice.
2. The microservice-oriented network traffic distribution method according to claim 1, characterized in that: The priority order of each microservice is set according to the content of each microservice, and the method is: Calculate the weight of each microservice; Calculate the weight proportion of each microservice according to the weight of each microservice; The priority order of each microservice is obtained according to the weight proportion of each microservice.
3. The microservice-oriented network traffic distribution method according to claim 2 is characterized in that: The weight W of each microservice is calculated i , the calculation method is: W i =ω F ·F i +oh D ·D i +oh E ·E i ; The weight proportion w of each microservice is calculated according to the weight of each microservice i , the calculation method is: The priority order H of each microservice is obtained according to the weight proportion of each microservice i , the calculation method is: H i =F×W i ×ρ; Among them, ω F Represents the historical traffic weight F of the i-th microservice i The weight coefficient, ω D Denotes the dependency weight D of the i-th microservice i The weight coefficient, ω E Represents the interaction weight E of the i-th microservice i The weight coefficient, W i represents the weight of the i-th microservice, represents the sum of the weights of all microservices, M represents the total number of microservices, F represents the total traffic that can be allocated by the system, and ρ represents the traffic adjustment factor.
4. The microservice-oriented network traffic distribution method according to claim 1, characterized in that: The method of obtaining the flow data and preprocessing the flow data to obtain a training data set and a test data set includes the following steps: Obtain the traffic data of each link between routers and nodes using the packet encapsulation tool to form an original data set; Standardizing and formatting the original data set to obtain a standard data set; The standard data set is split to obtain the training data set and the test data set respectively.
5. The microservice-oriented network traffic distribution method according to claim 1, characterized in that: The network traffic prediction model includes an input module, a prediction module, a linear regression module and a current limiting strategy module connected in sequence; The input module is used to input the flow data; The prediction module is used to perform traffic prediction for each microservice according to the traffic data, and output initial data to the linear regression module; The linear regression module is used to normalize the initial data to obtain normalized data; The current limiting strategy module formulates a corresponding network traffic current limiting strategy according to the normalized data.
6. The microservice-oriented network traffic distribution method according to claim 1, characterized in that: The step of constructing a network traffic prediction model and using the training data set to train the network traffic prediction model further includes: optimizing the network traffic prediction model.
7. The microservice-oriented network traffic distribution method according to claim 6, characterized in that: The optimizing the network traffic prediction model comprises: The first step is to randomly initialize the position ψ of each particle in the quantum particle group r , the method is: Among them, |explore> and |exploit> represent the search state and the exploitation state respectively, and r represents the particle index; The second step is to perform a quantum rotation gate operation on each particle to obtain a quantum rotation result U θ , the method is: Where θ represents the rotation angle; The third step is to update the position of the particle according to the quantum rotation result, by: ψ r '=U θ ψ r ; Among them, ψ r ' represents the updated position of the particle; The fourth step is to update the network parameters of the network traffic prediction model according to the updated position of the particle, by: was r =ωvr+c1e1(pbest-ψr')+c2e2(gbest-ψ'r); ψ r "=ψ" r '+v' r ; Among them, ω represents the inertia weight, v r represents the velocity of the particle, p best represents the best historical position of the particle, c1 and c2 represent acceleration coefficients, e1 and e2 are random numbers in the interval [0,1], and g best represents the global optimal position in the quantum particle group, v' r represents the updated particle velocity, ψ r " represents the position of the particle after it is updated again; The fifth step is to repeat the above steps to iteratively train the network traffic prediction model until the optimal solution is output.
8. The microservice-oriented network traffic distribution method according to claim 1, characterized in that: Also includes the steps: Apply the network traffic limiting strategy to obtain application data; The network traffic limiting strategy is dynamically adjusted according to the application data.
9. The microservice-oriented network traffic distribution method according to claim 8, characterized in that: Before the step of applying the network traffic limiting strategy, the method includes: Add current limiting implementation dependency, create current limiting identifier, and configure current limiting rate; A refresh test is performed on the interface requesting network traffic limiting, and when the refresh frequency meets the set conditions, the network traffic limiting strategy is applied.
Citation Information
Cited By
Traffic scheduling method and electronic equipment
CN120896909A
Traffic scheduling method and electronic device
CN120896909B
