A garbage collection dynamic adjustment method and a server

By monitoring and dynamically adjusting the garbage collection interval, and identifying and redirecting large object interfaces, the problem of frequent garbage collection in the server program was solved, ensuring the stability and performance of the application instance.

CN118312309BActive Publication Date: 2025-12-12FUJIAN TIANQUAN EDUCATION TECH LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410437807.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-12
Publication Date
2025-12-12
Estimated Expiration
2044-04-12

AI Technical Summary

Technical Problem

In server-side programs, due to the uncertainty of object creation, it is difficult to effectively reduce the number of garbage collections or the time required, which affects the stability of application instances.

Method used

By monitoring application instances in the virtual machine, the garbage collection interval is dynamically adjusted, and the interfaces of large objects are identified and diverted to the second application instance to reduce object generation in the first application instance. The second application instance is then used to provide additional services to stabilize the garbage collection interval.

Benefits of technology

It adaptively adjusts the garbage collection interval to ensure the stability of application instances and reduce the impact of frequent garbage collection on program pauses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118312309B_ABST
    Figure CN118312309B_ABST
Patent Text Reader

Abstract

The application discloses a garbage collection dynamic adjustment method and a server, first monitoring is performed on a first application instance in a virtual machine, second monitoring is performed on the first application instance after monitoring that a garbage collection time interval is shortened to a certain degree, a large object in the application instance can be obtained, an interface list corresponding to the large object is obtained, and the interface list corresponding to the large object is cut to a second application instance. Since the interface of the large object is cut to the other application instance, the object generation of the first application instance is effectively reduced, and the garbage collection time interval of the first application instance is reduced; when the garbage collection time interval of the large object switched is restored to a certain degree, the large object is cut back to the first application instance. In this way, only the interface is cut, and other interfaces of the whole application instance still provide services, so that the garbage collection time interval can be dynamically adjusted adaptively, and the stability of the application instance is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of garbage collection optimization, and particularly relates to a garbage collection dynamic adjustment method and a server. BACKGROUND

[0002] At present, JAVA language programs need to run on JVM virtual machines, and the virtual machines naturally carry various garbage collection (GC) functions. In each GC process, in order to enable the GC to proceed smoothly, the programs in the entire JVM are paused, and therefore good programs will optimize the GC function in order to reduce the impact on program pause and minimize the GC time or frequency.

[0003] At present, a large number of interfaces are provided in the server program, and a large number of objects may be generated in each interface, and these objects need to be stored in the memory heap of the JVM. There are two generations in the memory heap of the JVM, one is the young generation, and the other is the old generation. For the objects generated by the interface, if the object is small, it will be directly placed in the young generation, and if the object is large or the young generation does not have enough space, it will be directly placed in the old generation. When the old generation has a large number of large objects and insufficient space, the GC operation will be triggered.

[0004] However, it is currently difficult to reduce the GC frequency or time in this way because the number of objects generated in the interface of the server program is unknown, and it is unknown whether the generated objects are large or small. SUMMARY

[0005] The technical problem to be solved by the present application is to provide a garbage collection dynamic adjustment method and a server, which can dynamically adjust the time interval of garbage collection in an application instance to ensure the stability of the application instance.

[0006] To solve the above technical problems, the technical scheme adopted by the present application is:

[0007] A garbage collection dynamic adjustment method, comprising the steps of:

[0008] S1, a first application instance in a virtual machine is monitored to obtain the garbage collection time interval of the first application instance;

[0009] S2, it is judged whether the garbage collection time interval of the first application instance is less than a time threshold value, if yes, the first application instance is monitored, the objects and interfaces in the first application instance are monitored, the largest object and its interface in the first application instance are obtained, and the interface of the large object is cut to a second application instance;

[0010] S3, if the garbage collection time interval of the first application instance and the second application instance are both greater than or equal to a time threshold, then the interface of the large object is switched to the first application instance.

[0011] To solve the above technical problems, another technical solution adopted by the present application is:

[0012] A garbage collection dynamic adjustment server end comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements each step of the above-mentioned garbage collection dynamic adjustment method when executing the computer program.

[0013] The present application has the beneficial effects that: the first application instance in the virtual machine is monitored, and when the garbage collection time interval is monitored to be shortened to a certain extent, the first application instance is monitored again, the interface list of the large object in the application instance is obtained, and the interface list corresponding to the large object is switched to the second application instance. Since the interface of the large object is switched to other application instances, the object generation of the first application instance is effectively reduced, and the garbage collection time interval of the first application instance is further reduced, and when the garbage collection time interval of the switched large object is restored to a certain extent, it is switched back to the first application instance. In this way, only these interfaces are switched, and the other interfaces of the entire application instance still provide services to the outside, and the second application instance newly added additionally only provides services for the interfaces of the large object, so that the garbage collection time interval can be dynamically adjusted adaptively, and the stability of the application instance is ensured. BRIEF DESCRIPTION OF DRAWINGS

