Resource allocation method and device, electronic equipment and computer readable storage medium

By adding computing time for the target virtual machine in the cloud computing environment and allocating CPU resources based on the token bucket algorithm, the problem of unfair CPU allocation of virtual switches is solved, and a more fair and efficient virtual machine resource allocation is achieved.

CN119906685APending Publication Date: 2025-04-29BEIJING BAIDU NETCOM SCI & TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411875661.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-18
Publication Date
2025-04-29

AI Technical Summary

Technical Problem

In the cloud computing environment, multiple user virtual machines of different specifications are deployed on the same host, resulting in unfair allocation of CPU cores of virtual switches, and traditional speed limiting methods cannot effectively solve this problem.

Method used

By obtaining the packet sequence of the target virtual machine, calculate its new operation time, and add it to the remaining time in the token bucket as the operation time. Based on the processing time of the single message last processed, the number of preprocessed messages is calculated, and the forwarding time is recorded based on the number of forwarding messages, and the difference between the calculation time and the forwarding time is added to the token bucket as the remaining time.

Benefits of technology

The fairness of the operation time allocation of the target virtual machine is achieved, effectively limiting the virtual machine to occupy the virtual switch CPU, and improving the fairness of virtual machine resource allocation and equipment operation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119906685A_ABST
    Figure CN119906685A_ABST
Patent Text Reader

Abstract

The invention provides a resource allocation method and device, and relates to the technical field of computers, in particular to the technical field of cloud computing and the like. According to the specific implementation scheme, the method comprises the steps of obtaining a current message sequence of a target virtual machine; calculating the newly added operation time of the target virtual machine, and adding the newly added operation time and the last remaining time in the token bucket to serve as the current operation time to be added into the token bucket; calculating the number of preprocessed messages corresponding to the current operation time based on the processing time of processing a single message last time; forwarding the messages in the message sequence based on the number of the preprocessed messages, and recording the forwarding time of the messages; and the difference value between the current operation time and the forwarding time is used as the current remaining time, and the current remaining time is added into the token bucket, so that the fairness of virtual machine resource allocation is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the computer field, specifically to technical fields such as cloud computing, and in particular to a resource allocation method and device, an electronic device, a computer-readable storage medium, and a computer program product. Background Art

[0002] In cloud computing services, multiple user virtual machines of different specifications may be deployed on the same host. The CPU (Central Processing Unit) cores allocated to virtual switches are limited. Virtual switches use BPS (bytes per second) and PPS (packets per second) to limit user services, and limit the number of virtual machine sessions that virtual switches support and manage by the number of connections. However, BPS, PPS and connection number limits cannot achieve fairness in virtual machine CPU allocation. Summary of the invention

[0003] The present disclosure provides a resource allocation method and apparatus, an electronic device, a computer-readable storage medium, and a computer program product.

[0004] According to the first aspect, a resource allocation method is provided, which includes: obtaining the current message sequence of the target virtual machine; calculating the newly added operation time of the target virtual machine, and adding the newly added operation time and the last remaining time in the token bucket as the current operation time to the token bucket; based on the processing time of the last processing of a single message, calculating the number of pre-processed messages corresponding to the current operation time; based on the number of pre-processed messages, forwarding the messages in the current message sequence, and recording the forwarding time of the messages; taking the difference between the current operation time and the forwarding time as the current remaining time, and adding the current remaining time to the token bucket.

[0005] According to the second aspect, a resource allocation device is provided, which includes: an acquisition unit, configured to acquire the current message sequence of the target virtual machine; a new calculation unit, configured to calculate the new operation time of the target virtual machine, and add the new operation time and the last remaining time in the token bucket as the current operation time to the token bucket; a quantity calculation unit, configured to calculate the number of pre-processed messages corresponding to the current operation time based on the processing time of the last processing of a single message; a forwarding unit, configured to forward the messages in the current message sequence based on the number of pre-processed messages, and record the forwarding time of the messages; a result calculation unit, configured to use the difference between the current operation time and the forwarding time as the current remaining time, and add the current remaining time to the token bucket.

[0006] According to a third aspect, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in any implementation manner of the first aspect.

[0007] According to a fourth aspect, a non-transitory computer-readable storage medium storing computer instructions is provided, where the computer instructions are used to cause a computer to execute the method described in any implementation of the first aspect.

[0008] According to a fifth aspect, a computer program product is provided, comprising a computer program, which implements the method described in any implementation manner of the first aspect when executed by a processor.

[0009] The resource allocation method and device provided by the embodiment of the present disclosure first obtain the current message sequence of the target virtual machine; secondly, calculate the newly added operation time of the target virtual machine, and add the newly added operation time and the last remaining time in the token bucket as the current operation time to the token bucket; thirdly, based on the processing time of the last processing of a single message, calculate the number of pre-processed messages corresponding to the current operation time; then, based on the number of pre-processed messages, forward the messages in the current message sequence, and record the forwarding time of the messages; finally, take the difference between the current operation time and the forwarding time as the current remaining time, and add the current remaining time to the token bucket. Thus, by calculating the newly added operation time for the target virtual machine, allocating each operation time to the target virtual machine, and forwarding the message to the target virtual machine according to each operation time, the CPU occupied by the target virtual machine can be effectively limited, and the fairness of virtual machine resource allocation is improved.

[0010] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0012] Figure 1 is a flow chart of an embodiment of a resource allocation method according to the present disclosure;

[0013] Figure 2 is a flow chart of another embodiment of the resource allocation method according to the present disclosure;

[0014] Figure 3 It is a structural schematic diagram of an implementation process of the resource allocation method disclosed in the present invention;

[0015] Figure 4 is a timing diagram of data processing in a cycle of the present disclosure;

[0016] Figure 5 It is a structural diagram of an implementation result of the resource allocation method disclosed in the present invention;

