A kind of virtual machine method for scheduling task and system
Technical field
The present invention relates to business support technical field, relate in particular to a kind of virtual machine method for scheduling task and system.
Background technology
Task scheduling is distributed data base system, and the important component part of cloud computing system and operating system nucleus directly affects the efficiency of whole system.
At present, in operating system, the most popular scheduler is complete equity dispatching program (CompletelyFair Scheduler, CFS), according to the principle of complete justice, by abstract all tasks be scheduling entity (Schedule Entity), the corresponding one or more tasks of each scheduling entity, no longer distinguish interactive task, therefore, all tasks are all unified and treat.The core concept of CFS is to launch around virtual machine clock (VirtualClock), the virtual operation time (Virtual Run-time) is unique module of task scheduling and Runtime, when each scheduling, all can select the task of Virtual Run-time minimum to move.In addition, CFS has abandoned original priority query, as shown in Figure 1, form tissue by task with tree, a node on the corresponding tree of each task, Virtual Run-time is as the key assignments (Key-Value) of node, and the node of Key-Value minimum is the task that next time will be scheduled.
Under completely fair principle, in system, all task acquiescences have identical weight, can certainly change by certain methods the weight of task, as nice etc., but this situation is more rare, when the establishment of task, default-weight is identical, especially system task.
At present, the ultimate principle that the most popular virtual machine (Kernel Virtual Machine, KVM) is realized is: by each Virtual CPU(VCPU) be embodied as a CPU task and carry out accordingly the IO task (process) that IO operates.Therefore, to the scheduling of virtual machine be exactly the scheduling of the multiple tasks to representing virtual machine.CFS according to the control group equity dispatching strategy based on Virtual File System by each Virtual Machine(VM) be divided into an independently group, multiple groups that represent virtual machine are dispatched together with intrasystem other tasks.As shown in Figure 2, according to the grouping strategy of CFS, group 1 comprises 2 tasks, and group 2 comprises 3 tasks, and group 3 comprises 6 tasks.
Intel Virtualization Technology is one of gordian technique of relating to of cloud computing system.Cloud computing system is made up of a large amount of virtual machines conventionally, the performance of virtual machine has directly determined the performance of cloud computing system, and in cloud computing system, the scheduling of virtual machine has directly determined the height of resource utilization in the performance of virtual machine and cloud computing system, and then directly have influence on the height of the rate of profit of cloud computing system, therefore, how optimizing the scheduling strategy of virtual machine in cloud computing system is the key that improves cloud computing system performance and rate of profit.
As can be seen from Figure 2, operating system is at present to representing that the task of virtual machine does not have special treating, can not distinguish current task is virtual machine task or other common tasks, therefore, the computing power that virtual machine is required and various resource can not be given preferential treatment to from operating system level, in order to there is higher priority than common task or to obtain more resource, can only patch up in application program aspect the performance of the raising virtual machine of trying one's best.According to current CFS scheduling strategy, in Fig. 2 dispatching sequence's tree construction of task as shown in Figure 3, the order of digitized representation task scheduling, the i.e. Key-Value of task.
Before analyzing this scheduling topological structure, first do following hypothesis:
(1) t1 ~ t12 represents 12 tasks, is not completely independently between task;
(2) t1, t2, t4 belongs to same VM;
(3) t5, t6, t7, t8, t9 and t11 belong to another one VM;
(4) between t10 and t12, there is sibship;
(5) t3 and other tasks are without any relation, completely independent.
According to the scheduling strategy of CFS acquiescence, what CFS saw is only 12 independently tasks, and perception is less than the relation between task, and therefore, CFS can draw as dispatching sequence according to the tissue of tree:
t1->t2->t3->t4->t5->t6->t7->t8->t9->t10->t11->t12
Before the relative merits of scheduling sequence of analyzing acquiescence, introduce a context-sensitive parameter of measurement: uncorrelated context switching times (ICSC, Incorrelate Context Switch Count), represent the number of times completely independently switching between two tasks.
According to the scheduling strategy of the CFS of acquiescence, the ICSC=6 of the scheduling sequence shown in Fig. 3, be specially: t2->t3, t3->t4, t4->t5, t9->t10, t10->t11, t11->t12.
Although the scheduling strategy of CFS acquiescence has embodied justice, has ignored the relation between task completely, major embodiment is: the task of belonging to same virtual unit, task characteristic similarity is high, as shared address space, intertask communication is frequent, and Local principle of programme is obvious etc.Clearly, between group or independently between task, similarity of tasks is low, therefore, do not think that context between inter-related task switches and the task of feature similarity between context compare, will greatly reduce the hit rate of cache.As everyone knows, the hit rate of cache is one of key factor affecting system performance, so the scheduling strategy of CFS acquiescence, often due to the switching between uncorrelated task frequently, has greatly reduced the performance of whole system.
Based on above analysis, find that existing CFS scheduling strategy mainly contains following shortcoming:
1, common task is put on an equal footing with representing the task of virtual machine, can not maximize the performance of virtual machine.
2, perception, less than the relation between task, causes the switching between a large amount of uncorrelated tasks, greatly reduces the hit rate of cache, has affected the performance of entire system.
3, form because cloud computing system has a large amount of virtual machines, therefore, the CFS scheduling strategy of acquiescence is not suitable for cloud computing system very much.
Summary of the invention
In order to solve the lower technical matters of virtual machine performance in prior art, the present invention proposes a kind of virtual machine method for scheduling task and system.
One aspect of the present invention, provides a kind of virtual machine method for scheduling task, comprising: detect current task and whether belong to virtual unit; In the time that described current task belongs to virtual unit, process described current task; In the time that described current task does not belong to virtual unit, select next task according to the algorithm of acquiescence.
The method also comprises: other tasks of dispatching in the affiliated virtual unit of described current task are processed, until travel through the task of complete virtual unit.
The method also comprises: in the time that described current task belongs to virtual unit, detect the whether accessed mistake of described current task; When the accessed mistake of described current task, exit described virtual unit, select next task according to the algorithm of acquiescence; Not visited when described current task, be the mark of the accessed mistake of described current task setting.
Another aspect of the present invention, provides a kind of virtual machine task scheduling system, comprising: whether pick-up unit, belong to virtual unit for detection of current task; Dispatching device, in the time that described current task belongs to virtual unit, current task is processed described in priority scheduling; In the time that described current task does not belong to virtual unit, select next task according to the algorithm of acquiescence.
Wherein, dispatching device, also processes for other tasks in virtual unit under current task described in priority scheduling, until travel through the task of complete virtual unit.
This system also comprises setting device.Described pick-up unit, also in the time that described current task belongs to virtual unit, detects the whether accessed mistake of described current task; Described dispatching device, for when the accessed mistake of described current task, exits described virtual unit, selects next task according to the algorithm of acquiescence; Described setting device, for not visited when described current task, is the mark of the accessed mistake of described current task setting.
Virtual machine method for scheduling task of the present invention and system, in the time of task scheduling, can perceive the existence of virtual machine, thereby in the time of task choosing, preferentially select to belong to the task of virtual unit, be equivalent to improve the priority of virtual machine, and then improved the performance of virtual machine.
In addition, the task of the same virtual machine of priority scheduling, make to represent scheduling continuously between multiple tasks of same virtual machine, indirectly improve the priority of virtual machine, greatly reduce the number of times that the context between uncorrelated task switches, improve the hit rate of cache, and then improved the performance of whole system.
Further, the working time of having limited virtual unit by access flag (access), can not produce the situation that causes other tasks " to be died of hunger " due to the unrestricted operation of certain virtual unit, reduce most possibly the impact on system fairness and response time of scheduling strategy based on virtual machine perception.
Brief description of the drawings
Fig. 1 is the RBTree organization chart of task in CFS;
Fig. 2 is equity dispatching strategy based on the virtual file control group packet configuration figure to task;
Fig. 3 is the topology diagram of the CFS scheduling strategy task scheduling sequential tree of acquiescence;
Fig. 4 is the schematic flow sheet of virtual machine method for scheduling task embodiment of the present invention;
Fig. 5 is the topology diagram of the task scheduling sequential tree of scheduling strategy of the present invention;
Fig. 6 is the schematic flow sheet of another embodiment of virtual machine method for scheduling task of the present invention;
Fig. 7 is the structural representation of virtual machine task scheduling system embodiment of the present invention.
Embodiment
Below in conjunction with accompanying drawing, the present invention is described in detail.
As shown in Figure 4, the idiographic flow of virtual machine method for scheduling task embodiment of the present invention is as follows:
Step 402, selects a task;
Step 404, judges whether current task belongs to virtual unit, if so, and execution step 406, if not, execution step 410;
Step 406, processes this current task;
Step 408, other tasks under scheduling current task in virtual unit are processed, until travel through the task of complete virtual unit;
Step 410, selects next task, for example CFS dispatching algorithm according to default algorithm.
Particularly, the present invention is in task data, increase and describe the relevant data field of virtual machine group scheduling: virtual machine group descriptor (Virtual Group Description, be called for short VGP) and virtual unit institutional framework descriptor (Virtual Group Organization Description is called for short VGOD).
Wherein VGP is used for indicating task and belongs to which virtual unit, for example, when VGP place field is while being empty, represents that this task does not belong to virtual machine task; If VGP place field has value, represent that this task belongs to virtual machine task.VGP can be set to the descriptor of virtual unit group leader task, also can be set to point to the pointer of virtual unit group leader task, can realize flexibly according to different systems.
VGOD has described the organizational form that belongs to the task in same virtual unit, can realize flexibly according to concrete system equally, such as can be implemented as annular chain meter, also can be implemented as array.
In the establishment interface of task, increase the banner word of virtual unit perception, such as CLONE_VM_GROUP, being used for the task of the current establishment of reporting system is belonging in some virtual units of task, need in the process of task creation, complete the initialization of VGP and VGOD.
Concrete initial method is: VGP is assigned the task descriptor of father's task of creation task, according to different implementation methods, newly creating of task is added in the institutional framework of virtual machine group task of VGOD description.
Increase the overall gauge tap of the group scheduling strategy of virtual unit perception, be used for opening or close the group scheduling strategy based on virtual unit perception according to obstructed application scenarios, if defined the grand group scheduling strategy of unlatching based on virtual machine perception that just represent of CONFIG_VM_GROUP, otherwise, represent not open.
Shown in 5, the annular list that wherein dotted line forms represents virtual unit, and the direction of arrow represents the dispatching sequence in virtual unit.Group scheduling strategy based on virtual machine perception is choosing before next task operation, all go to judge whether current task belongs to some virtual units, if so, preferentially select other tasks in same virtual unit according to dotted line chained list, until travel through complete virtual unit; Otherwise, carry out selection task according to the CFS scheduling strategy of acquiescence.
Become according to the group scheduling strategy task scheduling sequence based on virtual machine perception:
t1->t2->t4->t3->t5->t7->t9->t11->t8->t6->t10->t12
Switching between uncorrelated task: t4->t3, t3->t5, t6->t10, i.e. ICSC=3.
Can find out from above-mentioned scheduling sequence, the number of times switching between uncorrelated task, from original becoming for 6 times 3 times, greatly reduces the number of times switching between uncorrelated task, and then can greatly improve the hit rate of cache, finally realizes the lifting of whole system performance.
In the present embodiment, on the basis of the CFS scheduling strategy of giving tacit consent to, increase the group scheduling strategy of virtual machine perception, system is in the time of task scheduling, can perceive the existence of virtual machine, thereby the preferential task of selecting to belong to virtual unit, has been equivalent to improve the priority of virtual machine, and then has improved the performance of virtual machine in the time of task choosing.
In addition, the task of the same virtual machine of priority scheduling, make to represent scheduling continuously between multiple tasks of same virtual machine, indirectly improve the priority of virtual machine, greatly reduce the number of times that the context between uncorrelated task switches, improve the hit rate of cache, and then improved the performance of whole system.
According to the group scheduling strategy based on virtual machine perception, once choose certain task in virtual unit, will preferentially select other tasks in this virtual unit, so, unless the task in current virtual unit all moved, otherwise, even if exist than also high task of task priority in current virtual unit, also can not get timely response, this not only can reduce the response time of whole system, has also destroyed widely the fairness of CFS.
For minimally reduces due to the destruction of the group scheduling algorithm of introducing based on virtual machine perception to CFS fairness, realize the compromise between performance and fairness, by increase an access flag access in task descriptor, whether be used for mark task in the accessed mistake of virtual unit, if all accessed mistakes of all tasks in current virtual unit, jump out this virtual unit, select next task according to the dispatching algorithm of acquiescence.
As shown in Figure 6, the idiographic flow of another embodiment of virtual machine method for scheduling task of the present invention is as follows:
Step 602, after selection task, judges whether current task belongs to certain virtual unit, if so, and execution step 604, if not, execution step 608;
Step 604, the whether accessed mistake of this task, if so, execution step 608, if not, execution step 606;
Step 606, arranges mark current task accessed mark (access=1) in this virtual unit;
Step 608, selects next task according to default algorithm.
From virtual group after selection task, first judge the access flag of this task, if accessed mistake (access=1), task in this virtual unit is described, and accessed mistake has been once, just exit this virtual unit, select next task according to the dispatching algorithm of acquiescence.
The Implementation of pseudocode of the present embodiment dispatching method is as follows:
In the present embodiment, on the one hand, by the priority scheduling of virtual machine group task having been reduced to the number of times (ICSC) of uncorrelated task context switching, improve on the whole the performance of system; On the other hand, the working time of having limited virtual unit by access flag (access), can not produce the situation that causes other tasks " to be died of hunger " due to the unrestricted operation of certain virtual unit, reduce most possibly the impact on system fairness and response time of scheduling strategy based on virtual machine perception.
Based on same inventive concept, the present invention also provides a kind of virtual machine task scheduling system embodiment, and as shown in Figure 7, this system embodiment comprises: pick-up unit 71 and dispatching device 72.Wherein, whether pick-up unit detection current task belongs to virtual unit; Dispatching device is in the time that current task belongs to virtual unit, and priority scheduling current task is processed; In the time that current task does not belong to virtual unit, select next task according to the algorithm of acquiescence.
Dispatching device also under priority scheduling current task other tasks in virtual unit process, until travel through the task of complete virtual unit.
Preferably, this system also comprises setting device 73.In the time that current task belongs to virtual unit, pick-up unit detects the whether accessed mistake of current task.When the accessed mistake of current task, exit virtual unit, dispatching device is selected next task according to the algorithm of acquiescence.Not visited when current task, setting device is the mark of the accessed mistake of current task setting.
It should be noted that: above embodiment is only unrestricted in order to the present invention to be described, the present invention is also not limited in above-mentioned giving an example, and all do not depart from technical scheme and the improvement thereof of the spirit and scope of the present invention, and it all should be encompassed in claim scope of the present invention.