[0014] Figure 1 A flow chart of a garbage collection dynamic adjustment method of an embodiment of the present application;

[0015] Figure 2 A schematic diagram of a garbage collection dynamic adjustment server end of an embodiment of the present application;

[0016] Figure 3 A monitoring schematic diagram of JProfiler of an embodiment of the present application.

[0017] LABEL EXPLANATION:

[0018] 1. A garbage collection dynamic adjustment server end; 2. a memory; 3. a processor. DETAILED DESCRIPTION

[0019] To explain the technical content, achieved purposes and effects of the present application in detail, the following will be explained in combination with the embodiments and the accompanying drawings.

[0020] Please refer to Figure 1The embodiment of the present application provides a garbage collection dynamic adjustment method, comprising the following steps:

[0021] S1, performing first monitoring on a first application instance in a virtual machine, and obtaining a garbage collection time interval of the first application instance through the monitoring;

[0022] S2, judging whether the garbage collection time interval of the first application instance is less than a time threshold value, if yes, performing second monitoring on the first application instance, monitoring objects and interfaces in the first application instance, obtaining a large object and interfaces of the large object in the first application instance, and switching the interfaces of the large object to a second application instance;

[0023] S3, if the garbage collection time intervals of the first application instance and the second application instance are both greater than or equal to the time threshold value, switching the interfaces of the large object back to the first application instance.

[0024] From the above description, the beneficial effects of the present application are as follows: the first application instance in the virtual machine is monitored, when the garbage collection time interval is monitored to be shortened to a certain degree, the second monitoring is performed on the first application instance, the large object in the application instance is obtained, the interface list of the large object is obtained, and the interface list corresponding to the large object is switched to the second application instance. Since the interfaces of the large object are switched to other application instances, the object generation of the first application instance is effectively reduced, and then the garbage collection time interval of the first application instance is reduced, when the garbage collection time interval of the switched large object is restored to a certain degree, the large object is switched back to the first application instance. In this way, only the interfaces are switched, the other interfaces of the whole application instance still provide services, and the second application instance newly added is only used to provide services for the interfaces of the large object, so that the garbage collection time interval can be dynamically adjusted, and the stability of the application instance is ensured.

[0025] Further, the step S1 comprises:

[0026] performing first monitoring on a first application instance in a virtual machine, the first monitoring is used for monitoring a memory occupation ratio in the first application instance, and a curve is drawn according to the memory occupation ratio;

[0027] obtaining a garbage collection time interval of the first application instance according to a time difference between adjacent wave crests in the curve.

[0028] From the above description, through the memory occupation curve obtained by monitoring, the garbage collection time interval is calculated according to the time difference between adjacent wave crests in the curve, the information of the time interval can be effectively and timely monitored, so as to facilitate subsequent memory dynamic adjustment according to the time interval.

[0029] Further, the largest object occupying the memory in the first application instance and the interface thereof are acquired, comprising:

[0030] The thread quantity proportion and the memory occupation size of each object in the first application instance are acquired to calculate the memory occupation amount corresponding to 1% thread quantity proportion of each object in the first application instance;

[0031] The object with the largest memory occupation amount corresponding to 1% thread quantity proportion in the first application instance is taken as the largest object, and the associated interface list of the largest object is acquired.

[0032] It can be known from the above description that the largest object in the first application instance is determined by calculating the memory occupation amount corresponding to 1% thread quantity proportion, and the object with large thread occupation can be quickly confirmed, so that the largest object is adjusted subsequently.

[0033] Further, the interface of the largest object is cut to the second application instance, and then comprising:

[0034] If the garbage collection time interval of the first application instance is less than the time threshold value, the step of performing the second monitoring on the first application instance is returned to continue acquiring the largest object occupying the memory in the current first application instance and cutting the flow.

[0035] It can be known from the above description that if the garbage collection time interval of the first application instance is still small after cutting, the first application instance needs to be further cut until the garbage collection time of the first application instance returns to normal, so as to ensure the stability of the first application instance.

[0036] Further, the garbage collection time interval of the first application instance is obtained by monitoring, and then comprising:

[0037] The first application instance is subjected to a stress test, and according to the relationship between the garbage collection time interval and the interface stability in the stress test, a garbage collection time interval is selected as a time threshold value.

[0038] It can be known from the above description that the time threshold value of the garbage collection time interval is determined by the stress test, and what kind of garbage collection time will affect the stability of the application instance interface can be effectively judged.

[0039] Please refer to Figure 2 Another embodiment of the application provides a garbage collection dynamic adjustment server, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements each step of the above-mentioned garbage collection dynamic adjustment method when executing the computer program.

