A method, device, electronic device and medium for cloning a virtual machine
By using the virtual machine cloning network model to generate cloning strategies and detect constraints, the problems of inefficient and low degree of automation of virtual machine cloning in the existing technology are solved, and efficient and automated virtual machine cloning is achieved.
Patent Information
- Application Number
- CN202411773082.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-04
- Publication Date
- 2025-04-08
AI Technical Summary
The existing virtual machine cloning methods are inefficient and low in automation, making it difficult to meet the needs of virtual machine cloning.
By obtaining the current status data of the target virtual machine and the configuration data input by the user, the target cloning network model is used to generate the target cloning policy, and detect whether the policy meets the constraints. If so, perform cloning operations.
It realizes the generation of cloning strategies through network models for virtual machine cloning, which improves cloning efficiency and automation, and meets the needs of virtual machine cloning.
Smart Images

Figure CN119781901A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of virtualization technology, and in particular to a method, device, electronic equipment and medium for cloning a virtual machine. Background Art
[0002] With the development of virtualization technology, more and more virtual machines are used. In some scenarios, virtual machines need to be cloned to quickly create virtual machines.
[0003] Among them, virtual machine cloning is an important function in virtualization technology. It allows users to quickly create a new virtual machine with the same configuration as the original virtual machine. However, the existing virtual machine cloning methods have many problems such as low efficiency and low automation, which make it difficult to meet the needs of virtual machine cloning. Summary of the invention
[0004] In view of the above problems, a method, device, electronic device and medium for cloning a virtual machine are proposed to overcome the above problems or at least partially solve the above problems, including:
[0005] A method for cloning a virtual machine, the method comprising:
[0006] Obtaining the current state data of the target virtual machine to be cloned and the configuration data input by the user;
[0007] Generate a target cloning strategy for the target virtual machine according to the current state data and configuration data by using a pre-trained virtual machine cloning network model;
[0008] Detecting whether the target cloning strategy satisfies constraint conditions; wherein the constraint conditions include restriction conditions on resources required by the target cloning strategy;
[0009] When the target cloning policy satisfies the constraint condition, the target virtual machine is cloned according to the target cloning policy.
[0010] Optionally, it also includes:
[0011] When the cloning operation does not satisfy the constraint condition, the target cloning policy is adjusted, and the cloning operation is performed on the target virtual machine according to the adjusted target cloning policy.
[0012] Optionally, before obtaining the current state data of the target virtual machine to be cloned and the configuration data input by the user, the method further includes:
[0013] Get virtual machine clone history data;
[0014] Generate an initial state vector arranged in chronological order according to the virtual machine clone historical data;
[0015] Generate a key state vector according to the initial state vector through a self-attention mechanism;
[0016] The key state vector is used to train a preset virtual machine clone network model.
[0017] Optionally, generating a key state vector according to the initial state vector through a self-attention mechanism includes:
[0018] Extracting a key query vector and a corresponding key vector and value vector from the initial state vector through a self-attention mechanism;
[0019] Calculating an attention score based on the key query vector and the corresponding key vector;
[0020] Calculate the probability weight corresponding to the key vector according to the attention score;
[0021] The value vectors are weighted and summed according to the probability weights to obtain a weighted value vector, so as to determine the key state vector according to the weighted value vector.
[0022] Optionally, extracting a key query vector and a corresponding key vector and value vector from the initial state vector includes:
[0023] Initialize the weight matrix and bias terms;
[0024] According to the weight matrix and the bias term, the initial state vector is linearly transformed to obtain a key query vector and a corresponding key vector and value vector.
[0025] Optionally, calculating the attention score according to the key query vector and the corresponding key vector includes:
[0026] For each key query vector, calculating a dot product of the key query vector and the key vector;
[0027] The dot product is scaled to obtain an attention score matrix.
[0028] Optionally, the virtual machine clone network model includes a primary network and a target network, and the adopting the key state vector to train the preset virtual machine clone network model includes:
[0029] Through the main network in the preset virtual machine clone network model, according to the key state vector, select the action related to the virtual machine clone, and determine the predicted evaluation value according to the key state vector, the action, the reward of the action, and the new state vector obtained after executing the action;
[0030] The target network in the preset virtual machine clone network model is cloned, and the target evaluation value is determined according to the key state vector, the action, the reward of the action, and the new state vector obtained after the action is executed;
[0031] According to the difference between the predicted evaluation value and the target evaluation value, the parameters of the virtual machine clone network model are updated to train the virtual machine clone network model.
[0032] A device for cloning a virtual machine, the device comprising:
[0033] A current state data and configuration data acquisition module, used to acquire the current state data of the target virtual machine to be cloned and the configuration data input by the user;
[0034] A target cloning strategy generation module, used to generate a target cloning strategy for the target virtual machine according to the current state data and configuration data through a pre-trained virtual machine cloning network model;
[0035] A constraint condition detection module, used to detect whether the target cloning strategy satisfies the constraint condition; wherein the constraint condition includes the restriction condition of the resources required by the target cloning strategy;
[0036] The cloning operation execution module is used to perform a cloning operation on the target virtual machine according to the target cloning strategy when the target cloning strategy meets the constraint condition.
[0037] An electronic device comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the method described above when executed by the processor.
[0038] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described above is implemented.
[0039] The embodiments of the present invention have the following advantages:
[0040] In an embodiment of the present invention, by obtaining the current state data of the target virtual machine to be cloned and the configuration data input by the user, a target cloning policy for the target virtual machine is generated according to the current state data and the configuration data through a pre-trained virtual machine cloning network model, and it is detected whether the target cloning policy meets the constraint conditions. If the target cloning policy meets the constraint conditions, the target virtual machine is cloned according to the target cloning policy, thereby achieving the goal of generating a cloning policy through a network model to perform virtual machine cloning and meet the virtual machine cloning requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0042] Figure 1 is a schematic diagram of a system module provided by some embodiments of the present invention;
[0043] Figure 2 is a flowchart of the steps of a method for cloning a virtual machine provided by some embodiments of the present invention;
[0044] Figure 3 is a flowchart of the steps of another method for cloning a virtual machine provided by some embodiments of the present invention;
[0045] Figure 4 is a schematic diagram of a system architecture provided by some embodiments of the present invention;
[0046] Figure 5 It is a structural block diagram of a virtual machine cloning device provided by some embodiments of the present invention. DETAILED DESCRIPTION
[0047] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] In virtualization technology, virtual machine cloning is an important function that allows users to quickly create a new virtual machine with the same configuration as the original virtual machine. The efficiency and performance of virtual machine cloning technology are significantly affected by the cloning strategy, and the choice of cloning strategy is directly related to the stability of the system.
[0049] In addition, virtual machine cloning technology also needs to focus on key issues such as resource allocation and management, data consistency and integrity, network configuration, and performance optimization.
[0050] In the related art, a snapshot node is generated based on the original image of the original virtual machine, and the cloning process is optimized through breadth pruning to reduce redundant data and improve cloning efficiency. In another related art, a virtual machine cloning instruction is obtained; according to the virtual machine cloning instruction, a card I / O tool for prohibiting the issuance of write instructions is started to control the target virtual machine to be cloned so that it cannot perform write operations; a snapshot of the target virtual machine is taken to obtain a target snapshot; and the target snapshot is cloned to obtain a cloned virtual machine.
[0051] Although the above technical solution solves the problems of low efficiency, data redundancy and write operation control that may be encountered in the virtual machine cloning process, it still has problems of poor program compatibility and low degree of automation, and cannot adopt accurate cloning solutions for diverse states, needs and conditions.
[0052] In a complex environment, the thinking mode of relying on experience to select cloning technology or formulating cloning strategies according to specific conditions is often insufficient. Therefore, the present invention proposes a virtual machine cloning technology system that combines self-attention mechanism and reinforcement learning, such as Figure 1 , specifically including:
[0053] 1. Status monitoring and input module: This module is responsible for monitoring the current status of the virtual machine, including hardware configuration, resource usage, network configuration, etc. Users or system administrators can input specific requirements, conditions or parameters through this module to provide guidance for cloning operations. The module then performs pre-processing operations on these status information.
[0054] 2. Cloning strategy prediction module: This module integrates a reinforcement learning model based on the self-attention mechanism, which can predict and output the optimal cloning strategy based on the input status, requirements and conditions. The prediction results include virtual machine cloning strategy selection, configuration adjustment, storage and network resource allocation plan, etc.
[0055] 3. Clone execution module: This module performs the actual cloning operation according to the predicted cloning strategy, including creating a copy of the virtual machine, copying data, configuring the network, etc.
[0056] 4. Constraint processing module: This module is responsible for checking whether the cloning operation meets various constraints, such as storage resource restrictions, network bandwidth restrictions, etc. If the constraints are not met, the module will trigger the corresponding processing logic, such as adjusting the cloning strategy, prompting the user to intervene, or recording error logs.
[0057] 5. User interface and interaction module: This module provides a friendly interface, allowing users to easily view the status of virtual machines, input cloning requirements, start cloning operations, etc. The module is also responsible for displaying cloning progress, results and performance data, and receiving user feedback and suggestions.
[0058] 6. Log recording and troubleshooting module: This module is responsible for recording the operation log of the clone system, including operation records, error logs, etc. When a failure or problem occurs, the administrator can locate the cause of the problem and conduct troubleshooting by analyzing the log.
[0059] In an embodiment of the present invention, a highly intelligent model is constructed by combining reinforcement learning technology with a self-attention mechanism. The model can accurately predict and implement the optimal virtual machine cloning strategy for a variety of states, requirements and conditions. Specifically, the model intelligently selects and executes the most appropriate cloning strategy and settings by deeply analyzing the input virtual machine status, business requirements and environmental conditions, aiming to significantly improve the efficiency of virtual machine cloning, while ensuring that the cloned virtual machine can run stably and meet the preset performance indicators. Moreover, the embodiment of the present invention fully considers the various constraints faced in the virtual machine cloning process, such as storage resource limitations, network bandwidth limitations, etc. By incorporating these constraints into the decision-making process, the adopted cloning strategy and settings are more in line with reality, improving its feasibility and applicability in complex environments.
[0060] The present invention is exemplarily described below with reference to the accompanying drawings:
[0061] Reference Figure 2 , shows a flowchart of a method for cloning a virtual machine provided by some embodiments of the present invention, which may specifically include the following steps:
[0062] Step 201: Acquire the current state data of the target virtual machine to be cloned and the configuration data input by the user.
[0063] In actual applications, the current status data of the target virtual machine to be cloned is monitored, including hardware configuration, resource usage, network configuration, etc., and the user or system administrator can enter configuration data such as specific requirements, conditions or parameters to provide guidance for the cloning operation.
[0064] Step 202: Generate a target cloning strategy for the target virtual machine according to the current state data and configuration data through a pre-trained virtual machine cloning network model.
[0065] In practical applications, the pre-trained virtual machine cloning network model can predict and output the optimal target cloning strategy based on the input status, requirements and conditions. The prediction results include virtual machine cloning strategy selection, configuration adjustment, storage and network resource allocation plans, etc.
[0066] Step 203: Detect whether the target cloning strategy satisfies constraint conditions; wherein the constraint conditions include the restriction conditions of the resources required by the target cloning strategy.
[0067] In actual applications, constraints can be set in advance, such as storage resource restrictions, network bandwidth restrictions, etc., and then it can be detected whether the target cloning strategy meets the constraints.
[0068] Step 204: When the target cloning policy satisfies the constraint condition, clone the target virtual machine according to the target cloning policy.
[0069] If the target cloning policy meets the constraints, the actual cloning operation is performed according to the predicted target cloning policy, including creating a copy of the virtual machine, copying data, configuring the network, etc.
[0070] In some embodiments of the present invention, it also includes:
[0071] When the cloning operation does not satisfy the constraint condition, the target cloning policy is adjusted, and the cloning operation is performed on the target virtual machine according to the adjusted target cloning policy.
[0072] If the target cloning strategy does not meet the constraint conditions, the corresponding processing logic will be triggered, such as adjusting the cloning strategy, prompting the user to intervene, or recording an error log.
[0073] In some examples, the operation log of the clone system may also be recorded, including operation logs, error logs, etc. When a failure or problem occurs, the cause of the problem may be located and investigated by analyzing the logs.
[0074] During the cloning operation, the operation logs and operation records of the clone system are recorded synchronously. These data not only help to monitor the operation status of the clone system in real time, but can also be used for subsequent model optimization and fault location. By analyzing the operation logs and operation records, we can gain an in-depth understanding of the performance of the cloning strategy in actual applications, discover potential problems and room for improvement, and further adjust and optimize the network model to improve the overall performance and stability of the virtual machine cloning system.
[0075] In some examples, the virtual machine clone network model may be a Double DQN (Deep Q-Network) model. The virtual machine clone network model may be trained before use, such as Figure 3 As shown:
[0076] 1. Collect the historical data of virtual machine clones as training data to build the clone network model. At the same time, the current virtual machine state data is used as a test model and does not participate in the subsequent training and optimization process.
[0077] 2. The collected data needs to be preprocessed: including cleaning noise and outliers, converting data formats, extracting and constructing features to form a multi-dimensional vector suitable for use by machine learning models, reflecting the status information of the virtual machine at each time point.
[0078] 3. The processed state information vector is passed through the self-attention mechanism to output the correlation between different states and capture key state features.
[0079] 4. After the state information vector of the virtual machine at each moment after the self-attention mechanism is used as the input of the Double·DQN model for training, the model begins to gradually learn how to predict and optimize the cloning strategy based on this state information.
[0080] 5. The trained target Q network serves as the prediction module of the virtual machine cloning system, receives virtual machine status data, and outputs cloning strategies, configuration adjustments, and expected returns.
[0081] 6. The clone execution module performs the operation accordingly, and the constraint processing module ensures compliance. At the same time, the logging and troubleshooting module monitors and records the system operation to provide a basis for model optimization and fault location.
[0082] In some embodiments of the present invention, before obtaining the current state data of the target virtual machine to be cloned and the configuration data input by the user, the process further includes:
[0083] Step 11: Obtain virtual machine clone history data.
[0084] In actual applications, the virtualization platform, storage resources, virtual machine historical data, environmental parameters and other historical data of virtual machine clones selected in the virtual machine historical clones are collected as training data. These virtual machine status data are mainly used to train the virtual machine clone network model.
[0085] For example, virtual machine cloning history data includes which virtualization platform is used (virtualization platform identifier), virtual machine status data (CPU usage, memory occupancy, disk read and write speed), virtual machine configuration data (hardware configuration, operating system type, application installation status), cloning operation history data (timestamp of each cloning, duration of the cloning process, performance of the virtual machine after cloning), network bandwidth usage during the cloning process, and error log information recorded for errors or exceptions that occur during cloning (error type, error level, error description).
[0086] Step 12: Generate an initial state vector arranged in chronological order according to the virtual machine clone historical data.
[0087] After obtaining the virtual machine clone historical data, the collected data can be processed. These data usually exist in the form of time series, and each time point corresponds to a set of state and environmental parameters. The collected virtual machine historical state data, environmental parameters and other data can be preprocessed to convert them into a format suitable for use by machine learning models.
[0088] In some examples, preprocessing steps include data cleaning (removing noise, outliers, or irrelevant data), data transformation (converting raw data into a format that the model can process), and feature engineering (extracting and constructing features that help the model learn).
[0089] After the processing is completed, the data at each time point is represented as a multidimensional vector, which contains the state information of the source virtual machine at that time. Taking the state of the source virtual machine at time t as an example, the initial state vector x t It can be expressed as:
[0090]
[0091] Among them, each element Represents the i-th state feature of the source virtual machine at time t.
[0092] In some examples, these features can be numerical data (such as CPU usage, memory usage, etc.) or categorical data (such as the platform type on which the virtual machine runs, the type of storage resources, etc.). The total number of features m depends on the number and type of state features selected.
[0093] In some examples, in order to enhance the generalization ability of the model, these features can be normalized or standardized to eliminate the impact of dimensional differences and numerical ranges between different features. Finally, after preprocessing and feature engineering, a series of initial state vectors arranged in chronological order are obtained, each of which contains the complete state information of the source virtual machine at a certain moment.
[0094] Step 13: Generate a key state vector based on the initial state vector through a self-attention mechanism.
[0095] In practical applications, the processed initial state vector is passed through the self-attention mechanism to output the correlation between different states and capture the key state features, that is, to generate the key state vector.
[0096] In some embodiments of the present invention, generating a key state vector according to the initial state vector by a self-attention mechanism includes:
[0097] Sub-step 131, extracting a key query vector and a corresponding key vector and value vector from the initial state vector through a self-attention mechanism.
[0098] In the self-attention mechanism, in order to extract the key query, key, and value representations from the feature vector containing the virtual machine state information, a linear transformation is adopted, which is specifically expressed as the product of a weight matrix and the input vector, and then a bias term is added.
[0099] In some embodiments of the present invention, extracting a key query vector and a corresponding key vector and value vector from the initial state vector includes:
[0100] Initialize a weight matrix and a bias term; perform a linear transformation on the initial state vector according to the weight matrix and the bias term to obtain a key query vector and a corresponding key vector and value vector.
[0101] 1. Initialize the weight matrix and bias term: Set the weight matrix W for query (Q), key (K) and value (V) respectively Q , W K and W V , and the corresponding bias term b Q , b K and b V .
[0102] In some examples, these parameters are obtained by random initialization at the beginning of model training, and the bias term is usually initialized to zero or a small value close to zero. As the model iterates and optimizes on the training data, these weight matrices and bias terms will gradually adjust to the best fit state, thereby minimizing the model's loss on the training set.
[0103] 2) Next, perform a linear transformation: for each virtual machine feature vector (x), apply the following formula to calculate the corresponding query, key, and value vectors:
[0104] q=w q x+b q
[0105] k=w k x+b k
[0106] v=w v x+b v
[0107] Among them, (x) is the state information vector, (q), (k), and (v) represent the query, key, and value vectors obtained through linear transformations, respectively. These transformations provide a diversified data representation for the self-attention mechanism, enabling the model to extract features related to queries, keys, and values from different perspectives.
[0108] 3. Stacking and combining: For each virtual machine state information vector in the time series, we perform the above linear transformation to generate a series of query, key, and value vectors. These vectors are then stacked into a matrix form for subsequent efficient self-attention calculations. This step not only improves the efficiency of the calculation, but also enables the model to more comprehensively consider the correlation between different states.
[0109] Through the above linear transformation process, the self-attention mechanism acquires the ability to extract key features from the original state information vector. These features not only reflect the state changes of the virtual machine at different times, but also reveal the potential connections and dependencies between states. This flexibility enables the model to process complex virtual machine state data more effectively and accurately capture key state features.
[0110] Sub-step 132, calculating an attention score according to the key query vector and the corresponding key vector.
[0111] In practical applications, the attention score is calculated by calculating the Query (i.e., key query vector) and Key (i.e., key vector), and the similarity between them is measured by the dot product operation. In order to make the training process more stable and prevent the gradient from being too large, a scaling factor is introduced. This operation is called Scaled Dot-Product Attention.
[0112] In some embodiments of the present invention, calculating the attention score according to the key query vector and the corresponding key vector includes:
[0113] For each key query vector, a dot product of the key query vector and the key vector is calculated; and a scaling operation is performed on the dot product to obtain an attention score matrix.
[0114] 1. Prepare Query and Key vectors: For each input virtual machine state vector, the corresponding Query and Key have been obtained through linear transformation. There is a Query vector set and a Key vector set Among them, m represents the number of Query and Key vectors, which is consistent with the number of previous state information vectors. k ) is the dimension of the Key vector. For a specific Query vector (q i ), whose dot product with all Key vectors can be expressed as a vector (a i ), where each element (a ij ) is (q i ) and (k i ) is the dot product of .
[0115] 2. Perform dot product operation: For each Query vector (q i ∈Q), calculate its difference with all Key vectors (k i The dot product operation essentially measures the similarity or compatibility between the Query and Key vectors.
[0116] 3. Scaling operation: In order to prevent the problem of unstable training caused by excessive gradient, the dot product is scaled. The scaling factor is the dimension of the Key vector (d k ), that is, This scaling operation ensures that when (d k ) is large, the variance of the dot product result will not be too large, so that the gradient remains in a reasonable range. The scaled attention score can be expressed as
[0117] 4. Obtain the attention score matrix: For all query vectors, repeat the above dot product and scaling operations, and finally obtain an attention score matrix (A), where each element (A ij ) represents the scaled attention score between the (i)th Query vector and the (j)th Key vector.
[0118] For example, it can be expressed as:
[0119]
[0120] Among them, (Qk T ) is the dot product operation of the Query and Key matrices, and is the scaling factor.
[0121] Sub-step 133, calculating the probability weight corresponding to the key vector according to the attention score.
[0122] In practical applications, the attention score A of the virtual machine-based Q vector (i.e., key query vector) and K vector (i.e., key vector) can be ij Apply the softmax function to get the probability weight e corresponding to each key vector ij In some examples, the softmax function converts the attention scores into probabilities so that the sum of all probabilities is 1. This can be expressed as:
[0123]
[0124] Among them, exp is an exponential function, and the denominator is the exponential sum of the scaled attention scores corresponding to all Key vectors.
[0125] Sub-step 134, performing weighted summation on the value vector according to the probability weight to obtain a weighted value vector, and determining a key state vector according to the weighted value vector.
[0126] In practical applications, the attention weight e after softmax processing can be ij And the corresponding Value vector v j (i.e., value vector) is weighted summed to obtain the weighted Value vector v′ i .
[0127] For example, it can be expressed as:
[0128] v′ i =∑ j e ij ·v j
[0129] After the above steps, each Query vector has a corresponding weighted vector, which is a weighted combination of all Value vectors and the Query vector's relevance. This process allows the model to dynamically adjust the weights of different Value elements based on the correlation between virtual machine state information, thereby extracting more useful information.
[0130] Step 14: Use the key state vector to train the preset virtual machine clone network model.
[0131] In practical applications, the key state vector of the virtual machine at each moment after the self-attention mechanism is used as the input of the DoubleDQN model to train the DoubleDQN model.
[0132] In some examples, such as Figure 4 The virtual machine cloning network model includes a main network and a target network. Double DQN includes two Q networks, namely the main Q-Network and the target Q-Network. The network receives the virtual machine state information vector as input and then extracts features through a series of fully connected layers. These features are then mapped to Q values of different actions through one or more fully connected layers. These actions include starting to clone a virtual machine, stopping to clone a virtual machine, virtual machine cloning strategy, selecting an installation location, modifying configuration information, etc.
[0133] Based on the results of the agent's actions, such as whether cloning is successful, resource efficiency, system stability, cloning speed, etc., the environment will give corresponding reward signals to update the Q value. The structure of the target Q network is the same as the main Q network, but the weights are fixed and are used to calculate the target Q value during training. Its weights are periodically copied from the main Q network, or slowly approach the weights of the main Q network through soft updates.
[0134] In some embodiments of the present invention, the virtual machine clone network model includes a primary network and a target network, and the key state vector is used to train the preset virtual machine clone network model, including:
[0135] Sub-step 141, through the main network in the preset virtual machine clone network model, according to the key state vector, select the action related to the virtual machine clone, and determine the predicted evaluation value according to the key state vector, the action, the reward of the action, and the new state vector obtained after executing the action.
[0136] In practical applications, for each time step t, the ε-greedy strategy is used to select the action a related to virtual machine cloning according to the main Q network. Action a includes but is not limited to starting to clone a virtual machine, stopping to clone a virtual machine, selecting a virtual machine cloning strategy, determining the virtual machine installation location, modifying the virtual machine configuration information, etc. Among them, the ε-greedy strategy refers to randomly generating a random number between 0 and 1 for each virtual machine state. If the random number is less than the exploration rate ε, an action is randomly selected; otherwise, the optimal action is selected according to the current state value function of the main Q network.
[0137] After executing action a, we observe the reward r associated with the cloning task and the new virtual machine state v″ i (i.e., the new state vector). The reward r may include indicators such as whether the cloning is successful, resource utilization efficiency, system stability, and cloning speed. i ,a,r,v″ i ) is stored in the experience replay buffer D.
[0138] In some examples, before using the main network, the following may also be included:
[0139] Initialize the parameters of the main Q network and the target Q network; initialize the experience playback buffer D (such as Figure 4The experience replay buffer D is mainly used to store the experience data obtained by the interaction between the agent and the environment (i.e., the virtual machine management system). It is a fixed-size circular queue. When new experience data arrives, the oldest data will be replaced. The experience replay buffer D plays the role of offline learning in the training process, allowing the agent to learn from past virtual machine cloning experience and thus optimize its cloning strategy.
[0140] Sub-step 142, cloning the target network in the network model through the preset virtual machine, and determining the target evaluation value according to the key state vector, the action, the reward of the action, and the new state vector obtained after executing the action.
[0141] As some examples, the evaluation values are the Q-values of the deep Q-network.
[0142] In practical applications, a batch of virtual machine clone experiences are randomly sampled from the experience replay buffer D to train the main Q network. For each experience, if the new virtual machine state v″ i is a terminal state (e.g., cloning is completed or the maximum number of iterations is reached), then the target Q value y i Reward i Otherwise, the target Q value y i is the current reward r i Add the discount factor γ and multiply it by the state v″ i Here, the main Q network is used to select the action, but the target Q network is used to evaluate the Q value of this action, realizing the separation of action selection and Q value evaluation.
[0143] For example, the formula can be expressed as:
[0144]
[0145] Sub-step 143: updating the parameters of the virtual machine clone network model according to the difference between the predicted evaluation value and the target evaluation value, so as to train the virtual machine clone network model.
[0146] Among them, the mean square error loss function is used to calculate the output Q value (i.e., the predicted evaluation value) of the main Q network and the target Q value y i (i.e., the target evaluation value). Subsequently, a gradient descent step is performed to update the parameters θ of the main Q network to minimize this loss function. The formula is expressed as:
[0147]
[0148] Where L(θ) is the loss function, θ is the parameter of the behavior network (main network). N is the batch size, which is the number of samples used in one training step. i is the target value of the actual Q value, that is, the Q value calculated by the target network. Q(v i ′ ,a i ; θ) is the behavior network for state v i ′ and action a i The predicted Q value of .
[0149] In some examples, every C steps (e.g., fixed at 100 steps), the parameters of the main Q network are copied to the target Q network, and the parameters of the target Q network are updated, which ensures that the target Q network remains relatively stable and contributes to the stability of training.
[0150] After training, the trained target Q network can be used as the core prediction module of the virtual machine cloning system, which receives the virtual machine state data from the state monitoring and input module as input. These data contain key information such as the current configuration, resource usage, and performance of the virtual machine. Subsequently, after being processed by the cloning strategy prediction module, the target Q network outputs the corresponding virtual machine cloning strategy, virtual machine configuration adjustment and other actions based on the learned Q value function, as well as the expected returns or performance evaluations that can be obtained by executing these actions. These expected returns or performance evaluations are usually manifested as key performance indicators such as the efficiency of the cloning operation, the stability of the cloned virtual machine, and resource utilization.
[0151] Based on these prediction results, the cloning execution module will perform the actual cloning operation according to the cloning strategy and configuration adjustment actions output by the network model. At the same time, the constraint processing module is responsible for checking whether the cloning operation meets the constraints set by the user or administrator, such as storage resource restrictions, network bandwidth restrictions, etc. If the cloning operation does not meet the constraints, the constraint processing module will record a detailed error log for subsequent analysis and processing.
[0152] During the cloning operation, the logging and troubleshooting module synchronously records the operation logs, operation records and other data of the clone system. These data not only help to monitor the operation status of the clone system in real time, but can also be used for subsequent model optimization and fault location. By analyzing the operation logs and operation records, we can gain a deep understanding of the performance of the cloning strategy in actual applications, discover potential problems and room for improvement, and further adjust and optimize the network model to improve the overall performance and stability of the virtual machine cloning system.
[0153] In an embodiment of the present invention, by obtaining the current state data of the target virtual machine to be cloned and the configuration data input by the user, a target cloning policy for the target virtual machine is generated according to the current state data and the configuration data through a pre-trained virtual machine cloning network model, and it is detected whether the target cloning policy meets the constraint conditions. If the target cloning policy meets the constraint conditions, the target virtual machine is cloned according to the target cloning policy, thereby achieving the goal of generating a cloning policy through a network model to perform virtual machine cloning and meet the virtual machine cloning requirements.
[0154] Specifically, it includes at least the following points:
[0155] 1. The present invention transforms the selection process of virtual machine cloning scheme into a machine learning algorithm model based on reinforcement learning. The model can predict and automatically output the best cloning strategy according to the current input environment status, user needs and specific conditions. Through the embodiments of the present invention, the performance of virtual machine cloning technology in terms of intelligence and automation is effectively improved, the efficiency of the operation process is significantly enhanced, and the need for manual intervention is significantly reduced, reducing the probability of human error.
[0156] 2. In response to the challenge of the complexity of virtual machine state information, the present invention introduces a self-attention mechanism, which allows the model to capture long-term dependencies in the input state, so as to more accurately understand and characterize the complex state of the virtual machine. By using the weighted information vector obtained by the self-attention mechanism as the input of the reinforcement learning model for training, it is possible to accurately predict the prediction and configuration parameters in the virtual machine cloning process. In addition, through learning and feedback from interactions with the environment, intelligent cloning strategy selection and configuration adjustment are achieved, which significantly improves the efficiency and performance of the cloning operation. Through the embodiments of the present invention, not only the decision-making process of the virtual machine cloning technology is optimized, but also an efficient and adaptive solution is provided for resource management in highly dynamic and complex virtualized environments.
[0157] 3. The present invention reduces the need for manual operation through the automated cloning process. The user interface simplifies the operation process, allowing non-professional users to easily manage and perform complex cloning tasks.
[0158] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0159] Reference Figure 5 , shows a schematic diagram of the structure of a virtual machine cloning device provided by some embodiments of the present invention, which may specifically include the following modules:
[0160] The current state data and configuration data acquisition module 501 is used to acquire the current state data of the target virtual machine to be cloned and the configuration data input by the user;
[0161] A target cloning strategy generating module 502 is used to generate a target cloning strategy for the target virtual machine according to the current state data and configuration data through a pre-trained virtual machine cloning network model;
[0162] A constraint condition detection module 503 is used to detect whether the target cloning strategy satisfies the constraint condition; wherein the constraint condition includes the restriction condition of the resources required by the target cloning strategy;
[0163] The cloning operation execution module 504 is used to perform a cloning operation on the target virtual machine according to the target cloning policy when the target cloning policy meets the constraint condition.
[0164] In some embodiments of the present invention, it is also used for:
[0165] When the cloning operation does not satisfy the constraint condition, the target cloning policy is adjusted, and the cloning operation is performed on the target virtual machine according to the adjusted target cloning policy.
[0166] In some embodiments of the present invention, before obtaining the current state data of the target virtual machine to be cloned and the configuration data input by the user, it is also used to:
[0167] Get virtual machine clone history data;
[0168] Generate an initial state vector arranged in chronological order according to the virtual machine clone historical data;
[0169] Generate a key state vector according to the initial state vector through a self-attention mechanism;
[0170] The key state vector is used to train a preset virtual machine clone network model.
[0171] In some embodiments of the present invention, generating a key state vector according to the initial state vector by a self-attention mechanism includes:
[0172] Extracting a key query vector and a corresponding key vector and value vector from the initial state vector through a self-attention mechanism;
[0173] Calculating an attention score based on the key query vector and the corresponding key vector;
[0174] Calculate the probability weight corresponding to the key vector according to the attention score;
[0175] The value vectors are weighted and summed according to the probability weights to obtain a weighted value vector, so as to determine the key state vector according to the weighted value vector.
[0176] In some embodiments of the present invention, extracting a key query vector and a corresponding key vector and value vector from the initial state vector includes:
[0177] Initialize the weight matrix and bias terms;
[0178] According to the weight matrix and the bias term, the initial state vector is linearly transformed to obtain a key query vector and a corresponding key vector and value vector.
[0179] In some embodiments of the present invention, calculating the attention score according to the key query vector and the corresponding key vector includes:
[0180] For each key query vector, calculating a dot product of the key query vector and the key vector;
[0181] The dot product is scaled to obtain an attention score matrix.
[0182] In some embodiments of the present invention, the virtual machine clone network model includes a primary network and a target network, and the adopting of the key state vector to train the preset virtual machine clone network model includes:
[0183] Through the main network in the preset virtual machine clone network model, according to the key state vector, select the action related to the virtual machine clone, and determine the predicted evaluation value according to the key state vector, the action, the reward of the action, and the new state vector obtained after executing the action;
[0184] The target network in the preset virtual machine clone network model is cloned, and the target evaluation value is determined according to the key state vector, the action, the reward of the action, and the new state vector obtained after the action is executed;
[0185] According to the difference between the predicted evaluation value and the target evaluation value, the parameters of the virtual machine clone network model are updated to train the virtual machine clone network model.
[0186] Some embodiments of the present invention further provide an electronic device, comprising a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the above method is implemented when the computer program is executed by the processor.
[0187] Some embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the above method is implemented.
[0188] Some embodiments of the present invention further provide a computer program product, including a computer program, which implements the above method when executed by a processor.
[0189] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0190] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0191] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0192] Those skilled in the art will appreciate that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0193] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.
[0194] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0195] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0196] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0197] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the above elements.
[0198] The method, device, electronic device and medium for cloning a virtual machine provided are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for cloning a virtual machine, characterized in that: The method comprises: Obtaining the current state data of the target virtual machine to be cloned and the configuration data input by the user; Generate a target cloning strategy for the target virtual machine according to the current state data and configuration data by using a pre-trained virtual machine cloning network model; Detecting whether the target cloning strategy satisfies constraint conditions; wherein the constraint conditions include restriction conditions on resources required by the target cloning strategy; When the target cloning policy satisfies the constraint condition, the target virtual machine is cloned according to the target cloning policy.
2. The method according to claim 1, characterized in that Also includes: When the cloning operation does not satisfy the constraint condition, the target cloning policy is adjusted, and the cloning operation is performed on the target virtual machine according to the adjusted target cloning policy.
3. The method according to claim 1 or 2, characterized in that: Before obtaining the current state data of the target virtual machine to be cloned and the configuration data input by the user, the method further includes: Get virtual machine clone history data; Generate an initial state vector arranged in chronological order according to the virtual machine clone historical data; Generate a key state vector according to the initial state vector through a self-attention mechanism; The key state vector is used to train a preset virtual machine clone network model.
4. The method according to claim 3, characterized in that The step of generating a key state vector according to the initial state vector through the self-attention mechanism includes: Extracting a key query vector and a corresponding key vector and value vector from the initial state vector through a self-attention mechanism; Calculating an attention score based on the key query vector and the corresponding key vector; Calculate the probability weight corresponding to the key vector according to the attention score; The value vectors are weighted and summed according to the probability weights to obtain a weighted value vector, so as to determine the key state vector according to the weighted value vector.
5. The method according to claim 4, characterized in that The step of extracting a key query vector and a corresponding key vector and value vector from the initial state vector includes: Initialize the weight matrix and bias terms; According to the weight matrix and the bias term, the initial state vector is linearly transformed to obtain a key query vector and a corresponding key vector and value vector.
6. The method according to claim 4, characterized in that The calculating the attention score according to the key query vector and the corresponding key vector includes: For each key query vector, calculating a dot product of the key query vector and the key vector; The dot product is scaled to obtain an attention score matrix.
7. The method according to claim 3, characterized in that The virtual machine clone network model includes a main network and a target network, and the key state vector is used to train the preset virtual machine clone network model, including: Through the main network in the preset virtual machine clone network model, according to the key state vector, select the action related to the virtual machine clone, and determine the predicted evaluation value according to the key state vector, the action, the reward of the action, and the new state vector obtained after executing the action; The target network in the preset virtual machine clone network model is cloned, and the target evaluation value is determined according to the key state vector, the action, the reward of the action, and the new state vector obtained after the action is executed; According to the difference between the predicted evaluation value and the target evaluation value, the parameters of the virtual machine clone network model are updated to train the virtual machine clone network model.
8. A device for cloning a virtual machine, characterized in that: The device comprises: A current state data and configuration data acquisition module, used to acquire the current state data of the target virtual machine to be cloned and the configuration data input by the user; A target cloning strategy generation module, used to generate a target cloning strategy for the target virtual machine according to the current state data and configuration data through a pre-trained virtual machine cloning network model; A constraint condition detection module, used to detect whether the target cloning strategy satisfies the constraint condition; wherein the constraint condition includes the restriction condition of the resources required by the target cloning strategy; The cloning operation execution module is used to perform a cloning operation on the target virtual machine according to the target cloning strategy when the target cloning strategy meets the constraint condition.
9. An electronic device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the method according to any one of claims 1 to 7 when executed by the processor.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.