Summary of the invention
The object of this invention is to provide method and the device of the many instance datas of a kind of buffer memory, the data cached committed memory space that utilization rate is not high can either be avoided, also can reduce the expense of cpu and unnecessary DataBase combining as far as possible, reduce the pressure of database.
A method for the many instance datas of buffer memory, safeguards there is active instance list, at least comprises field: the time T of example id and the last request server end data of example in described active instance list in the internal memory of server end;
Described method comprises:
When receiving the request of data that a certain example is sent, if do not find this example in described active instance list, then the id of this example is added in described active instance list, and the time T of correspondence is set to the time of current server end, and inquire about the data of this example from database after, return to client corresponding to this example;
If found this example in described active instance list, then the data cached of this example is returned to client corresponding to this example, and upgraded the last-minute plea time of corresponding instance in described active instance list.
Described from database, inquire about the data of this example after return to client corresponding to this example after, described method also comprises:
The data of this example inquired from database are put into buffer memory.
Described method also comprises:
Regularly updating maintenance is carried out to described active instance list.
Describedly regularly updating maintenance is carried out to described active instance list and is specially:
Make regular check on the last update time of each example in described active instance list;
If the difference of the last update time of a certain example and current time exceedes the threshold value of setting, then judge that this example is inactive example, and this example is deleted from described active instance list.
Described this example is deleted from described active instance list after, also comprise:
To exist in the buffer but the data cached deletion of non-existent example in described active instance list.
A device for the many instance datas of buffer memory, described device comprises:
Active instance list management unit, for safeguarding active instance list, at least comprises field in described active instance list: the time T of example id and the last request server end data of example;
Data receipt unit, for receiving the request of data that a certain example is sent;
Instance data processing unit, the request of data sent for a certain example received according to described data receipt unit carries out searching process in described active instance list, specifically comprise: if do not find this example in described active instance list, then the id of this example is added in described active instance list, and the time T of correspondence is set to the time of current server end, and inquire about the data of this example from database after, return to client corresponding to this example; If found this example in described active instance list, then the data cached of this example is returned to client corresponding to this example, and upgraded the last-minute plea time of corresponding instance in described active instance list.
Described device also comprises:
Data cached administrative unit, for inquiring about the data of this example at described instance data processing unit and after returning to client corresponding to this example, the data of this example inquired from database being put into buffer memory from database.
Described active instance list management unit is further used for regularly carrying out updating maintenance to described active instance list.
Described active instance list management unit comprises updating maintenance module further, for making regular check on the last update time of each example in described active instance list; If the difference of the last update time of a certain example and current time exceedes the threshold value of setting, then judge that this example is inactive example, and this example is deleted from described active instance list.
Described updating maintenance module also for: will exist in the buffer but the data cached deletion of non-existent example in described active instance list.
As seen from the above technical solution provided by the invention, the data cached committed memory space that the method can either avoid utilization rate not high, also can reduce the expense of cpu and unnecessary DataBase combining as far as possible, reduces the pressure of database.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, be clearly and completely described the technical scheme in the embodiment of the present invention, obviously, described embodiment is only the present invention's part embodiment, instead of whole embodiments.Based on embodiments of the invention, those of ordinary skill in the art, not making the every other embodiment obtained under creative work prerequisite, belong to protection scope of the present invention.
The embodiment of the present invention by adding active instance list in the internal memory of server end, this active instance list of Dynamic Maintenance is carried out according to the data of client-requested server end, and server end only carries out data buffer storage to the example in this active instance list, avoid the data cached committed memory space that utilization rate is not high, also can reduce the expense of cpu and unnecessary DataBase combining as far as possible, reduce the pressure of database.Be described in further detail the embodiment of the present invention below in conjunction with accompanying drawing, Fig. 1 provides by the embodiment of the present invention method flow schematic diagram of the many instance datas of buffer memory, and described method comprises:
Step 11: safeguard there is active instance list in the internal memory of server end, and only updating maintenance is carried out to the data cached of all examples be present in described active instance list;
In this step, following field is at least comprised in this active instance list: the time T of example id and the last request server end data of example.
Step 12: when receiving the request of data that a certain example is sent, searches active instance list;
Step 13: if do not find this example in described active instance list, then the id of this example is added in described active instance list, and the time T of correspondence is set to the time of current server end, and inquire about the data of this example from database after, return to client corresponding to this example;
In this step, further the data of this example inquired from database can also be put into buffer memory, thus ensure that the example in active instance list has the data cached of correspondence.
Step 14: if found this example in described active instance list, then return to client corresponding to this example by the data cached of this example, and upgrade the last-minute plea time of corresponding instance in described active instance list.
In this step, current time specifically can be utilized to upgrade the last-minute plea time, such as, use the time of current server end to upgrade the last-minute plea time of corresponding instance in described active instance list.
In specific implementation, regularly can also carry out updating maintenance to described active instance list, detailed process is:
Make regular check on the last update time of each example in described active instance list;
If the difference of the last update time of a certain example and current time exceedes the threshold value of setting, then judge that this example is inactive example, and this example is deleted from described active instance list;
For example, threshold value can be set to 12 hours, if check, one of them example last update time was before 2 days, exceed set threshold value, then judge that this example is inactive example, so just this example is deleted from active instance list, so just can keep the validity of active instance list always, reduce the buffer memory pressure of server end.
And can also exist in the buffer but the data cached deletion of non-existent example in described active instance list further, with ensure carry out safeguarding data cached be all useful, data cachedly to empty very low for utilization rate, to save memory consumption.
For example, if said 100 examples, wherein there are 20 examples to enliven always, such as be kept on all the monitor client moment and check current monitor data, other 80 examples are inactive, within such as two days, log in a monitor client, check five minutes at every turn, just exit supervisory system if not abnormal.In such a scenario, server end only needs to provide data buffer storage to 20 active instance, and other 80 examples can not provide buffer memory completely, which reduces taking of memory cost and cpu, the enquiry frequency of other 80 is very low simultaneously, also substantially can ignore the pressure of database.
The operation of above steps all can have been come by server end or the device be integrated in server end.
Based on the method for the many instance datas of above-mentioned buffer memory, the embodiment of the present invention additionally provides the device of the many instance datas of a kind of buffer memory, is illustrated in figure 2 the structural representation of described device, and described device comprises:
Active instance list management unit, for safeguarding active instance list, at least comprises field in described active instance list: the time T of example id and the last request server end data of example;
Data receipt unit, for receiving the request of data that a certain example is sent;
Instance data processing unit, the request of data sent for a certain example received according to described data receipt unit carries out searching process in described active instance list, specifically comprise: if do not find this example in described active instance list, then the id of this example is added in described active instance list, and the time T of correspondence is set to the time of current server end, and inquire about the data of this example from database after, return to client corresponding to this example; If found this example in described active instance list, then the data cached of this example is returned to client corresponding to this example, and upgraded the last-minute plea time of corresponding instance in described active instance list.
In specific implementation, described device also can comprise:
Data cached administrative unit, for inquiring about the data of this example at described instance data processing unit and after returning to client corresponding to this example, the data of this example inquired from database being put into buffer memory from database.
Above-mentioned active instance list management unit can also be used for regularly carrying out updating maintenance to described active instance list further, specifically, active instance list management unit can comprise updating maintenance module, for making regular check on the last update time of each example in described active instance list; If the difference of the last update time of a certain example and current time exceedes the threshold value of setting, then judge that this example is inactive example, and this example is deleted from described active instance list;
Updating maintenance module can also be used for: will exist in the buffer but the data cached deletion of non-existent example in described active instance list.
The specific works process of said apparatus is as described in above-mentioned embodiment of the method.
In sum, the data cached committed memory space that method described in the embodiment of the present invention can either avoid utilization rate not high, needs the example quantity upgraded to lack when upgrading buffer memory because each; Also can reduce the expense of cpu and unnecessary DataBase combining as far as possible, reduce the pressure of database.
The above; be only the present invention's preferably embodiment, but protection scope of the present invention is not limited thereto, is anyly familiar with those skilled in the art in the technical scope that the present invention discloses; the change that can expect easily or replacement, all should be encompassed within protection scope of the present invention.Therefore, protection scope of the present invention should be as the criterion with the protection domain of claims.