[0040] The garbage collection dynamic adjustment method and the server disclosed by the application are suitable for dynamically adjusting the time interval of garbage collection in an application instance to ensure the stability of the application instance. The following is described by means of specific embodiments.

[0041] Embodiment one

[0042] Please refer to Figure 1 A garbage collection dynamic adjustment method comprises the following steps:

[0043] S1, a first application instance in a virtual machine is monitored to obtain the garbage collection time interval of the first application instance.

[0044] Specifically, the first application instance in the virtual machine is monitored, the first monitoring is used to monitor the memory occupation ratio in the first application instance, and a curve is drawn according to the memory occupation ratio; the garbage collection time interval of the first application instance is obtained according to the time difference between adjacent peaks in the curve.

[0045] In this embodiment, the first application instance is taken as a main application instance, the application instance provides at least dozens of external interfaces, and the JVM monitoring function is added to the application instance, mainly monitoring the thread number and the memory occupation ratio per second of the application instance in the JVM, the memory occupation ratio curve containing peaks and troughs can be drawn through the memory occupation ratio, in this way, the time difference between adjacent peaks in the curve can be taken as the garbage collection time interval.

[0046] S2, it is judged whether the garbage collection time interval of the first application instance is less than a time threshold value, if yes, the first application instance is monitored, the objects and interfaces in the first application instance are monitored, the largest object and its interface occupying the memory in the first application instance are obtained, and the interface of the large object is cut to the second application instance.

[0047] S21, the first application instance is tested under pressure, according to the relationship between the garbage collection time interval and the interface stability in the pressure test, a garbage collection time interval is selected as a time threshold value.

[0048] Specifically, according to the pressure test, it can be obtained that when the garbage collection time interval is reduced to a certain proportion, the stability of the interface will be affected, therefore, the garbage collection time interval is taken as the time threshold value. In this embodiment, the time threshold value is 60s, that is, when the garbage collection time interval is less than 60s, the interface performance or stability will be affected due to frequent garbage collection.

[0049] S22, if the garbage collection time interval of the first application instance is less than the time threshold, then the first application instance is monitored for a second time, the objects and interfaces in the first application instance are monitored, the thread quantity proportion and memory occupation size of each object in the first application instance are obtained, the memory occupation corresponding to 1% thread quantity proportion of each object in the first application instance is calculated, and the object with the largest memory occupation corresponding to 1% thread quantity proportion in the first application instance is taken as a large object, and the associated interface list of the large object is obtained.

[0050] Specifically, if the garbage collection time interval of the first application instance is less than the time threshold, the second monitoring is performed; please refer to Figure 3 In this embodiment, the second monitoring is JProfiler monitoring, and the data of the memory objects in a period of time is monitored through the monitoring.

[0051] The size of each object in the Figure 3 The size of each object in the

[0052] The large object with the largest memory size corresponding to 1% instance count is obtained, and the associated interfaces of the large object are associated through the node tree, so that the interface list of the large object can be obtained.

[0053] S23, after the interface list of the large object is associated, the stream cutting operation is automatically performed, and each interface in the interface list of the large object is cut to the second application instance.

[0054] S3, if the garbage collection time interval of the first application instance and the second application instance is greater than or equal to the time threshold, the interfaces of the large object are cut back to the first application instance.

[0055] Specifically, the garbage collection time interval of the main application instance after stream cutting should be larger, and when the garbage collection time interval is greater than or equal to the time threshold, it means that the main application instance is stable and normal at this time, and the garbage collection time interval of the second application instance is continuously observed.

[0056] When the garbage collection time interval of the second application instance continuously increases to the time threshold for multiple periods, it means that the interface object is less, the cut interface can be restored to the main application instance, and the main application instance is continuously observed.

[0057] When the garbage collection time interval in the second application instance continuously decreases for multiple periods, it indicates that after the large object interface is switched to the second application instance, the garbage collection time interval still gradually decreases, and in this scenario, the external request volume may have really become very large, and manual intervention is required for analysis or the memory of the main application instance is expanded, and an alarm information can be issued to prompt relevant personnel.

[0058] If the garbage collection time interval in the first application instance is less than a time threshold, the step of performing second monitoring on the first application instance is returned to, and the large object occupying the most memory in the current first application instance is continuously obtained and switched.

[0059] Embodiment Two

[0060] Please refer to Figure 2 A garbage collection dynamic adjustment server 1 includes a memory 2, a processor 3, and a computer program stored in the memory 2 and executable on the processor 3, and the processor 3 implements each step of the garbage collection dynamic adjustment method of embodiment one when the computer program is executed.