[0017] Figure 6 is a structural diagram of another implementation result of the resource allocation method disclosed in the present invention;

[0018] Figure 7 is a structural schematic diagram of an embodiment of a resource allocation device according to the present disclosure;

[0019] Figure 8 It is a block diagram of an electronic device used to implement the resource allocation method according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0020] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0021] Existing virtual switches usually have two forwarding modes, slow path and fast path. The fast path is used for regular and efficient packet forwarding, usually supported by hardware acceleration and caching mechanisms, and has a fast processing speed. The slow path is used for abnormal and control traffic processing or first traffic identification, and has a slower processing speed. In the virtual switch software forwarding model, the fast and slow paths are mixed, and the long connection and short connection processing occupy different forwarding CPUs. For example, a virtual switch product has a long connection specification of 12Mpps and a short connection of only 1.2Mpps. The slow path and fast path occupy a CPU ratio of 10:1. In the scenario with short connection services, the service of Qvo1-queue1 corresponding to virtual machine 1 is a short connection, and other services of the host are long connections. Because pmd consumes too much CPU to process short connections, the actual virtual machine 1 occupies 60%+ of the CPU processing power of the current pmd core, while other virtual machines can only occupy 40%. When a host deploys multiple virtual machines, one of which is a small-sized virtual machine that mainly provides short-connection services. Under the BPS and PPS specifications limited by QoS (Quality of Service), it can also occupy most of the CPU of the forwarding thread. The waiting time for polling the virtual network card queues of other virtual machines becomes longer, resulting in longer service delays for other virtual machines. It also causes congestion and packet loss in the physical network card queue, resulting in service damage.

[0022] In view of the defects in the traditional technology, the present invention proposes a resource allocation method. Figure 1 A process 100 according to an embodiment of a resource allocation method of the present disclosure is shown. The resource allocation method comprises the following steps:

[0023] Step 101, obtaining the current message sequence of the target virtual machine.

[0024] In this embodiment, the execution subject on which the resource allocation method runs can be a virtual switch (VirtualSwitch). The virtual switch is a key component of software-defined network technology, which can create and manage virtual local area networks in a virtualized environment, isolate network traffic, and achieve functions such as load balancing. The virtual switch can create multiple virtual local area networks by configuring and managing in a server cluster, and limit the communication between virtual machines to a specific virtual network, thereby achieving isolation and barriers to network traffic; the virtual switch in the cloud network can virtualize the functions of the physical switch and divide a physical switch into multiple logical switches to meet the needs of multiple tenants; the virtual switch can achieve isolation between different virtual machines and avoid communication interference and security issues between different virtual machines. The virtual switch can control and manage the network traffic between different virtual machines to ensure the smoothness and stability of network traffic.

[0025] In this embodiment, the target virtual machine is any one of the multiple virtual machines managed by the virtual switch. For example, the virtual switch manages five virtual machines. When a message of any one of the five virtual machines needs to be processed, the virtual machine is used as the target virtual machine.

[0026] In this embodiment, the execution entity on which the resource allocation method runs will process the messages of each virtual machine on the host in turn, and can obtain the message sequence from the network card or virtual network card of the virtual machine. For the target virtual machine, the message sequence of the target virtual machine can be directly obtained from the network card or virtual network card of the target virtual machine.

[0027] In this embodiment, in cloud computing, a host may have multiple virtual machines of different specifications and a virtual switch for managing the virtual machines, and each virtual machine has a corresponding network card or a virtual network card for receiving messages.

[0028] In this embodiment, the execution subject on which the resource allocation method runs traverses the virtual machine network card or virtual network card connected to it as a cycle. In the current cycle, when the execution subject on which the resource allocation method runs traverses to the target virtual machine and obtains the message sequence of the network card or virtual network card of the target virtual machine, the obtained message sequence is used as the message sequence for this time.

[0029] In the technical solution disclosed herein, the collection, storage, use, processing, transmission, provision and disclosure of the message sequence involved are carried out after authorization, comply with the provisions of relevant laws and regulations, and do not violate public order and good morals.

[0030] Step 102, calculate the newly added operation time of the target virtual machine, and add the newly added operation time and the last remaining time in the token bucket as the current operation time and add it into the token bucket.

[0031] In this embodiment, the execution subject on which the resource allocation method runs takes a forwarding thread to traverse the network card queue for a cycle. When processing the message sequence of the virtual machine in the cycle cycle, the waiting time of the target virtual machine (the virtual machine currently to be processed) is multiplied by the proportion of the default specification of the target virtual machine in the host to obtain the target virtual machine's newly added computing time, wherein the default specification can be the specification of the target virtual machine package sold, which is generally formulated according to the virtual machine CPU core and memory. For example, a physical machine actually has 64 CPU cores that can be sold; if a 32CPU virtual machine is purchased, it can occupy 50% of the virtual switch CPU resources, and if a 16CPU virtual machine is purchased, it can occupy 25% of the virtual switch CPU resources.

[0032] In this embodiment, the current operation time is the message processing time that can be allocated to the target virtual machine in this cycle. The current operation time is related to the newly added operation time and the last remaining time, wherein the last remaining time is the remaining time of the message in the last message sequence forwarded for the target virtual machine in the last cycle. There are three possibilities for the last remaining time. One possibility is that the forwarding time of the last forwarded message is longer than the last operation time, that is, the last forwarding time is greater than the last operation time, in which case the last remaining time is recorded as a negative value, another possibility is that the forwarding time of the last forwarded message is shorter than the last operation time, that is, the last forwarding time is less than the last operation time, in which case the last remaining time is recorded as a positive value, and another possibility is that the forwarding time of the last forwarded message is equal to the last operation time, in which case the last remaining time is recorded as zero. Among them, the forwarding time is the time for the execution subject on which the resource allocation method runs to actually forward the message in the message sequence of the target virtual machine in one cycle.

