Summary of the invention
The application is intended to solve at least some of the technical problems in related technologies.
For this purpose, first purpose of the application is to propose a kind of method for preventing memory from exhausting, this method can in time to
Administrative staff send the warning message of releasing memory, facilitate administrative staff to discharge in time, application server is avoided memory consumption occur
Most situation, and then the stability and robustness of server can be improved.
Second purpose of the application is to propose a kind of device for preventing memory from exhausting.
In order to achieve the above object, the application first aspect embodiment proposes a kind of method for preventing memory from exhausting, comprising: when
When monitoring the operation of inquiry database, the operation of the inquiry database is intercepted;And for behavior is intercepted every time, judge institute
Whether returning the result for the inquiry operation of interception is to preset object then to obtain element in the default object if default object
Size, and determine according to the size of element in preassigned and the default object of acquisition the rank of corresponding monitored object,
So that monitor supervision platform counts the monitored object for the different stage being collected into, when the monitored object quantity of different stage reaches
When corresponding threshold value, the warning message of releasing memory is sent.
The embodiment of the present application prevents the method that memory exhausts, and intercepts the operation of inquiry database, and for interception every time
Behavior judges whether returning the result for intercepted inquiry operation is default object, if default object, then obtains default object
The size of middle element, and the grade for corresponding to monitored object is determined according to the size of element in preassigned and the default object of acquisition
Not, so that monitor supervision platform counts the monitored object for the different stage being collected into, when the monitored object quantity of different stage
When reaching corresponding threshold value, the warning message of releasing memory is sent, so that administrative staff are according to the timely releasing memory of warning message,
It avoids application server from the case where memory exhausts occur, and then the stability and robustness of server can be improved.
In order to achieve the above object, the application second aspect embodiment proposes a kind of device for preventing memory from exhausting, comprising: block
Module is cut, for when monitoring the operation of inquiry database, intercepting the operation of the inquiry database;And processing module,
For for behavior is intercepted every time, judging whether returning the result for intercepted inquiry operation is default object, if default pair
As then obtaining the size of element in the default object, and according to element in preassigned and the default object of acquisition
Size determines the rank of corresponding monitored object, so that monitor supervision platform counts the monitored object for the different stage being collected into,
When the monitored object quantity of different stage reaches corresponding threshold value, the warning message of releasing memory is sent.
The embodiment of the present application prevents the device that memory exhausts, and the operation of inquiry database, needle are intercepted by blocking module
Behavior is intercepted to each, processing module judges whether returning the result for intercepted inquiry operation is default object, if default
Object then obtains the size of element in default object, and true according to the size of element in preassigned and the default object of acquisition
Surely the rank of monitored object is corresponded to, so that monitor supervision platform counts the monitored object for the different stage being collected into, works as difference
When the monitored object quantity of rank reaches corresponding threshold value, the warning message of releasing memory is sent, so that administrative staff are according to report
The alert timely releasing memory of information, avoids application server from the case where memory exhausts occur, and then the stability of server can be improved
And robustness.
Specific embodiment
Embodiments herein is described below in detail, examples of the embodiments are shown in the accompanying drawings, wherein from beginning to end
Same or similar label indicates same or similar element or element with the same or similar functions.Below with reference to attached
The embodiment of figure description is exemplary, it is intended to for explaining the application, and should not be understood as the limitation to the application.
Below with reference to the accompanying drawings the method and device for preventing memory from exhausting of the embodiment of the present application is described.
Fig. 1 is the flow chart of the method for preventing memory from exhausting of the application one embodiment, as shown in Figure 1, in this prevents
Depositing the method exhausted includes:
S101 intercepts the operation of the inquiry database when monitoring the operation of inquiry database.
In this embodiment, firstly, creating an interception function based on tangent plane programming, wherein the interception function is mainly used
In the inquiry operation that interception application server is sent to database.Then, the inquiry behaviour that application server is sent to database
It is monitored, when monitoring the inquiry operation that application server is sent to database, inquires number by intercepting intercepting api calls
According to the operation in library.
S102 intercepts behavior for each, judges whether returning the result for intercepted inquiry operation is default object, if
To preset object, then the size of element in default object is obtained, and according to element in preassigned and the default object of acquisition
Size determines the rank of corresponding monitored object, so that monitor supervision platform counts the monitored object for the different stage being collected into,
When the monitored object quantity of different stage reaches corresponding threshold value, the warning message of releasing memory is sent.
After obtaining inquiry database manipulation by intercepting function, it can determine whether that returning the result for intercepted inquiry operation is
It is no for default object, wherein above-mentioned default object may include set, above-mentioned set can be set (collection), list (list) and
Map (mapping) etc..When above-mentioned inquiry operation return the result be that default object is for example gathered when, can obtain first in default object
The size of element is then based on the rank that preassigned determines monitored object corresponding to default object, is determining corresponding monitoring pair
After the rank of elephant, the monitored object of appropriate level can print.Wherein, above-mentioned monitored object can include but is not limited to log.
For example, preset standard are as follows: the size of element is less than or equal to 1k in default object, and the rank of corresponding log is
DEBUG rank;The size of element is greater than 1k in default object, and is less than or equal to 5k, and the rank of corresponding log is INFO
Rank;The size of element is greater than 5k in default object, and is less than or equal to 1M, and the rank of corresponding log is WARN rank;
The size of element is greater than 1M in default object, and the rank of corresponding log is ERROR rank.If it is determined that element in default object
Size is 25k, can determine that the rank of the default corresponding log of object is WARN rank, exportable WARN according to preset standard
The log of rank.
In this embodiment, when the inquiry operation intercepted return the result be not default object when, can check return
As a result whether comprising default object in corresponding object properties, if obtaining element in the default object comprising presetting object
Size.
For example, do not gather when intercepting returning the result for the inquiry operation that is intercepted of function, when general object, can look into
Whether see in the corresponding attribute of object comprising set, if comprising set, gather in element size, and according to calibrating in advance
The quasi- size with element in the set obtained determines the rank of the log of corresponding set.
During printing the log of appropriate level, monitor supervision platform collects the log of different stage, and to different stage
Log counted, if the quantity of the log of corresponding level be more than corresponding threshold value, monitor supervision platform can by mail and/
Or the mode of short message sends the warning message of different stage to related personnel.Related personnel is in the alarm for receiving monitor supervision platform transmission
After information, the memory in application server can be discharged in time according to warning message.
For example it is assumed that the corresponding threshold value of log that INFO rank is arranged in monitor supervision platform is 30000, the day of WARN rank
The corresponding threshold value of will is 10000.If the quantity that monitor supervision platform monitors the log of INFO rank has been more than 30000, or
The log quantity of person's WARN rank is more than 10000, at this point, monitor supervision platform can be by way of short message or mail to management
Personnel send warning message, administrative staff receive monitor supervision platform send warning message after, can timely releasing memory, avoid answering
There is the case where memory exhausts with server, and then the stability and robustness of application server can be improved.
The embodiment of the present application prevents the method that memory exhausts, and intercepts the operation of inquiry database, and for interception every time
Behavior judges whether returning the result for intercepted inquiry operation is default object, if default object, then obtains default object
The size of middle element, and the grade for corresponding to monitored object is determined according to the size of element in preassigned and the default object of acquisition
Not, so that monitor supervision platform counts the monitored object for the different stage being collected into, when the monitored object quantity of different stage
When reaching corresponding threshold value, the warning message of releasing memory is sent, so that administrative staff are according to the timely releasing memory of warning message,
It avoids application server from the case where memory exhausts occur, and then the stability and robustness of server can be improved.
In order to realize above-described embodiment, the application also proposes a kind of device for preventing memory from exhausting.
Fig. 2 is the structural schematic diagram of the device for preventing memory from exhausting of the application one embodiment, as shown in Fig. 2, the dress
Set includes: blocking module 100 and processing module 200, in which:
Blocking module 100 is used to intercept the operation of inquiry database when monitoring the operation of inquiry database;And place
It manages module 200 and is used for judging whether returning the result for intercepted inquiry operation is default object for behavior is intercepted every time, if
To preset object, then the size of element in default object is obtained, and according to element in preassigned and the default object of acquisition
Size determines the rank of corresponding monitored object, so that monitor supervision platform counts the monitored object for the different stage being collected into,
When the monitored object quantity of different stage reaches corresponding threshold value, the warning message of releasing memory is sent.
Wherein, above-mentioned default object may include set.Above-mentioned set can be set (collection), list (list) and map
(mapping) etc., above-mentioned monitored object can include but is not limited to log.
Specifically, when processing module 200 determine inquiry operation return the result be that default object is for example gathered when, can obtain
The size that element in object must be preset is then based on the rank that preassigned determines log corresponding to default object, and true
Surely after the rank for corresponding to log, the log of appropriate level is printed.
For example, preset standard are as follows: the size of element is less than or equal to 1k in default object, and the rank of corresponding log is
DEBUG rank;The size of element is greater than 1k in default object, and is less than or equal to 5k, and the rank of corresponding log is INFO
Rank;The size of element is greater than 5k in default object, and is less than or equal to 1M, and the rank of corresponding log is WARN rank;
The size of element is greater than 1M in default object, and the rank of corresponding log is ERROR rank.If it is determined that element in default object
Size is 25k, and processing module 200 can determine that the rank of the default corresponding log of object is WARN grades according to preset standard
Not, and the log of WARN rank is printed.
Above-mentioned blocking module 100 is used to inquire the operation of database by intercepting intercepting api calls.
In addition, the creation module 300 is for intercepting as shown in figure 3, above-mentioned apparatus can also include creation module 300
Before operation of the module by intercepting intercepting api calls inquiry database, function is intercepted based on tangent plane programming creation.
Above-mentioned processing module 200 is also used to: if returning the result for the inquiry operation intercepted is not default object, being checked
It returns the result whether comprising default object in corresponding object properties, if obtaining element in default object comprising presetting object
Size.
Specifically, it when processing module 200 judges that returning the result for intercepted inquiry operation is not default object, can look into
It sees and returns the result whether comprising default object in corresponding object properties, if returning the result in corresponding object properties comprising default
Object, then obtain the size of element in corresponding default object, and according in preassigned and the default object of acquisition element it is big
The rank of small determining corresponding log works as different stage so that monitor supervision platform counts the log for the different stage being collected into
Log quantity when reaching corresponding threshold value, monitor supervision platform sends the warning message of different stage by mail and/or short message.By
This, so that administrative staff can avoid application server from the case where memory exhausts occur according to the timely releasing memory of warning message, into
And the stability and robustness of application server can be improved.
The process that the device for preventing memory from exhausting prevents memory from exhausting can be found in Fig. 1, not repeat herein.
The embodiment of the present application prevents the device that memory exhausts, and the operation of inquiry database, needle are intercepted by blocking module
Behavior is intercepted to each, processing module judges whether returning the result for intercepted inquiry operation is default object, if default
Object then obtains the size of element in default object, and true according to the size of element in preassigned and the default object of acquisition
Surely the rank of monitored object is corresponded to, so that monitor supervision platform counts the monitored object for the different stage being collected into, works as difference
When the monitored object quantity of rank reaches corresponding threshold value, the warning message of releasing memory is sent, so that administrative staff are according to report
The alert timely releasing memory of information, avoids application server from the case where memory exhausts occur, and then the stability of server can be improved
And robustness.
In the description of this specification, reference term " one embodiment ", " some embodiments ", " example ", " specifically show
The description of example " or " some examples " etc. means specific features, structure, material or spy described in conjunction with this embodiment or example
Point is contained at least one embodiment or example of the application.In the present specification, schematic expression of the above terms are not
It must be directed to identical embodiment or example.Moreover, particular features, structures, materials, or characteristics described can be in office
It can be combined in any suitable manner in one or more embodiment or examples.In addition, without conflicting with each other, the skill of this field
Art personnel can tie the feature of different embodiments or examples described in this specification and different embodiments or examples
It closes and combines.
In addition, term " first ", " second " are used for descriptive purposes only and cannot be understood as indicating or suggesting relative importance
Or implicitly indicate the quantity of indicated technical characteristic.Define " first " as a result, the feature of " second " can be expressed or
Implicitly include at least one this feature.In the description of the present application, the meaning of " plurality " is at least two, such as two, three
It is a etc., unless otherwise specifically defined.
Any process described otherwise above or method description are construed as in flow chart or herein, and expression includes
It is one or more for realizing specific logical function or process the step of executable instruction code module, segment or portion
Point, and the range of the preferred embodiment of the application includes other realization, wherein can not press shown or discussed suitable
Sequence, including according to related function by it is basic simultaneously in the way of or in the opposite order, Lai Zhihang function, this should be by the application
Embodiment person of ordinary skill in the field understood.
Expression or logic and/or step described otherwise above herein in flow charts, for example, being considered use
In the order list for the executable instruction for realizing logic function, may be embodied in any computer-readable medium, for
Instruction execution system, device or equipment (such as computer based system, including the system of processor or other can be held from instruction
The instruction fetch of row system, device or equipment and the system executed instruction) it uses, or combine these instruction execution systems, device or set
It is standby and use.For the purpose of this specification, " computer-readable medium ", which can be, any may include, stores, communicates, propagates or pass
Defeated program is for instruction execution system, device or equipment or the dress used in conjunction with these instruction execution systems, device or equipment
It sets.The more specific example (non-exhaustive list) of computer-readable medium include the following: there is the electricity of one or more wirings
Interconnecting piece (electronic device), portable computer diskette box (magnetic device), random access memory (RAM), read-only memory
(ROM), erasable edit read-only storage (EPROM or flash memory), fiber device and portable optic disk is read-only deposits
Reservoir (CDROM).In addition, computer-readable medium can even is that the paper that can print described program on it or other are suitable
Medium, because can then be edited, be interpreted or when necessary with it for example by carrying out optical scanner to paper or other media
His suitable method is handled electronically to obtain described program, is then stored in computer storage.
It should be appreciated that each section of the application can be realized with hardware, software, firmware or their combination.Above-mentioned
In embodiment, software that multiple steps or method can be executed in memory and by suitable instruction execution system with storage
Or firmware is realized.It, and in another embodiment, can be under well known in the art for example, if realized with hardware
Any one of column technology or their combination are realized: having a logic gates for realizing logic function to data-signal
Discrete logic, with suitable combinational logic gate circuit specific integrated circuit, programmable gate array (PGA), scene
Programmable gate array (FPGA) etc..
Those skilled in the art are understood that realize all or part of step that above-described embodiment method carries
It suddenly is that relevant hardware can be instructed to complete by program, the program can store in a kind of computer-readable storage medium
In matter, which when being executed, includes the steps that one or a combination set of embodiment of the method.
It, can also be in addition, can integrate in a processing module in each functional unit in each embodiment of the application
It is that each unit physically exists alone, can also be integrated in two or more units in a module.Above-mentioned integrated mould
Block both can take the form of hardware realization, can also be realized in the form of software function module.The integrated module is such as
Fruit is realized and when sold or used as an independent product in the form of software function module, also can store in a computer
In read/write memory medium.
Storage medium mentioned above can be read-only memory, disk or CD etc..Although having been shown and retouching above
Embodiments herein is stated, it is to be understood that above-described embodiment is exemplary, and should not be understood as the limit to the application
System, those skilled in the art can be changed above-described embodiment, modify, replace and become within the scope of application
Type.