[0061] In summary, the garbage collection dynamic adjustment method and server provided by the present application perform first monitoring on a first application instance in a virtual machine, perform second monitoring on the first application instance when the garbage collection time interval is monitored to decrease to a certain extent, obtain the interface list of the large object in the application instance, and switch the interface list corresponding to the large object to a second application instance. Since the interface of the large object is switched to other application instances, the object generation of the first application instance is effectively reduced, and the garbage collection time interval of the first application instance is further reduced, and when the garbage collection time interval of the switched large object is restored to a certain extent, it is switched back to the first application instance. In this way, only these interfaces are switched, and the other interfaces of the entire application instance still provide services to the outside, and the second application instance newly added only provides services to the interfaces of the large object, and therefore the garbage collection time interval can be dynamically adjusted to ensure the stability of the application instance.

[0062] The above description is only an embodiment of the present application, and does not limit the patent range of the present application, and any equivalent transformation or direct or indirect application in related technical fields using the content of the specification and drawings of the present application is also included in the patent protection range of the present application.

Claims

1. A method of dynamically adjusting garbage collection, characterized by, The method comprises the steps of: S1, performing first monitoring on a first application instance in a virtual machine, and obtaining a garbage collection time interval of the first application instance through the monitoring; S2, judging whether the garbage collection time interval of the first application instance is less than a time threshold value, if yes, performing second monitoring on the first application instance, monitoring objects and interfaces in the first application instance, obtaining a large object and interfaces of the large object in the first application instance which occupy the largest memory, and cutting the interfaces of the large object to a second application instance; S3, if the garbage collection time intervals of the first application instance and the second application instance are both greater than or equal to the time threshold value, cutting the interfaces of the large object back to the first application instance; Step S1 comprises: performing first monitoring on a first application instance in a virtual machine, and the first monitoring is used for monitoring a memory occupation ratio in the first application instance, and drawing a curve graph according to the memory occupation ratio; obtaining a garbage collection time interval of the first application instance according to a time difference of adjacent wave crests in the curve graph; obtaining a large object and interfaces of the large object in the first application instance which occupy the largest memory, comprising: obtaining a thread quantity proportion and a memory occupation size of each object in the first application instance, so as to calculate a memory occupation amount corresponding to 1% thread quantity proportion of each object in the first application instance; taking an object corresponding to the largest memory occupation amount of 1% thread quantity proportion in the first application instance as the large object, and obtaining an associated interface list of the large object; cutting the interfaces of the large object to a second application instance, and the method further comprises: if the garbage collection time interval of the first application instance is less than the time threshold value, returning to perform the step of performing second monitoring on the first application instance, and continuing to obtain the large object which occupies the largest memory in the current first application instance and perform cutting.

2. A method of dynamically adjusting garbage collection according to claim 1, characterized in that, The method further comprises: performing stress testing on the first application instance, and selecting a garbage collection time interval as the time threshold value according to a relationship between the garbage collection time interval and interface stability in the stress testing. 3.A garbage collection dynamic adjustment server, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein, The processor implements the following steps when executing the computer program: S1, performing first monitoring on a first application instance in a virtual machine, and obtaining a garbage collection time interval of the first application instance through the monitoring; S2, judging whether the garbage collection time interval of the first application instance is less than a time threshold value, if yes, performing second monitoring on the first application instance, monitoring objects and interfaces in the first application instance, obtaining a large object and interfaces of the large object in the first application instance which occupy the largest memory, and cutting the interfaces of the large object to a second application instance; S3, if the garbage collection time intervals of the first application instance and the second application instance are both greater than or equal to the time threshold value, cutting the interfaces of the large object back to the first application instance; Step S1 comprises: performing first monitoring on a first application instance in a virtual machine, and the first monitoring is used for monitoring a memory occupation ratio in the first application instance, and drawing a curve graph according to the memory occupation ratio; obtaining a garbage collection time interval of the first application instance according to a time difference between adjacent peaks in the curve; obtaining a large object occupying the most memory in the first application instance and an interface thereof, comprising: obtaining a thread quantity proportion and a memory occupation size of each object in the first application instance to calculate a memory occupation amount corresponding to 1% thread quantity proportion of each object in the first application instance; taking an object with the largest memory occupation amount corresponding to 1% thread quantity proportion in the first application instance as a large object and obtaining an associated interface list of the large object; cutting a stream of the interface of the large object to a second application instance, and further comprising: if the garbage collection time interval in the first application instance is less than a time threshold, returning to perform a step of second monitoring on the first application instance, and continuing to obtain a large object occupying the most memory in the current first application instance and to cut a stream.

4. A garbage-collected dynamic adjustment server according to claim 3, characterized in that, the monitoring obtains a garbage collection time interval of the first application instance, and further comprising: performing a stress test on the first application instance, and selecting a garbage collection time interval as the time threshold according to a relationship between the garbage collection time interval and interface stability in the stress test.

Citation Information

Patent Citations

  • Parallel mark processing and device for garbage collection

    CN107239406A

  • Garbage recycling method, system and equipment of collaborative instance, medium and product

    CN114330772A