[0033] In this embodiment, the remaining time of the target virtual machine in each cycle is stored in a token bucket, and the remaining time of the current cycle relative to the previous week can be obtained in real time through the token bucket. The calculated additional operation time is added to the remaining time of the previous week to obtain the current operation time, and the current operation time is added to the token bucket. The token bucket can be used to determine the time for processing messages that can be allocated to the target virtual machine in the current cycle.

[0034] In this embodiment, the token bucket is a token bucket algorithm specially set for the present disclosure, which is completely different from the conventional token bucket algorithm. The conventional token bucket algorithm calculates the actual released traffic volume by the number of bytes and messages, while this algorithm needs to estimate the current operation time by the remaining time of the previous time in history.

[0035] Step 103, based on the processing time of the last processing of a single message, the number of pre-processed messages corresponding to the current operation time is calculated.

[0036] In this embodiment, the processing time of a single message is the time taken by the execution entity on which the resource allocation method runs to forward a message. For some fixed scenarios, the time taken for each processing of a message of the same virtual machine is close, and a preset value can be used as the processing time of a single message, wherein the preset value can be the time obtained by recording the forwarding time of a single message.

[0037] In this embodiment, the number of pre-processed messages is the number of messages that can be forwarded in the time allocated to the target virtual machine in the current cycle, and the current operation time can be directly divided by the processing time of the last processing of a single message to obtain the number of pre-processed texts. Optionally, it is also possible to detect whether the current operation time is an integer multiple of the processing time of the last processing of a single message; in response to detecting that the current operation time is an integer multiple of the processing time of the last processing of a single message, the current operation time is divided by the processing time of the last processing of a single message to obtain the number of pre-processed texts; in response to detecting that the current operation time is not an integer multiple of the processing time of the last processing of a single message, the current operation time is adjusted by adding or subtracting a preset value, and the adjusted value is divided by the processing time of the last processing of a single message to obtain the number of pre-processed messages.

[0038] Step 104: forward the messages in the current message sequence based on the number of pre-processed messages, and record the forwarding time of the messages.

[0039] In this embodiment, the number of messages actually forwarded in the message sequence may be equal to the number of pre-processed messages, or may be less than the number of pre-processed messages, and the forwarding time is the time of actually forwarding the messages in the message sequence.

[0040] The above step 104 includes: in response to the number of pre-processed messages being less than the number of messages in the current message sequence, forwarding the messages of the number of pre-processed messages in the current message sequence to the network card or virtual network card of the target virtual machine, and recording the forwarding time of the messages. The forwarding time is the time from the start of forwarding the first message of the number of pre-processed messages in the message sequence to the last message.

[0041] Step 105: The difference between the current operation time and the forwarding time is taken as the current remaining time, and the current remaining time is added to the token bucket.

[0042] In this embodiment, the remaining time is the allocated time remaining relative to the current operation time after forwarding the messages in the current message sequence, and the specific value of the remaining time can be a positive value, a negative value, or zero. When the specific value of the remaining time is a positive value, it means that there is time remaining in the current operation time relative to the forwarding time of the actual forwarded message; when the specific value of the remaining time is a negative value, it means that there is no time remaining in the current operation time relative to the forwarding time of the actual forwarded message; when the specific value of the remaining time is zero, it means that the current operation time is equal to the forwarding time of the actual forwarded message.

[0043] In this embodiment, the remaining time of this time is added to the token bucket to provide a time basis for calculating the next operation time for forwarding messages for the target virtual machine next time, that is, in the next cycle.

[0044] The resource allocation method provided by the embodiment of the present disclosure first obtains the current message sequence of the target virtual machine; secondly, calculates the newly added operation time of the target virtual machine, and adds the newly added operation time and the last remaining time in the token bucket as the current operation time to the token bucket; thirdly, based on the processing time of the last processing of a single message, calculates the number of pre-processed messages corresponding to the current operation time; then, based on the number of pre-processed messages, forwards the messages in the current message sequence, and records the forwarding time of the messages; finally, takes the difference between the current operation time and the forwarding time as the current remaining time, and adds the current remaining time to the token bucket. Thus, the operation time of each virtual machine is fairly allocated for the virtual switch, virtual machines of different specifications are treated fairly, and the operation efficiency of the equipment is improved; by calculating the newly added operation time for the target virtual machine, allocating each operation time for the target virtual machine, and forwarding messages to the target virtual machine according to each operation time, the CPU occupied by the target virtual machine can be effectively limited, and the fairness of virtual machine resource allocation is improved.

[0045] Figure 2 A process 200 according to another embodiment of a resource allocation method of the present disclosure is shown. The resource allocation method comprises the following steps:

[0046] Step 201, obtain the current message sequence of the target virtual machine, and then execute step 202.

[0047] Step 202 , calculate the newly added operation time of the target virtual machine, and add the newly added operation time and the last remaining time in the token bucket as the current operation time and add it into the token bucket, then execute step 203 .

[0048] Step 203 , based on the processing time of the last processing of a single message, calculate the number of pre-processed messages corresponding to the current operation time, and then execute step 204 .

[0049] Step 204 , forwarding the messages in the current message sequence based on the number of pre-processed messages, and recording the forwarding time of the messages, and then executing step 205 .

[0050] Step 205 , taking the difference between the current operation time and the forwarding time as the current remaining time, and then executing step 206 .

[0051] It should be understood that the operations and features in the above steps 201 to 205 correspond to the operations and features in steps 101 to 105, respectively. Therefore, the above descriptions of the operations and features in steps 101 to 105 are also applicable to steps 201 to 205 and will not be repeated here.

[0052] Step 206, detect whether the remaining time of this time is less than the time threshold; if it is detected that the remaining time of this time is less than the time threshold, then execute step 207; if it is detected that the remaining time of this time is greater than or equal to the time threshold, then execute step 208.

