Background technology
(Garbage Collection, GC) mechanism is such as the total characteristic of the language of new generation of Java, C#, Python, Eiffel, Roby etc. in refuse collection.Through this Garbage Collection Mechanism, can manage recovery automatically to internal memory, come releasing memory and need not the programmer through call function, thereby alleviated programmer's programming burden.
At present, in large-scale application, adopt the application server of aggregated structure widely, as based on application server of Java, C# etc. such as telecommunication service.For example, Java language has advantages such as being easy to learn and writing, be independent of operating system, and current major applications server is to support the business based on Java based on the framework of Java, such as the Websphere Application Server of IBM Corporation.
The most important requirement of exploitation to such as the real-time application of telecommunication service is exactly the excellent real-time handling property, thereby time restriction has been forced in behavior when part moved.This type of some part that limits application programs is normally implemented, and such as interrupt handling routine, code that its response is interrupted must be finished the work in given time range.The application server middleware operates on the virtual machine that is provided with GC mechanism.Though GC mechanism has been simplified exploitation, has also brought a certain amount of system overhead simultaneously.Virtual machine can suspend all calculation process when carrying out refuse collection, this phenomenon also is called as " world suspend (Stop The World, STW) ", and the frequency and the duration of this " world's time-out " are all uncertain.This phenomenon can cause user's request responding time is increased, and for the demanding application of real-time of telecommunication applications etc., is unacceptable sometimes.
The problem of this in order to solve " world's time-out "; David F.Bacon, Perry Cheng and V.T.Rajan have proposed the Metronome algorithm (" A Real-timeGarbage Collector with Low Overhead and Consistent Utilization " to the Java application; Conference Record of the Thirtieth ACM Symposium on Principles ofProgramming Languages (New Orleans; Louisiana; January 2003), pp.285-298).In the Metronome algorithm, GC handled to be subdivided in a plurality of discontinuous minor time slices carry out, thereby shortened time of each " world's time-out ".Yet this GC method has reduced the service ability of memory usage and server.
As stated, present telecommunication applications all adopts aggregated structure basically, comprising a plurality of virtual machines.In cluster environment, a kind of method that solves " world's time-out " problem is that the service request of carrying out the virtual machine of GC is switched to the virtual machine that GC does not take place in the cluster.
With by Java Virtual Machine (Java Virtual Machine; JVM) cluster environment that constitutes is an example; The inventor finds that the configuration of the virtual machine in this cluster environment is often approximate, thereby a plurality of virtual machines that can occur in the cluster are tending towards almost synchronously taking place the situation that GC handles.This situation can be by Fig. 1 illustration.
Fig. 1 illustration in always having the Java Virtual Machine group system example of 4 Java Virtual Machines, the internal memory operating position of every Java Virtual Machine is over time.Visible by Fig. 1,4 Java Virtual Machines in the group system are tending towards synchronously carrying out GC along with the propelling of time.When GC almost takes place in all Java Virtual Machines synchronously in the cluster, can cause handling common service request, we claim that this situation is " (no place to hide) has nowhere to run ".In case occur " having nowhere to run ", will have a strong impact on the real-time performance of whole group system.Can conceive, the phenomenon of this synchronous GC can appear at all based in the cluster environment that application constituted with GC mechanism, for example, supports large-scale Application of C # cluster environment.The inventor believes that along with the widespread use of language in cluster environment that a new generation has Garbage Collection Mechanism, the problem of above-mentioned synchronous refuse collection will become and become increasingly conspicuous.
Therefore, be desirable to provide a kind of method and apparatus that can dispatch the refuse collection between a plurality of virtual machines in the cluster environment.
Embodiment
Should be appreciated that accompanying drawing of the present invention simplifies with describing, help to be expressly understood step of the present invention or parts, from purpose clearly, removed other steps or parts in the typical software analysis technology simultaneously with illustration.Those skilled in the art will recognize that, for embodiment of the present invention, other steps or parts be hope and/or be essential.Yet, because these steps or parts are known in the field, and owing to they do not help understand the present invention better, so do not provide the description about them among this paper.It is also understood that the included accompanying drawing of this paper has only provided the diagrammatic representation for current embodiment of the present invention, fall into step or parts in the scope of the present invention and can comprise and be different from step shown in these accompanying drawings or parts.With quoted figures, wherein give similar Reference numeral below to similar step or parts.
As stated, refuse collection synchronously possibly be to be applied to the problem that the language with Garbage Collection Mechanism in the cluster environment will face jointly.Start from clearly illustration the object of the invention, hereinafter will be applied as example with Java particularly and specify embodiments of the invention.Fig. 2 shows the process flow diagram according to refuse collection dispatch control method of the present invention of the group system of (n is a positive integer) the individual Java Virtual Machine that is applied to have n.At first; At step 202 place; N from cluster environment Java Virtual Machine receives the refuse collection report; Comprise refuse collection type (that is initiatively refuse collection or passive refuse collection), the refuse collection generation moment, refuse collection execution duration, the internal memory use value when triggering refuse collection and the relevant informations such as internal memory use value after the refuse collection in this refuse collection report.Then; At step 204 place; For example be based on the refuse collection report that step 202 place receives; Judged whether to occur the individual Java Virtual Machine of predetermined quantity m (m is the positive integer that is less than or equal to n) according to predetermined criterion the trend of synchronous refuse collection has taken place, thereby determined whether and to dispatch the refuse collection of Java Virtual Machine in this group system.This predetermined quantity m confirms according to the general requirement of system performance.For example, total total n=7 platform virtual machine in the group system, if wherein 3 almost carry out refuse collection simultaneously and will cause satisfying application requirements, then can be set to 3 by this predetermined quantity m.Certainly, this predetermined quantity m also can be made as the Java Virtual Machine sum n that equals in the group system.
Above-mentioned predetermined criterion for example can be to calculate the time interval of between each Java Virtual Machine refuse collection taking place successively in the cluster environment; And when the time interval value of the m in these time intervals is less than or equal to a predetermined time interval value, judge the trend that synchronous refuse collection occurs.Wherein said predetermined time interval value can be according to the cluster environment framework, be provided with professional factors such as requirement are provided, and also can take the practical experience value.The above-mentioned method that the refuse collection time interval between each Java Virtual Machine and a predetermined time interval value are compared only is exemplary, it will be appreciated by those skilled in the art that any other judgment criterion that is fit to all is feasible.In addition, in the above-described embodiments, be to start refuse collection scheduling controlling of the present invention in step 204, but dispatching method of the present invention also can regularly be carried out through detecting synchronous refuse collection trend.For example; According to system's actual conditions; For example through investigating the average period that synchronous trend appears in a plurality of Java Virtual Machines in this group system; Set a scheduled time slot, in step 204, whether passed through this scheduled time slot apart from refuse collection scheduling last time, thereby determine whether to carry out the refuse collection scheduling through monitoring.
If confirm not carry out the refuse collection scheduling at step 204 place, then turn back to step 202, continue to receive the refuse collection report.And if confirm to want operation dispatching at step 204 place, then start the refuse collection dispatch control method of the present invention shown in the frame of broken lines among Fig. 2, implement initiatively refuse collection intervention.Particularly, at step 206 place, the n from cluster environment Java Virtual Machine receives the internal memory operation report, and this internal memory operation report comprises the current internal memory use value of Java Virtual Machine.Next, play step 322,, carry out scheduling particularly the refuse collection of each Java Virtual Machine in the cluster environment based on this internal memory operation report that receives from step 208.In the embodiment shown in Figure 2, at step 208 place, calculate the corresponding target internal memory of each Java Virtual Machine use value, and desired value is assigned to corresponding Java Virtual Machine.Hereinafter will describe target internal memory use value how to calculate each Java Virtual Machine in detail with reference to Fig. 3.
Then, at step 210 place,, judge that whether its current internal memory use value is more than or equal to target internal memory use value to each Java Virtual Machine.If the current internal memory use value that has no a Java Virtual Machine is more than or equal to its corresponding target internal memory use value; Then receive next Java Virtual Machine internal memory operation report (step 212) constantly, continue the internal memory use value at execution in step 210 places then and judge.The reception internal memory operation report at repeated execution of steps 212 places and the judgement at step 210 place, up to the internal memory use value that Java Virtual Machine is arranged more than or equal to target internal memory use value.
When the internal memory use value that detects Java Virtual Machine at step 210 place during more than or equal to target internal memory use value, at step 214 place, put it in the formation, provide token to wait for.At step 216 place, whether inspection has available token then.If there is not available tokens, then at step 218 place, this situation is recorded in the daily record and reports, wait for that then token returns (step 220).And if judgement has available tokens at step 216 place, then at step 222 place, from formation, read the Java Virtual Machine of waiting to provide token, and it is provided token.To explain how Java Virtual Machine carries out the operation of refuse collection receiving this order bridge queen with reference to Fig. 4 B in the back literary composition.
Here; Need to prove; To the token number of group system can be the quantity n that considers the Java Virtual Machine in this group system, the predetermined quantity m and the user that set when being used to judge synchronous refuse collection trend set performance demands, it can be one or more less than the sum of Java Virtual Machine.For example, in telecommunication service, the user requires high to the real-time performance of system, and the Java Virtual Machine that does not then allow to carry out simultaneously refuse collection is too many.On the other hand; If the token number that is provided with very little; Then for larger cluster environment; Can cause waiting in the formation that the Java Virtual Machine of providing token is too much, can cause the Java Virtual Machine of these waits before the token granting, passive refuse collection just to take place when serious, make dispatching effect of the present invention reduce greatly.
To target internal memory use value how to calculate each Java Virtual Machine be described with reference to Fig. 3 below.At first, at step 302 place, the internal memory use value that comprises in the internal memory operation report from each Java Virtual Machine that receives according to the place of the step 206 in Fig. 2 is calculated the corresponding memory consumption rate of each Java Virtual Machine.Then at step 304 place, according to the current internal memory use value of ascending each Java Virtual Machine of series arrangement.
Then; At step 306 place; The target internal memory use value of the Java Virtual Machine that the maximum memory use value Ha of the automatic triggering refuse collection that comprises in the refuse collection report that receives according to step 202 place at Fig. 2 is set to make number one, this Java Virtual Machine that makes number one is that Java Virtual Machine of current internal memory use value minimum in the said n Java Virtual Machine.Need to prove that in this embodiment, the maximum memory use value Ha when passive refuse collection takes place is set to the target internal memory use value of the minimum Java Virtual Machine of current internal memory use value.Yet the initiatively target internal memory use value of refuse collection takes place as Java Virtual Machine in any other fit values that also can be provided with less than this maximum memory use value Ha.From the angle of maximization memory usage, select near or to be slightly less than the target internal memory use value of maximum memory use value of passive refuse collection more favourable.
Then, at step 308 place, follow following formula and calculate the corresponding target internal memory of the Java Virtual Machine that comes next bit use value hJ
k:
(hJ
k-h
k)/Rh
k=(hJ
K-1-h
K-1)/Rh
K-1-F (hJ
k)-Tg, n>K>=2 formulas 1
Wherein, n is the Java Virtual Machine sum in the cluster environment,
HJ
kThe target internal memory use value of the Java Virtual Machine that comes the k position of indicating to calculate,
HJ
K-1The target internal memory use value of the Java Virtual Machine that comes the k-1 position that expression has been set or calculated,
h
kAnd h
K-1The current internal memory use value of representing the Java Virtual Machine of k position and k-1 position respectively,
Rh
kAnd Rh
K-1Be illustrated respectively in the memory consumption rate of the Java Virtual Machine of k position that step 302 place calculates and k-1 position,
Tg is the minimum time interval between the adjacent refuse collection, this parameter can be based on the user to the requirement of system performance and definite and
F (hJ
k) represent to reach hJ when the internal memory use value
kThe time, carry out refuse collection institute's time spent, the refuse collection that this parameter is comprised in for example can reporting according to the refuse collection that the place of the step 202 in Fig. 2 receives is carried out duration and is confirmed.
Then, at step 310 place, judged whether to calculate the target internal memory use value of all Java Virtual Machines.If confirm to calculate, then turn back in the scheduling flow shown in Fig. 2 to all Java Virtual Machines.Otherwise, turn back to step 308 place, continue to calculate target internal memory use value, up to the target internal memory use value of having calculated all Java Virtual Machines to other Java Virtual Machines.
The target internal memory use value of utilizing the algorithm computation shown in Fig. 3 to obtain makes and can dispatch the refuse collection of each Java Virtual Machine in time basically equably, and can guarantee the utilization rate maximization of memory source.Here need to prove that the algorithm of aforementioned calculation target internal memory use value only is an exemplary, the present invention is not limited to this.Those skilled in the art are according to the teacher of this instructions, and can understand other modification that are fit to fully all is feasible with changing.For example, can select to make the target internal memory use value computational algorithm that the refuse collection of each Java Virtual Machine anisotropically takes place in time.In addition, also can be according to (hJ
k-h
k)/Rh
k<(hJ
K-1-h
K-1)/Rh
K-1-F (hJ
k)-Tg selects the target internal memory use value of k position Java Virtual Machine, and even now can cause the waste to a certain degree of memory source.Even; Under the situation of not taking into account system memory source utilization rate and system's real-time response performance; Arbitrary or several Java Virtual Machines in can the picked at random cluster environment be set at the arbitrary value that is less than or equal to maximum memory use value Ha with their target internal memory use value.
Explain in the Java Virtual Machine according to the embodiment of the invention with reference to Fig. 4 A and Fig. 4 B below and handle.In the present invention, Java Virtual Machine need be monitored its internal memory and used, and regularly sends the internal memory operation report.Thereby when synchronous refuse collection not taking place do not carry out refuse collection and initiatively dispatch, the processing in the Java Virtual Machine is shown in Fig. 4 A.Along with internal memory is constantly consumed, and trigger refuse collection, i.e. refuse collection (step 402) passively.After the refuse collection,, send the refuse collection report at step 404 place, with the type of reporting this refuse collection, constantly, carry out duration, the internal memory use value that triggers refuse collection and the internal memory use value after the refuse collection.
And under the situation that the scheduling of the refuse collection in having carried out Fig. 2 and Fig. 3 is handled, shown in Fig. 4 B, Java Virtual Machine at first receives token at step 412 place, then carries out initiatively refuse collection (step 414).Similar with the step 404 among Fig. 4 A, Java Virtual Machine sends the refuse collection report at step 416 place.Then, this Java Virtual Machine that initiatively refuse collection takes place returns token to (step 418).Thereby, accomplished once initiatively garbage collection process.
Fig. 5 shows method of the present invention internal memory use and the refuse collection scheduling situation afterwards of having used with Java Virtual Machine cluster topology instance shown in Figure 1.In Java Virtual Machine group system shown in Figure 5, suppose always to have 4 Java Virtual Machine JVM1, JVM2, JVM3 and JVM4.As shown in Figure 1, when detecting 4 Java Virtual Machines in this cluster environment at step 204 place shown in Figure 2 and the trend of synchronous refuse collection occurred, start refuse collection scheduling of the present invention and handle.In this example, set that to begin to carry out the moment that the refuse collection scheduling handles be 0.
At first, shown in step 206, receive internal memory operation report separately from 4 Java Virtual Machines.The internal memory use value of supposing JVM1, JVM2, JVM3 and JVM4 current (that is, 0 locates constantly) is respectively 100,100,110 and 120, and their memory consumption rate is Rh=50M/s (million/second).In this example, suppose the maximum memory use value Ha=950M of automatic triggering refuse collection, this maximal value Ha is distributed to JVM1 as its target internal memory use value hJ1.According to user's request, the time interval of adjacent refuse collection is set to Tg=3s, and in this example, setting token number is 1.In addition, from the purpose that clearly demonstrates, suppose that it is F (h)=1s that each Java Virtual Machine carries out the required time average of refuse collection under corresponding target internal memory use value.Next, according to above-mentioned formula 1, the target internal memory use value hJ2, hJ3 and the hJ4 that calculate JVM2, JVM3 and JVM4 successively are respectively 750M, 560M and 370M, shown in first row in the chart of Fig. 5 (0 constantly).
Shown in Fig. 5 second row, when implementing the 5th second, the internal memory use value of JVM4 has reached its desired value hJ4=370M.Thus, provide token to this JVM4, trigger refuse collection among the JVM4 thereby be shown in like Fig. 4 B, JVM4 returns token and sends refuse collection report then.After F (h)=1s is carried out in refuse collection, located at the 6th second, see that the current internal memory use value of carrying out refuse collection JVM4 afterwards is 50M.From this constantly, JVM4 gets into the automatic garbage collection treatment scheme shown in Fig. 4 A.As time goes on, located at the 9th second, the 13rd second respectively, find that the internal memory use value of JVM3 and JVM2 has reached corresponding desired value hJ3=560M and hJ2=750M.Thus, in JVM3 and JVM2, carry out initiatively refuse collection respectively, make and located at the 10th second and the 14th second respectively that the internal memory use value among JVM3 and the JVM2 is 50M, and begins to get into the automatic garbage collection treatment scheme.At last, located at the 17th second, JVM1 has reached its target internal memory use value hJ1=950M, thereby carries out refuse collection.The data of the 18th second that delegation are visible from Fig. 5, through above-mentioned refuse collection scheduling, make the current internal memory use value difference of JVM1, JVM2, JVM3 and JVM4 open, thereby slackened the possibility that synchronous refuse collection occurs effectively.The internal memory use value time history plot of JVM1, JVM2, JVM3 and JVM4 more clearly show that among Fig. 6, dispatches processing through refuse collection of the present invention, thereby has avoided the generation of synchronous refuse collection.
Fig. 7 shows the block diagram according to the group system with refuse collection scheduling feature 700 of the embodiment of the invention.As shown in the figure, in this group system 700, have n Java Virtual Machine JVM1 to JVMn.All has the annunciator that is used to send refuse collection report and internal memory operation report in every Java Virtual Machine.This group system 700 also comprises scheduling determiner 740 and refuse collection (GC) scheduler 720.This scheduling determiner 740 receives the refuse collection report from the annunciator of each among the JVM1 to JVMn, and according to determining whether to carry out the refuse collection scheduling based on this refuse collection report shown in the step 204 among Fig. 2.When scheduling determiner 740 confirms to carry out the refuse collection scheduling, send dispatch command to refuse collection scheduler 720.Refuse collection scheduler 720 receives the internal memory operation report from a said n annunciator behind the dispatch command that receives self scheduling determiner 740, and dispatches the refuse collection between the JVM1 to JVMn based on this internal memory operation report.
Fig. 8 shows the block diagram of the configuration of refuse collection scheduler 720.This refuse collection scheduler 720 comprises target internal memory use value controller 810 and token controller 820.This target internal memory use value controller 810 is used for calculating and distributes corresponding target internal memory use value to each of JVM1 to JVMn.The target internal memory use value that token controller 820 based target internal memory use value controllers 810 calculate is carried out control; Providing token greater than the Java Virtual Machine of the corresponding target internal memory use value that obtains by target internal memory use value controller, thereby allow it to carry out refuse collection to current internal memory use value.
Particularly, target internal memory use value controller 810 comprises: memory consumption rate counter 812 is used for according to the said internal memory operation report that receives the memory consumption rate of each among the calculating JVM1 to JVMn; Sorting unit 814 is used for the current internal memory use value according to ascending series arrangement JVM1 to JVMn; With target internal memory use value counter 816; The maximum memory use value that is used for triggering automatically refuse collection is set at the target internal memory use value of the Java Virtual Machine that makes number one; This Java Virtual Machine that makes number one is that minimum Java Virtual Machine of current internal memory use value in the said n Java Virtual Machine, and this target internal memory use value counter 816 is also followed above-mentioned formula 1 and calculated the corresponding target internal memory of other Java Virtual Machines use value.And token controller 820 comprises: token number setting device 822 is used to consider that Java Virtual Machine quantity n and user to performance demands, set the token number in this cluster environment; With token dispensing apparatus 824; Be used for current internal memory use value is put into a formation greater than the Java Virtual Machine of the corresponding target internal memory use value of being distributed by said target internal memory use value controller; And several Java Virtual Machines of token that being less than or equal to of in formation, waiting for successively set by said token number setting device 822 provide tokens, carry out refuse collection to allow it.
Should be noted that the refuse collection scheduler shown in Fig. 8 only is exemplary.Those skilled in the art are through reading the description to Fig. 2 to Fig. 6, can envision the refuse collection scheduler that comprises the module of the function of step shown in these figure of realization.
Provided above description from illustration and illustrative purposes to various aspects of the present invention.This is not to be intended to exhaustive or to limit the invention to disclosed precise forms, and obviously can much revise and change.For example, the various appropriate combination of step among above-mentioned a plurality of embodiment and module also are feasible.
Be applied as example with Java hereinbefore refuse collection dispatching method of the present invention and device have been described; Yet those skilled in the art can conceive fully; Method and apparatus of the present invention also can be applicable to have in the application of Garbage Collection Mechanism based on other, for example in the application based on C#.In addition; The method and apparatus of the refuse collection of the scheduling Java Virtual Machine of the embodiment of the invention can be applied to any application server based on Java; Be particularly useful for the demanding application system of real-time performance, and be not limited to particular system disclosed in this specification.In addition, it should be appreciated by those skilled in the art that alleged among this paper " token " can be signal, instruction, operation or other suitable forms.
Therefore, should be appreciated that the present invention is not limited to above disclosed specific embodiment, and be intended to cover modification and the modification that limits following claim.