Take the cyberspace information service high-performance memory cache method accessing temperature into account
Technical field
The present invention relates to network geographic information system technology, a kind of cyberspace information service high-performance memory cache method taking access temperature into account.
Background technology
Cyberspace information service high-performance memory cache is one of major issue needing solution in network geographic information system (WebGIS), utilize the high-performance concurrent reading and writing performance of server memory, by in cyberspace information service request data buffer storage to the high-speed internal memory of server, the concurrent response efficiency of client request can be improved, but the memory source of server is limited, for large-scale massive spatial data, can only buffer unit divided data in the internal memory of server, when large user measure intensive concurrently access time, owing to a large amount of temporary visit data are added in limited memory cache, can cause carrying out the data in memory cache continually eliminating process, reduce efficiency and the cache hit rate of memory cache.
Summary of the invention
The technical problem to be solved in the present invention is for defect of the prior art, a kind of cyberspace information service high-performance memory cache method taken into account and access temperature is provided, reduce the superseded frequency of memory cache on server, improve cyberspace information service memory cache performance.
The technical solution adopted for the present invention to solve the technical problems is: a kind of cyberspace information service high-performance memory cache method taking access temperature into account, and it comprises the following steps:
Step 1: spatial data request number of times cache threshold (ACT) of server end, global memory's cache object maximum number (GCT), temporal cache object maximum number (TCT) are set.
Step 2: the spatial data request that received server-side client sends, it is thus achieved that the reference address of request.
Step 3: go to retrieve cache object from global memory caches as keyword using address, if global buffer hit, go to step 4;If during global memory's caching is lost one's life, going to step 6.
Step 4: update hit global memory's cache object finally access time attribute.
Step 5: the result data of storage in the cache object of hit is directly returned to client, terminates.
Step 6: retrieve the data of client request from spatial database.
Step 7: result data is returned to client.
Step 8: client request address is retrieved from temporal cache the temporal cache object of correspondence as keyword, if temporal cache hit, goes to step 9;If temporal cache is miss, go to step 15.
Step 9: obtain the access times (RAC) of temporal cache object.If RAC > ACT, go to step 10;Otherwise then go to step 14.
Step 10: result data current request obtained increases in global memory's caching.
Step 11: delete the temporal cache object of current request,
Step 12: obtain the caching number (GCC) in global memory's caching, if GCC>GCT, go to step 13, if GCC<GCT, terminates.
Step 13: delete in global memory's caching and be not accessed for a cache object at most, terminate.
Step 14: the access times (RAC) of temporal cache object are added 1, and update the last access time of temporal cache object, terminate.
Step 15: the access times of the temporal cache object of current request are initially 1, and are increased in temporal cache.
Step 16: obtain the cache object number (TCC) in temporal cache, if TCC > TCT, go to step 17;If TCC < TCT, terminate.
Step 17: delete in temporal cache and be not accessed for a cache object at most, terminates.
By such scheme, in described step 1), temporal cache and global buffer all use the form of key-value pair to store, and wherein, key is the address of request, and value is respectively temporal cache object and global buffer object.
By such scheme, the value of described each temporal cache object includes the last access time of request address and the access times to this address that its key is corresponding;The value of described each global buffer object includes the result data corresponding with this request of the last access time of the request address that its key is corresponding.
By such scheme, in described step 9), only just result data corresponding for request address is cached in global buffer when the access times of request address exceed threshold value.
The invention has the beneficial effects as follows and can judge whether to be cached in the memory cache of server request data according to the access temperature of cyberspace information service access request, to avoid storing some temporary visit number of times less data in the memory cache of server, reduce the conversion times of server memory caching, improving server end memory cache efficiency and cache hit rate, the large user improving cyberspace information service measures concurrent request processing performance.
Accompanying drawing explanation
Below in conjunction with drawings and Examples, the invention will be further described, in accompanying drawing:
Fig. 1 is the method flow diagram of the present invention.
Detailed description of the invention
In order to make the purpose of the present invention, technical scheme and advantage clearer, below in conjunction with embodiment, the present invention is further elaborated.Should be appreciated that specific embodiment described herein, only in order to explain the present invention, is not intended to limit the present invention.
As it is shown in figure 1, the cyberspace information service high-performance memory cache method flow diagram taking access temperature into account that Fig. 1 is the present invention to be provided, said method comprising the steps of:
Step 1: spatial data request number of times cache threshold (ACT) of server end, global memory's cache object maximum number (GCT), temporal cache object maximum number (TCT) are set.
Step 2: the spatial data request that received server-side client sends, it is thus achieved that the http address that request accesses.
Step 3: go to retrieve cache object from global memory caches as keyword using address, if global buffer hit, go to step 4;If during global memory's caching is lost one's life, going to step 6.
Global buffer object uses the form storage of key-value pair, the http address that request accesses is as key, value is a global buffer object class (GlobalCacheItem), its result data comprising request (data) and the time that finally accesses (lastAccessTime) of request.Global buffer object class is defined as follows:
Public class GlobalCacheItem
{
Public byte[] data;
Public DateTime lastAccessTime;
}
Step 4: obtain global memory's cache object (globalCacheObj) of hit, updates the time that finally accesses (lastAccessTime) attribute of globalCacheObj, is updated to current time.
Step 5: the result data (globalCacheObj.data) of storage in the cache object of hit is directly returned to client, terminates.
Step 6: retrieve the data of client request from spatial database.
Step 7: result data is returned to client.
Step 8: client request address is retrieved from temporal cache the temporal cache object of correspondence as keyword, if temporal cache hit, goes to step 9;If temporal cache is miss, go to step 15.
Temporal cache object uses the form storage of key-value pair, the http address that request accesses is as key, value is a temporal cache object class (TempCacheItem), its access times comprising request (RAC) and the time that finally accesses (lastAccessTime) of request.Temporal cache object class is defined as follows:
Public class TempCacheItem
{
Public int RAC;
Public DateTime lastAccessTime;
}
Step 9: obtain the temporal cache object (tempCacheObj) of hit, obtains the access times (tempCacheObj.RAC) of temporal cache object.If tempCacheObj.RAC > ACT, go to step 10;Otherwise then go to step 14.
Step 10: the result data of the current request obtained in step 6 is increased in global memory's caching.
Step 11: delete the temporal cache object (tempCacheObj) of current request,
Step 12: obtain the caching number (GCC) in global memory's caching, if GCC>GCT, go to step 13, if GCC<GCT, terminates.
Step 13: in caching according to global memory each cache object finally access time attribute (lastAccessTime), delete in global memory's caching and be not accessed for a cache object at most, terminate.
Step 14: the access times (tempCacheObj.RAC) of temporal cache object are added 1, and update the last access time (tempCacheObj.lastAccessTime) of temporal cache object, terminate.
Step 15: for the newly-built temporal cache object of current request, the access times (RAC) of the temporal cache object of current request are initially 1, finally accessing the time (lastAccessTime) is initially current time, and is increased in temporal cache.
Step 16: obtain the cache object number (TCC) in temporal cache, if TCC > TCT, go to step 17;If TCC < TCT, terminate.
Step 17: according in temporal cache each cache object finally access time attribute (lastAccessTime), delete in temporal cache and be not accessed for a cache object at most, terminate.
The most obvious difference of the present invention is to add temporal cache module, when server receive large user measure concurrent access request time, the most directly the result data of new request is increased in global memory's caching, and only access times and the last access time of request are stored in temporal cache, just the result data of request is cached in global memory's caching when access times exceed default threshold value.The method is it can be avoided that temporary visit number of times less data is stored in global memory's caching, reduce the frequency of replacement of global memory's caching, improve global memory's buffer efficiency and hit rate, improve the concurrent processing performance of cyberspace information service, especially when server memory resource is less, the advantage of the method becomes apparent from.
Embodiment one:
For the thought of the apparent explanation present invention, below the cyberspace information service high-performance memory cache method taking access temperature into account is further detailed, with the OGC in cyberspace information service
As a example by the GetCapabilities request of WMS service, spatial data request number of times cache threshold is set to 10, and global memory's cache object maximum number is set to 10000, and temporal cache object maximum number is set to 100.Specifically comprise the following steps that
Step 1: spatial data request number of times cache threshold (ACT=10) of server end, global memory's cache object maximum number (GCT=10000), temporal cache object maximum number (TCT=100) are set.
Step 2: the GetCapabilities request of the WMS service that received server-side client sends, it is thus achieved that the http address that GetCapabilities request accesses, request address form is as follows:
http://domain/wms?REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS
Step 3: go to retrieve cache object from global memory caches as keyword using the address obtained in step 2, if global buffer hit, go to step 4;If during global memory's caching is lost one's life, going to step 6.
Step 4: obtain global memory's cache object (globalCacheObj) of hit, updates the time that finally accesses (lastAccessTime) attribute of globalCacheObj, is updated to current time.
Step 5: the result data (globalCacheObj.data) of storage in the cache object of hit is directly returned to client, terminates.
Step 6: retrieve the data of client request from spatial database, generates according to the interface specification of WMS service and meets the result data that GetCapabilities service interface requires.
Step 7: result data is returned to client.
Step 8: client request address is retrieved from temporal cache the temporal cache object of correspondence as keyword, if temporal cache hit, goes to step 9;If temporal cache is miss, go to step 15.
Step 9: obtain the temporal cache object (tempCacheObj) of hit, obtains the access times (tempCacheObj.RAC) of temporal cache object.If tempCacheObj.RAC > 10, go to step 10;Otherwise then go to step 14.
Step 10: use the client request address obtained in step 2 as key, create the instance objects (globalItem) of a new GlobalCacheItem class, arranging its lastAccessTime attribute is current time, and it is set to the result data that data attribute is the current request obtained in step 6, then the global buffer object globalItem of this request is increased in global memory's caching.
Step 11: delete the temporal cache object (tempCacheObj) of current request,
Step 12: obtain the caching number (GCC) in global memory's caching, if GCC>10000, go to step 13, if GCC<10000, terminates.
Step 13: in caching according to global memory each cache object finally access time attribute (lastAccessTime), delete in global memory's caching and be not accessed for a cache object at most, terminate.
Step 14: the access times (tempCacheObj.RAC) of temporal cache object are added 1, and the last access time (tempCacheObj.lastAccessTime) updating temporal cache object be current time, terminates.
Step 15: for the instance objects (tempItem) of the newly-built TempCacheItem class of current request, its access times (RAC) are initially 1, finally accessing the time (lastAccessTime) is initially current time, use the client request address obtained in step 2 as key, the temporal cache object tempItem of this request is increased in temporal cache.
Step 16: obtain the cache object number (TCC) in temporal cache, if TCC > 100, go to step 17;If TCC < 100, terminate.
Step 17: according in temporal cache each cache object finally access time attribute (lastAccessTime), delete in temporal cache and be not accessed for a cache object at most, terminate.
Use present invention design takes the cyberspace information service high-performance memory cache method accessing temperature into account, when the concurrent access request of received server-side large user amount, it can be avoided that the request data of temporary visit joins in global memory's caching too much, efficiently reduce the displacement number of times of global memory's caching, it is favorably improved efficiency and the hit rate of global memory's caching, promotes the concurrent processing performance of cyberspace information service when large user measures intensive concurrently access.
It should be appreciated that for those of ordinary skills, can be improved according to the above description or be converted, and all these modifications and variations all should be belonged to the protection domain of claims of the present invention.