[0053] In this embodiment, the time threshold is a threshold set for the remaining time of each cycle or each time. The specific value of the time threshold can be set based on development requirements, or the specific value of the time threshold is based on empirical values ​​obtained from multiple experiments.

[0054] In this embodiment, when it is detected that the remaining time of this time is greater than or equal to the time threshold, it is determined that the remaining time of this time is unreliable or unavailable time, and it is necessary to set the remaining time of this time based on the time threshold.

[0055] Step 207: Use the current remaining time to replace the previous remaining time in the token bucket.

[0056] Step 208: Use the time threshold to replace the last remaining time in the token bucket.

[0057] The resource allocation method provided in this embodiment detects whether the current remaining time is less than the time threshold after obtaining the current remaining time; in response to detecting that the current remaining time is less than the time threshold, the current remaining time is used to replace the previous remaining time in the token bucket; in response to detecting that the current remaining time is greater than or equal to the time threshold, the time threshold is used to replace the previous remaining time in the token bucket, which provides a reliable implementation basis for obtaining the current remaining time and improves the reliability of obtaining the previous remaining time.

[0058] In some optional implementations of the present disclosure, the above method also includes: obtaining the processing time of processing a single message this time based on the forwarding time and the number of pre-processed messages; and replacing the processing time of processing a single message last time with the processing time of processing a single message this time.

[0059] In this embodiment, the forwarding time can be directly divided by the number of pre-processed messages to obtain the processing time of a single message processed this time. The processing time of a single message processed this time is used to replace the processing time of a single message processed last time. This can provide a reliable time basis for the next cycle or the next calculation of the number of pre-processed messages corresponding to the next operation time.

[0060] The resource allocation method provided in this embodiment obtains the processing time of a single message processed this time based on the forwarding time and the number of pre-processed messages; the processing time of a single message processed this time is used to replace the processing time of a single message processed last time, which provides a reliable basis for calculating the number of pre-processed messages in the next cycle, improves the reliability of resource allocation, and improves the fairness of the CPU of the virtual switch of each virtual machine.

[0061] In some optional implementations of the present disclosure, the above-mentioned forwarding of messages in the current message sequence based on the number of pre-processed messages and recording the forwarding time of the messages includes: forwarding the messages in the current message sequence in real time, and recording the number and time of forwarded messages; detecting whether the number of forwarded messages reaches the number of pre-processed messages; in response to detecting that the number of forwarded messages does not reach the number of pre-processed messages, detecting whether there are any unforwarded messages in the current message sequence; in response to detecting that there are no unforwarded messages in the current message sequence, using the time of the forwarded messages as the forwarding time.

[0062] In this optional implementation, the forwarded message is the message that has been sent to the network card or virtual network card of the target virtual machine in this message sequence. When forwarding the message, the number and time of the forwarded message are recorded in real time to obtain the number of forwarded messages.

[0063] In this optional implementation, the unforwarded message is a message that is not sent to the network card or virtual network of the target virtual machine in this message sequence.

[0064] The method for forwarding messages in the current message sequence provided by this optional implementation forwards the messages in the current message sequence in real time, and records the number and time of forwarded messages; detects whether the number of forwarded messages reaches the pre-processed message number; in response to detecting that the number of forwarded messages does not reach the pre-processed message number, detects whether there are any unforwarded messages in the current message sequence; in response to detecting that there are no unforwarded messages in the current message sequence, uses the time of the forwarded message as the forwarding time, which provides a reliable implementation method for obtaining the forwarding time and improves the reliability of obtaining the forwarding time.

[0065] Optionally, the above-mentioned forwarding of the messages in the current message sequence based on the number of preprocessed messages and recording the forwarding time of the messages includes: detecting whether the number of messages in the current message sequence is the same as the number of preprocessed messages; in response to detecting that the number of messages in the current message sequence is different from the number of preprocessed messages, detecting whether the number of messages in the current message sequence is greater than the number of preprocessed messages; in response to detecting that the number of messages in the current message sequence is greater than the number of preprocessed messages, selecting and forwarding the number of preprocessed messages in the current message sequence.

[0066] In some optional implementations of the present disclosure, the above-mentioned forwarding of messages in the current message sequence based on the number of preprocessed messages and recording the forwarding time of the messages includes: in response to detecting that the number of forwarded messages has reached the number of preprocessed messages, taking the time of the forwarded messages as the forwarding time.

[0067] The method for obtaining the forwarding time provided by this optional implementation method, in response to detecting that the number of forwarded messages has reached the number of pre-processed messages, uses the time of the forwarded message as the forwarding time, providing another reliable implementation method for obtaining the forwarding time and improving the reliability of obtaining the forwarding time.

[0068] In some optional implementations of the present disclosure, the above-mentioned forwarding of messages in the current message sequence based on the number of pre-processed messages and recording the forwarding time of the messages includes: in response to detecting that there are still unforwarded messages in the current message sequence, continuing to forward the messages in the current message sequence in real time, and recording the number and time of forwarded messages; until it is detected that there are no unforwarded messages in the current message sequence, or it is detected that the number of forwarded messages reaches the number of pre-processed messages.

[0069] In this optional implementation, when it is detected that there is no unforwarded message in the current message sequence, or when it is detected that the number of forwarded messages reaches the pre-processed message number, the forwarding time of the current forwarded message is used as the forwarding time.

[0070] The method for obtaining the forwarding time provided by this optional implementation mode, in response to detecting that there are still unforwarded messages in the current message sequence, continues to forward the messages in the current message sequence in real time, and records the number and time of the forwarded messages; until it is detected that there are no unforwarded messages in the current message sequence, or it is detected that the number of forwarded messages reaches the pre-processed message number, providing another reliable implementation method for obtaining the forwarding time, and improving the reliability of obtaining the forwarding time.

[0071] In some optional implementations of the present disclosure, the above-mentioned calculation of the additional computing time of the target virtual machine includes: calculating the resource ratio of the target virtual machine; calculating the time difference between the time point of forwarding the message of the target virtual machine this time and the time point of forwarding the message of the target virtual machine last time; and taking the product of the resource ratio and the time difference as the additional computing time of the target virtual machine.

[0072] In this optional implementation, the resource ratio is the ratio of the CPU resources of the execution subject on which the resource allocation method runs that are occupied by the virtual machine. The resource ratio can be calculated by the number of data packets per second of the virtual machine connected to the execution subject.

[0073] In this optional implementation, the time difference between the time point of forwarding the target virtual machine's message this time and the time point of forwarding the target virtual machine's message last time is the CPU clock difference between the network card port of the target virtual machine in the last cycle and the network port of the target virtual machine in this cycle.

[0074] The method for obtaining the newly added computing time provided by this optional implementation calculates the resource ratio of the target virtual machine; calculates the time difference between the time point of forwarding the message of the target virtual machine this time and the time point of forwarding the message of the target virtual machine last time; and uses the product of the resource ratio and the time difference as the newly added computing time of the target virtual machine, thereby improving the accuracy of the newly added computing calculation.

[0075] Optionally, the above calculation of the additional computing time of the target virtual machine includes: calculating the time difference between the time point of forwarding the message of the target virtual machine this time and the time point of forwarding the message of the target virtual machine last time; and taking the product of the fixed resource ratio of the target virtual machine and the time difference as the additional computing time of the target virtual machine. The resource ratio of the target virtual machine is determined based on a default rule.

[0076] In this optional implementation, the proportion of virtual switch CPU resources that can be used by the virtual network port corresponding to each virtual machine is first obtained through the specifications of the currently deployed virtual machines, and then the CPU clock difference between the network port in the previous cycle and the network port in this cycle is used to calculate the additional computing time during this period through the clock difference and the proportion.

[0077] Optionally, the above calculation of the additional computing time of the target virtual machine includes: dynamically allocating the resource ratio of the target virtual machine according to the number of virtual machines deployed on the current host; calculating the time difference between the time point of forwarding the message of the target virtual machine this time and the time point of forwarding the message of the target virtual machine last time; and taking the product of the resource ratio of the above target virtual machine and the time difference as the additional computing time of the target virtual machine. In the previous scenario, if the current physical machine only deploys a 16-CPU virtual machine, it can occupy 100% of the virtual switch CPU resources. If a new 32-CPU virtual machine is deployed, the virtual switch CPU resource allocation becomes 33%:66%.

[0078] In some optional implementations of the present disclosure, the above-mentioned calculation of the resource ratio of the target virtual machine includes: calculating the sum of the number of data packets transmitted per second by all virtual machines on the physical machine to obtain the sum of the number of data packets; dividing the number of data packets transmitted per second by the target virtual machine by the sum of the number of data packets to obtain the resource ratio of the target virtual machine.

[0079] The method for calculating resource ratio provided by this optional implementation method calculates the sum of the number of data packets transmitted per second by all virtual machines on the physical machine to obtain the sum of the number of data packets; divides the number of data packets transmitted per second by the target virtual machine by the sum of the number of data packets to obtain the resource ratio of the target virtual machine, providing a reliable implementation method for obtaining the resource ratio and improving the reliability and accuracy of obtaining the resource ratio.

[0080] In some optional implementations of the present disclosure, the above-mentioned calculation of the resource ratio of the target virtual machine includes: determining the maximum number of data packets transmitted per second on the physical machine; dividing the number of data packets transmitted per second of the target virtual machine by the maximum number of data packets transmitted per second to obtain the resource ratio of the target virtual machine.

[0081] The method for calculating resource ratio provided by this optional implementation method determines the maximum number of data packets transmitted per second on the physical machine; the number of data packets transmitted per second of the target virtual machine is divided by the maximum number of data packets transmitted per second to obtain the resource ratio of the target virtual machine, providing another reliable implementation method for obtaining the resource ratio, thereby improving the reliability and accuracy of obtaining the resource ratio.

[0082] In some optional implementations of the present disclosure, the above-mentioned calculation of the number of pre-processed messages corresponding to the current operation time based on the processing time of the last processing of a single message includes: calculating the ratio of the current operation time to the processing time of the last processing of a single message, and obtaining the number of pre-processed messages.

[0083] In this optional implementation, the current operation time is directly divided by the processing time of the last processing of a single message to obtain the number of pre-processed messages.

[0084] This optional implementation provides a method for calculating the number of pre-processed messages corresponding to the current operation time, calculating the ratio of the current operation time to the processing time of the last processing of a single message, and obtaining the number of pre-processed messages. The number of pre-processed messages is obtained simply and reliably, thereby improving the reliability of obtaining the number of pre-processed messages.

[0085] In a specific example of the present disclosure, virtual machines vm1, vm2, and vm3 are deployed according to the default CPU usage ratio 1, ratio 2, and ratio 3 according to the specifications, and the forwarding thread of the virtual switch jh (the execution subject on which the resource allocation method of the present disclosure runs) traverses the network card queue for one cycle as a cycle ( Figure 3 The resource allocation method disclosed in the present invention is performed on the target virtual machine (which can be any one of the above virtual machines vm1, vm2, and vm3), and the following is performed by Figure 3 A schematic diagram of an implementation process of the resource allocation method disclosed in the present invention is shown. Figure 4 The data processing timing diagram in one cycle of the present disclosure is shown, Figure 5 A structural diagram showing an implementation result of the resource allocation method disclosed in the present invention, Figure 6 FIG. 1 is a schematic diagram showing another implementation result of the resource allocation method of the present disclosure, and describes the resource allocation method of the present disclosure in detail:

[0086] Step 1: In the current cycle (such as Figure 3 In loop2), the virtual switch jh controls the current message sequence in the virtual queue to be dequeued, such as Figure 4 The virtual switch jh controls the virtual queue to dequeue the message corresponding to the current message sequence.

[0087] Step 2: For the target virtual machine, for example, virtual machine vm1, the virtual switch jh calculates the newly added computing time by obtaining the difference between vm1 and the last processing time and adds it to the token bucket vm-cpu-cir of the target virtual machine, such as Figure 4 , calculate the additional computing time.

[0088] Step 3, the virtual switch jh gets the previous cycle (such as Figure 3 The processing time of the last single message processed by the virtual machine queue in loop 1) shown in , and the number of pre-processed messages corresponding to this operation time are estimated.

[0089] Step 4: The virtual switch jh pre-allocates tokens from the token bucket vm-cpu-cir to determine how many packets it can process, that is, the number of pre-processed messages, such as Figure 4 , calculate the number of pre-processed messages.

[0090] Step 5: The virtual switch jh controls the message sequence to be forwarded through the message forwarding module according to the forwarding process, such as Figure 4 In the process, the virtual switch jh controls the message forwarding module, so that the message forwarding module follows the message forwarding process and forwards the current message sequence.

[0091] Step 6: The virtual switch jh controls the remaining packets in this message sequence to be discarded as exceeding the CPU fairness limit. Figure 4 In the process, the virtual switch jh processes the message sequence and discards the remaining packets.

[0092] Step 7: After the forwarding module processes the message, it is added to the outgoing queue of the network card. Figure 4 In the forwarding module, the message is added to the outgoing queue of the network card.

[0093] Step 8: The virtual switch jh obtains the forwarding time zf consumed by this processing and updates the token bucket vm-cpu-cir, such as Figure 4 In , the virtual switch jh calculates the forwarding time.

[0094] Step 9: Update the remaining time of this round of loop2 based on the number of messages processed this time, add the remaining time of this time to the token bucket vm-cpu-cir, and use the remaining time of this time in the next round of loop3 as the remaining time of the previous round to calculate the operation time of the next round, such as Figure 4 In the example, the virtual switch jh calculates the remaining time of this time and puts the calculated remaining time of this time into the token bucket vm-cpu-cir. Figure 5 Based on this method, the virtual switch can accurately limit the virtual machine's occupation of the virtual switch CPU. Before the implementation of the method, the three virtual machines (vm1, vm2, and vm3) have different specifications and deploy the same TCP (Transmission Control Protocol) short connection service. The three hosts occupy the same amount of service on the virtual switch (e.g. Figure 5 After implementing this method, we can see that the business volume of the three virtual machines is limited to the corresponding specification range of the virtual machines (such as Figure 5 The dotted lines of vm1, vm2, and vm3 in Figure 5 In the figure, the ordinate represents PPS and the abscissa represents the test time in seconds.

[0095] like Figure 6 ,Comparison of the packet sending and receiving and packet loss results before and after the virtual machine mixed UDP service scenario, two hosts deploy multiple virtual machines respectively, and the virtual machines use UDP (User Datagram Protocol) services to access each other one by one at the same time, Figure 6For one of the virtual machines, the CPU usage of the virtual switch reached 100%. Due to the precise PPS control, the physical network card receiving capacity increased by 28%, and the packet loss caused by queue congestion at the physical network card receiving end was reduced to 0. Figure 6 In the example, the hx curve represents the PPS curve of the virtual machine before the resource allocation method is adopted, and the nx curve represents the PPS curve of the virtual machine after the resource allocation method is adopted. Figure 6 In the figure, the ordinate represents PPS and the abscissa represents the test time in seconds.

[0096] Further references Figure 7 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a resource allocation device, which is similar to Figure 1 Corresponding to the method embodiment shown, the device can be specifically implemented in various electronic devices.

[0097] like Figure 7 As shown, the resource allocation device 700 provided in this embodiment includes: an acquisition unit 701, a new calculation unit 702, a quantity calculation unit 703, a forwarding unit 704, and a result calculation unit 705. Among them, the acquisition unit 701 is configured to acquire the current message sequence of the target virtual machine. The new calculation unit 702 is configured to calculate the new operation time of the target virtual machine, and add the new operation time and the last remaining time in the token bucket as the current operation time and add the current remaining time to the token bucket. The quantity calculation unit 703 is configured to calculate the number of pre-processed messages corresponding to the current operation time based on the processing time of the last processing of a single message. The forwarding unit 704 is configured to forward the messages in the current message sequence based on the number of pre-processed messages, and record the forwarding time of the messages. The result calculation unit 705 is configured to use the difference between the current operation time and the forwarding time as the current remaining time, and add the current remaining time to the token bucket.

[0098] In this embodiment, in the resource allocation device 700, the specific processing of the acquisition unit 701, the new addition calculation unit 702, the quantity calculation unit 703, the forwarding unit 704, and the result calculation unit 705 and the technical effects thereof can be referred to respectively. Figure 1 The relevant descriptions of step 101, step 102, step 103, step 104, and step 105 in the corresponding embodiments are not repeated here.

[0099] In some optional implementations of the present embodiment, the above-mentioned device 700 also includes: a detection unit (not shown in the figure), and the above-mentioned detection unit is configured to: detect whether the remaining time of this time is less than a time threshold; in response to detecting that the remaining time of this time is less than the time threshold, use the remaining time of this time to replace the last remaining time in the token bucket; in response to detecting that the remaining time of this time is greater than or equal to the time threshold, use the time threshold to replace the last remaining time in the token bucket.

[0100] In some optional implementations of this embodiment, the above-mentioned device 700 also includes: an obtaining unit (not shown in the figure), and the above-mentioned obtaining unit is configured to: obtain the processing time of processing a single message this time based on the forwarding time and the number of pre-processed messages; and use the processing time of processing a single message this time to replace the processing time of processing a single message last time.

[0101] In some optional implementations of the present embodiment, the forwarding unit 704 is configured to: forward the messages in the current message sequence in real time, and record the number and time of the forwarded messages; detect whether the number of forwarded messages reaches the number of pre-processed messages; in response to detecting that the number of forwarded messages does not reach the number of pre-processed messages, detect whether there are any unforwarded messages in the current message sequence; in response to detecting that there are no unforwarded messages in the current message sequence, use the time of the forwarded message as the forwarding time.

[0102] In some optional implementations of this embodiment, the message forwarding unit 704 is further configured to: in response to detecting that the number of forwarded messages has reached the number of pre-processed messages, use the time of the forwarded messages as the forwarding time.

[0103] In some optional implementations of the present embodiment, the message forwarding unit 704 is further configured to: in response to detecting that there are unforwarded messages in the current message sequence, continue to forward the messages in the current message sequence in real time, and record the number and time of forwarded messages; until it is detected that there are no unforwarded messages in the current message sequence, or it is detected that the number of forwarded messages reaches the pre-processed message number.

[0104] In some optional implementations of this embodiment, the above-mentioned newly added computing unit 702 is also configured to: calculate the resource ratio of the target virtual machine; calculate the time difference between the time point of forwarding the message of the target virtual machine this time and the time point of forwarding the message of the target virtual machine last time; and use the product of the resource ratio and the time difference as the newly added computing time of the target virtual machine.

[0105] In some optional implementations of this embodiment, the above-mentioned newly added computing unit 702 is configured to: calculate the sum of the number of data packets transmitted per second by all virtual machines on the physical machine to obtain the sum of the number of data packets; divide the number of data packets transmitted per second by the target virtual machine by the sum of the number of data packets to obtain the resource ratio of the target virtual machine.

[0106] In some optional implementations of this embodiment, the newly added computing unit 702 is configured to: determine the maximum number of data packets transmitted per second on the physical machine; divide the number of data packets transmitted per second of the target virtual machine by the maximum number of data packets transmitted per second to obtain the resource ratio of the target virtual machine.

[0107] In some optional implementations of this embodiment, the above-mentioned quantity calculation unit 703 is configured to: based on the processing time of the last processing of a single message, calculate the number of pre-processed messages corresponding to the current operation time, including: calculating the ratio of the current operation time to the processing time of the last processing of a single message, and obtaining the number of pre-processed messages.

[0108] The resource allocation device provided by the embodiment of the present disclosure, first, the acquisition unit 701 acquires the current message sequence of the target virtual machine; secondly, the new calculation unit 702 calculates the new operation time of the target virtual machine, and adds the new operation time and the last remaining time in the token bucket as the current operation time to the token bucket; thirdly, the number calculation unit 703 calculates the number of pre-processed messages corresponding to the current operation time based on the processing time of the last processing of a single message; then, the forwarding unit 704 forwards the message in the current message sequence based on the number of pre-processed messages, and records the forwarding time of the message; finally, the result calculation unit 705 takes the difference between the current operation time and the forwarding time as the current remaining time, and adds the current remaining time to the token bucket. Thus, the virtual switch obtains a fair allocation of the operation time for each virtual machine, and treats virtual machines of different specifications fairly, thereby improving the operation efficiency of the device; by calculating the new operation time for the target virtual machine, allocating each operation time for the target virtual machine, and forwarding messages to the target virtual machine according to each operation time, the target virtual machine can effectively limit the CPU occupied by the virtual switch, thereby improving the fairness of virtual machine resource allocation.

[0109] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0110] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0111] Figure 8A schematic block diagram of an example electronic device 800 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0112] like Figure 8 As shown, the device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0113] A number of components in the device 800 are connected to the I / O interface 805, including: an input unit 806, such as a keyboard, a mouse, etc.; an output unit 807, such as various types of displays, speakers, etc.; a storage unit 808, such as a disk, an optical disk, etc.; and a communication unit 809, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 809 allows the device 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0114] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as the resource allocation method. For example, in some embodiments, the resource allocation method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the resource allocation method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the resource allocation method in any other appropriate manner (e.g., by means of firmware).

[0115] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0116] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable resource allocation device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0117] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0118] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0119] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an information server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communications network). Examples of communications networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0120] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.

[0121] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0122] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. A resource allocation method, the method comprising: Obtain the current message sequence of the target virtual machine; Calculate the newly added computing time of the target virtual machine, and add the newly added computing time and the last remaining time in the token bucket as the current computing time and add it to the token bucket; Based on the processing time of the last processing of a single message, calculate the number of pre-processed messages corresponding to the current operation time; Based on the number of pre-processed messages, forward the messages in the current message sequence, and record the forwarding time of the messages; The difference between the current operation time and the forwarding time is taken as the current remaining time, and the current remaining time is added to the token bucket.

2. According to the method of claim 1, before adding the remaining time of the current time into the token bucket, the method further comprises: Detect whether the remaining time of this time is less than the time threshold; In response to detecting that the current remaining time is less than the time threshold, replacing the previous remaining time in the token bucket with the current remaining time; In response to detecting that the current remaining time is greater than or equal to the time threshold, the previous remaining time in the token bucket is replaced by the time threshold.

3. The method according to claim 1, further comprising: Based on the forwarding time and the number of pre-processed messages, obtain the processing time of a single message processed this time; The processing time of processing a single message last time is replaced by the processing time of processing a single message this time.

4. The method according to any one of claims 1 to 3, wherein: The forwarding of the messages in the current message sequence based on the number of pre-processed messages, and recording the forwarding time of the messages includes: Forward the messages in the message sequence in real time, and record the number and time of the forwarded messages; Detecting whether the number of the forwarded messages reaches the number of the pre-processed messages; In response to detecting that the number of the forwarded messages does not reach the number of pre-processed messages, detecting whether there are any unforwarded messages in the current message sequence; In response to detecting that there is no unforwarded message in the current message sequence, the time of the forwarded message is used as the forwarding time.

5. The method according to claim 4, wherein: The forwarding of the messages in the current message sequence based on the number of pre-processed messages, and recording the forwarding time of the messages includes: In response to detecting that the number of the forwarded messages has reached the number of pre-processed messages, the time of the forwarded messages is used as the forwarding time.

6. The method according to claim 4, wherein: The forwarding of the messages in the current message sequence based on the number of pre-processed messages, and recording the forwarding time of the messages includes: In response to detecting that there are still unforwarded messages in the current message sequence, continue to forward the messages in the current message sequence in real time, and record the number and time of forwarded messages; until it is detected that there are no unforwarded messages in the current message sequence, or it is detected that the number of forwarded messages reaches the pre-processed message number.

7. The method according to any one of claims 1 to 3, wherein: The calculating the additional computing time of the target virtual machine includes: Calculating the resource ratio of the target virtual machine; Calculate the time difference between the time point of forwarding the message of the target virtual machine this time and the time point of forwarding the message of the target virtual machine last time; The product of the resource ratio and the time difference is used as the newly added computing time of the target virtual machine.

8. The method according to claim 7, wherein: The calculating the resource ratio of the target virtual machine includes: Calculate the sum of the number of data packets transmitted per second by all virtual machines on the physical machine to obtain the sum of the number of data packets; The number of data packets transmitted per second by the target virtual machine is divided by the sum of the number of data packets to obtain the resource ratio of the target virtual machine.

9. The method according to claim 7, wherein: The calculating the resource ratio of the target virtual machine includes: Determine the maximum number of packets transmitted per second on the physical machine; The number of data packets transmitted per second of the target virtual machine is divided by the maximum number of data packets transmitted per second to obtain the resource ratio of the target virtual machine.

10. The method according to any one of claims 1 to 3, wherein: The calculating the number of pre-processed messages corresponding to the current operation time based on the processing time of the last processing of a single message includes: The ratio of the current operation time to the processing time of the last processing of a single message is calculated to obtain the number of pre-processed messages.

11. A resource allocation device, comprising: An acquisition unit, configured to acquire the current message sequence of the target virtual machine; A newly added calculation unit is configured to calculate the newly added computing time of the target virtual machine, and add the newly added computing time and the last remaining time in the token bucket as the current computing time and add it to the token bucket; A quantity calculation unit is configured to calculate the number of pre-processed messages corresponding to the current operation time based on the processing time of the last processing of a single message; a forwarding unit, configured to forward the messages in the current message sequence based on the number of pre-processed messages, and record the forwarding time of the messages; The result calculation unit is configured to use the difference between the current operation time and the forwarding time as the current remaining time, and add the current remaining time to the token bucket.

12. The device according to claim 11, further comprising: A detection unit, wherein the detection unit is configured to: detect whether the remaining time of the current transaction is less than a time threshold; In response to detecting that the remaining time of this time is less than the time threshold, the remaining time of this time is used to replace the remaining time of the previous time in the token bucket; in response to detecting that the remaining time of this time is greater than or equal to the time threshold, the time threshold is used to replace the remaining time of the previous time in the token bucket.

13. The device according to claim 11, further comprising: An obtaining unit, wherein the obtaining unit is configured to: obtain a processing time for processing a single message this time based on the forwarding time and the number of pre-processed messages; The processing time of processing a single message last time is replaced by the processing time of processing a single message this time.

14. The device according to any one of claims 11 to 13, wherein: The forwarding unit is configured to: forward the messages in the current message sequence in real time, and record the number and time of the forwarded messages; detect whether the number of the forwarded messages reaches the number of pre-processed messages; In response to detecting that the number of the forwarded messages does not reach the number of pre-processed messages, detecting whether there are any unforwarded messages in the current message sequence; In response to detecting that there is no unforwarded message in the current message sequence, the time of the forwarded message is used as the forwarding time.

15. The device according to claim 14, wherein: The forwarding unit is configured to: in response to detecting that the number of the forwarded messages has reached the number of pre-processed messages, use the time of the forwarded messages as the forwarding time.

16. The device according to claim 14, wherein: The forwarding unit is configured to: in response to detecting that there are still unforwarded messages in the current message sequence, continue to forward the messages in the current message sequence in real time, and record the number and time of the forwarded messages; Until it is detected that there is no unforwarded message in the current message sequence, or it is detected that the number of the forwarded messages reaches the pre-processed message number.

17. The device according to any one of claims 11 to 13, wherein: The newly added computing unit is configured to: calculate the resource ratio of the target virtual machine; calculate the time difference between the time point of forwarding the message of the target virtual machine this time and the time point of forwarding the message of the target virtual machine last time; and use the product of the resource ratio and the time difference as the newly added computing time of the target virtual machine.

18. The device according to claim 17, wherein: The newly added computing unit is configured to: calculate the sum of the number of data packets transmitted per second by all virtual machines on the physical machine to obtain the sum of the number of data packets; divide the number of data packets transmitted per second by the target virtual machine by the sum of the number of data packets to obtain the resource ratio of the target virtual machine.

19. The device according to claim 17, wherein: The newly added computing unit is configured to: determine the maximum number of data packets transmitted per second on the physical machine; divide the number of data packets transmitted per second of the target virtual machine by the maximum number of data packets transmitted per second to obtain the resource ratio of the target virtual machine.

20. The device according to any one of claims 11 to 13, wherein: The quantity calculation unit is configured to calculate the ratio of the current operation time to the processing time of the last processing of a single message to obtain the number of pre-processed messages.

21. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 10.

22. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to enable the computer to execute the method according to any one of claims 1 to 10.

23. A computer program product, comprising a computer program, which, when executed by a processor, implements the method of any one of claims 1 to 10.