CN111209308B - Method and device for optimizing distributed cache - Google Patents
Method and device for optimizing distributed cache Download PDFInfo
- Publication number
- CN111209308B CN111209308B CN202010022449.3A CN202010022449A CN111209308B CN 111209308 B CN111209308 B CN 111209308B CN 202010022449 A CN202010022449 A CN 202010022449A CN 111209308 B CN111209308 B CN 111209308B
- Authority
- CN
- China
- Prior art keywords
- cache
- level
- data
- value
- level cache
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
- G06F16/24552—Database cache management
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2453—Query optimisation
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Computational Linguistics (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a method and a device for optimizing distributed cache, and relates to the technical field of computers. One embodiment of the method comprises the following steps: storing partial cache data in the first-level cache into a second-level cache when the first-level cache reaches the maximum data amount or the current time reaches the cleaning time of the first-level cache; and modifying the value of the partial cache data in the primary cache into the key value of the partial cache data in the secondary cache. The embodiment can solve the technical problem of performance degradation caused by a cache degradation strategy under the conditions of large data volume and long aging requirement.
Description
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for optimizing a distributed cache.
Background
The purpose of the cache is mainly as follows:
1) Improving the performance: a) In most cases, the select statement in SQL is where performance problems are greatest. On the one hand, select statements have many rich semantics like join, group, order, like, which are very performance-intensive; on the other hand, most applications are read-write-less, so the problem of slow query is aggravated; b) Remote invocation in a distributed system also reduces system performance because of network overhead, resulting in an overall response time extension. In order to save such performance overhead, it is very necessary to use a buffer under traffic-allowed conditions (data that is not needed in too real time).
2) And releasing the pressure of the database, namely, when the user requests to increase, the pressure of the database is greatly increased, and the pressure of the database can be greatly reduced through caching.
The distributed cache is one of caches, so that data can be shared among processes, network access cost is increased, the use amount of memory is reduced, and the distributed cache is an indispensable module in a distributed system and becomes a key component of a high-concurrency high-performance architecture.
Disk is a slow Input Output (IO) device relative to CPU cache and memory, disk IO consumption is the largest in the whole request response ratio, especially in IO intensive computing and high concurrency situations. In order to improve efficiency and corresponding transient peaks, most systems choose to save the process data in the memory buffer, and then write the process data to the disk asynchronously. When the memory buffer is full, the disc dropping process needs to be waited for.
Currently, most systems use a memory to cache frequently used data, and the size of the memory determines the amount of data to be cached. The cache data range of the distributed system is wider and wider, so that the data is often not only local database data, but also a large amount of remote call data, especially large data application. The data volume of the cache eventually exceeds the memory volume, and the main stream cache middleware adopts strategies such as disk dropping or cleaning cache which is not used for a long time to avoid memory stack overflow, which is also a protection mechanism of service degradation.
In the process of implementing the present invention, the inventor finds that at least the following problems exist in the prior art:
redis is a key-value store system. To ensure efficiency, data is buffered in memory. The Redis can periodically write updated data into the disk or write modification operation into the additional record file, so that the cache can be recovered from the disk file after power failure and restarting.
Memcached is a memory-based key-value store that is used to store arbitrary data (strings, objects) for small blocks. The data may be a database call, an interface call, or a result of a page rendering. Unlike Redis, it does not support persistence, i.e., the cache does not recover after a power-down restart.
The cache data volume of the distributed system is very large, benefits are sought to be maximized, and the purpose cannot be achieved by adding physical memory. If the performance of the cache is to be improved, the cost problem is solved by adopting a disk drop mode, and after all, the cost of the disk is far lower than that of the memory. If the database pressure is to be relieved, the problem of performance degradation after the disk is used must be solved.
However, memcached itself does not support data persistence, and power-down caches are lost, and it is assumed that long aging of the caches cannot be achieved. Redis adopts a data disk-dropping strategy, solves the problem that the cache data volume exceeds the physical memory limit, and also solves the problem of long aging, but has the problem that the performance is reduced when the service is degraded.
Disclosure of Invention
In view of this, the embodiments of the present invention provide a method and apparatus for optimizing a distributed cache, so as to solve the technical problem of performance degradation caused by a cache degradation policy under the requirements of a large data volume and long aging.
To achieve the above object, according to one aspect of the embodiments of the present invention, there is provided a method for optimizing a distributed cache, including:
if the first level buffer memory reaches the maximum data amount or the current time reaches the cleaning time of the first buffer memory, storing part of buffer memory data in the first level buffer memory into the second level buffer memory;
and modifying the value of the partial cache data in the primary cache into the key value of the partial cache data in the secondary cache.
Optionally, the first-level cache is a memory type cache, and the second-level cache is a document type cache.
Optionally, the in-memory type cache is Redis or Memcached, and the document type cache is MongoDB, cassandra or elastic search.
Optionally, the first level buffer reaches a maximum data size, including:
the data in the first-level cache reaches the maximum number, or the stored space of the first-level cache reaches the maximum storage space.
Optionally, storing the partial cache data in the first level cache into a second level cache, including:
respectively calculating hit rates of all cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold into a secondary cache.
Optionally, the method further comprises:
receiving and analyzing a service request to obtain a key value;
acquiring a value corresponding to the key value from the first-level cache according to the key value;
if the value in the first-level cache is the key value in the second-level cache, acquiring the value corresponding to the key value from the second-level cache, and returning the value in the second-level cache;
otherwise, directly returning the value in the first-level cache.
In addition, according to another aspect of the embodiment of the present invention, there is provided an apparatus for optimizing a distributed cache, including:
the buffer memory module is used for storing part of buffer memory data in the first-level buffer memory into the second-level buffer memory if the first-level buffer memory reaches the maximum data amount or the current time reaches the cleaning time of the first buffer memory;
and the optimization module is used for modifying the value of the partial cache data in the primary cache into the key value of the partial cache data in the secondary cache.
Optionally, the first-level cache is a memory type cache, and the second-level cache is a document type cache.
Optionally, the in-memory type cache is Redis or Memcached, and the document type cache is MongoDB, cassandra or elastic search.
Optionally, the first level buffer reaches a maximum data size, including:
the data in the first-level cache reaches the maximum number, or the stored space of the first-level cache reaches the maximum storage space.
Optionally, the cache module is further configured to:
respectively calculating hit rates of all cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold into a secondary cache.
Optionally, the method further comprises an acquisition module for:
receiving and analyzing a service request to obtain a key value;
acquiring a value corresponding to the key value from the first-level cache according to the key value;
if the value in the first-level cache is the key value in the second-level cache, acquiring the value corresponding to the key value from the second-level cache, and returning the value in the second-level cache;
otherwise, directly returning the value in the first-level cache.
According to another aspect of an embodiment of the present invention, there is also provided an electronic device including:
one or more processors;
storage means for storing one or more programs,
the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the methods of any of the embodiments described above.
According to another aspect of an embodiment of the present invention, there is also provided a computer readable medium having stored thereon a computer program which, when executed by a processor, implements the method according to any of the embodiments described above.
One embodiment of the above invention has the following advantages or benefits: because the technical means of storing part of cache data in the first-level cache into the second-level cache and modifying the value of the part of cache data in the first-level cache into the key value of the part of cache data in the second-level cache is adopted, the technical problem of performance degradation caused by cache degradation strategies under the requirements of large data volume and long time efficiency in the prior art is solved. The embodiment of the invention is used for layering the caches, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. The local landing disc is changed into a distributed landing disc, so that the landing disc efficiency is improved, and the retrieval speed is ensured. Meanwhile, computing resources of the first-level cache and the second-level cache are separated, the hit first-level cache is only searched in the memory type cache, the hit second-level cache is mainly computed in the document type cache, and intensive computation at the same node is avoided.
Further effects of the above-described non-conventional alternatives are described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main flow of a method of optimizing a distributed cache according to an embodiment of the present invention;
FIG. 2 is a schematic architecture diagram of a method of optimizing a distributed cache implementing an embodiment of the present invention;
FIG. 3 is a schematic diagram of the main flow of a method of optimizing a distributed cache according to one referenceable embodiment of the invention;
FIG. 4 is a schematic diagram of the main flow of a method of optimizing a distributed cache according to another referenceable embodiment of the invention;
FIG. 5 is a schematic diagram of the main modules of an apparatus for optimizing distributed caches according to an embodiment of the present invention;
FIG. 6 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
fig. 7 is a schematic diagram of a computer system suitable for use in implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
FIG. 1 is a schematic diagram of the main flow of a method of optimizing a distributed cache according to an embodiment of the present invention. As an embodiment of the present invention, as shown in fig. 1, the method for optimizing a distributed cache may include:
step 101, judging whether the first-level buffer memory reaches the maximum data amount or whether the current time reaches the cleaning time of the first buffer memory; if yes, go to step 102; if not, ending.
As shown in fig. 2, the embodiment of the present invention divides the cache into two layers: a first level cache and a second level cache. The first-level cache is a memory type cache, and the second-level cache is a document type cache. For example, the first-level cache may use the distributed nature and efficient key-value storage mode of the memory type cache such as Redis or Memcached; the secondary cache can be stored by using a MongoDB, cassandra or elastic search document type database and the like, so that the efficient data retrieval target is achieved. The first-level cache and the second-level cache can be deployed independently and support distributed deployment, so that the problems of local disk drop, data synchronization and disk IO waiting are avoided.
Optionally, as shown in fig. 2, in order to implement the method for optimizing a distributed cache according to the embodiment of the present invention, a cache access layer may be set up between a service logic layer and a cache, where the cache access layer executes the cache optimization method according to the embodiment of the present invention, and the cache access layer is a bridge connecting the service logic and the cache.
The maximum data amount of the primary cache or the flushing time of the primary cache may be preconfigured, and if the primary cache reaches the maximum data amount or if the current time reaches the flushing time of the first cache, step 102 is performed. In the embodiment of the invention, the maximum data amount or the cleaning time can be used as whether to trigger the cache optimization condition.
Optionally, the first level buffering up to the maximum data size includes: the data in the first-level cache reaches the maximum number, or the stored space of the first-level cache reaches the maximum storage space. In the embodiment of the invention, the number of the data stored in the first-level cache can be used as a judging basis for judging whether the maximum data volume is reached, and the stored space of the first-level cache can also be used as a judging basis for judging whether the maximum storage space is reached.
And 102, storing part of cache data in the primary cache into a secondary cache.
And if the first-level cache reaches the maximum data amount or the current time reaches the cleaning time of the first cache, storing part of cache data in the first-level cache into the second-level cache so as to release the storage space of the first-level cache. Otherwise, the data is still stored in the level one cache. Alternatively, in an embodiment of the present invention, the data cached in the first level cache may be a hotword search result cache, a system parameter cache, or the like.
Optionally, step 102 may include: respectively calculating hit rates (such as N times/minute) of each cache data in the first-level cache; and storing the cache data with the hit rate smaller than the preset frequency threshold into a secondary cache. The embodiment of the invention adopts a reference counting method to clean the cache data with low hit rate, and stores the cache data with low hit rate into a secondary cache.
And step 103, modifying the value of the partial cache data in the primary cache to the key value of the partial cache data in the secondary cache.
In order to ensure that the cache data can be queried in the secondary cache when the data is queried, the value of the part of cache data in the primary cache is also required to be modified into the key value of the part of cache data in the secondary cache. That is, the index key value of the secondary cache is written in the primary cache. Therefore, when a request is input, even if the second-level cache is hit, the cache data can be quickly retrieved through the second-level cache key.
According to the various embodiments described above, it can be seen that the technical means of storing part of cache data in the primary cache into the secondary cache and modifying the value of the part of cache data in the primary cache into the key value of the part of cache data in the secondary cache solves the technical problem of performance degradation caused by cache degradation strategies under the requirements of large data volume and long time in the prior art. The embodiment of the invention is used for layering the caches, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. The local landing disc is changed into a distributed landing disc, so that the landing disc efficiency is improved, and the retrieval speed is ensured. Meanwhile, computing resources of the first-level cache and the second-level cache are separated, the hit first-level cache is only searched in the memory type cache, the hit second-level cache is mainly computed in the document type cache, and intensive computation at the same node is avoided.
FIG. 3 is a schematic diagram of the main flow of a method of optimizing distributed caches according to one referenceable embodiment of the invention. As yet another embodiment of the present invention, as shown in fig. 3, the method for optimizing a distributed cache may include:
step 301, judging whether the first level buffer memory reaches the maximum data amount or whether the current time reaches the cleaning time of the first buffer memory; if yes, go to step 302; if not, ending.
The embodiment of the invention divides the cache into two layers: a first level cache and a second level cache. The first-level cache is a memory type cache, and the second-level cache is a document type cache. The first-level cache and the second-level cache can be deployed independently and support distributed deployment, so that the problems of local disk drop, data synchronization and disk IO waiting are avoided.
The maximum data amount of the primary cache or the flushing time of the primary cache may be preconfigured, and if the primary cache reaches the maximum data amount or if the current time reaches the flushing time of the first cache, step 302 is performed. In the embodiment of the invention, the maximum data amount or the cleaning time can be used as whether to trigger the cache optimization condition.
Step 302, respectively calculating hit rates of each cache data in the first-level cache.
And step 303, storing the cache data with the hit rate smaller than the preset frequency threshold into a secondary cache.
The embodiment of the invention adopts a reference counting method to clean the cache data with low hit rate, and stores the cache data with low hit rate into a secondary cache.
If the first-level cache is monitored to reach the maximum data amount or the current time reaches the cleaning time of the first cache, storing the cache data with the hit rate smaller than the preset frequency threshold value in the second-level cache. Otherwise, the data is still stored in the level one cache. Alternatively, in an embodiment of the present invention, the data cached in the first level cache may be a hotword search result cache, a system parameter cache, or the like.
And step 304, modifying the value of the cache data with the hit rate smaller than a preset frequency threshold in the first-level cache to be the key value of the partial cache data in the second-level cache.
In order to ensure that the cache data can be queried in the secondary cache when the data is queried, the value of the part of cache data in the primary cache is also required to be modified into the key value of the part of cache data in the secondary cache. That is, the index key value of the secondary cache is written in the primary cache. Therefore, when a request is input, even if the second-level cache is hit, the cache data can be quickly retrieved through the second-level cache key.
The existing cache middleware has no persistence function or uses a local disk-dropping mode, so that service degradation and performance reduction are finally caused. The embodiment of the invention is used for layering the caches, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. The local landing disc is changed into a distributed landing disc, so that the landing disc efficiency is improved, and the retrieval speed is ensured. Meanwhile, computing resources of the first-level cache and the second-level cache are separated, the hit first-level cache is only searched in the memory type cache, the hit second-level cache is mainly computed in the document type cache, and intensive computation at the same node is avoided.
In an embodiment of the present invention, a memory type cache of the first level cache may be used as a common memory type cache, such as Redis, memcached. The first-level cache provides a memory type cache, which has high access speed but a certain limit. The secondary cache may use MongoDB, cassandra or elastic search, etc., as long as it can reach the value that can be quickly indexed with key values and support distributed deployment. The secondary cache uses a document type cache, and the speed is high when the key value is used for searching the index, so that mass storage is supported.
In addition, the implementation of the method for optimizing the distributed cache in one reference embodiment of the present invention is already described in detail in the method for optimizing the distributed cache, and thus the description thereof will not be repeated here.
FIG. 4 is a schematic diagram of the main flow of a method of optimizing distributed caches according to another referenceable embodiment of the invention. As another embodiment of the present invention, as shown in fig. 4, the method for optimizing a distributed cache may include:
step 401, judging whether the first level buffer memory reaches the maximum data amount or whether the current time reaches the cleaning time of the first buffer memory; if yes, go to step 402; if not, ending.
Step 402, calculating hit rates of the cache data in the first-level cache respectively.
And step 403, storing the cache data with hit rate smaller than the preset frequency threshold into the secondary cache.
And step 404, modifying the value of the cache data with the hit rate smaller than the preset frequency threshold in the first-level cache into the key value of the partial cache data in the second-level cache.
And step 405, receiving and analyzing the service request to obtain a key value.
When the service request is input, the service request is analyzed to obtain the input parameters of the request, and thus the key value is obtained. For example, the key value may be obtained by assembling the parameters.
And step 406, obtaining a value corresponding to the key value from the first-level cache according to the key value.
Step 407, judging whether the value in the first-level cache is a key value in the second-level cache; if yes, go to step 408; if not, go to step 409.
Step 408, obtaining the value corresponding to the key value from the second-level cache, and returning the value in the second-level cache.
If the value is a key value in the secondary cache, the cache data corresponding to the key is stored in the secondary cache, so that the value corresponding to the key value is obtained from the secondary cache, and then the value in the secondary cache is returned. Therefore, when a request is input, even if the second-level cache is hit, the cache data can be quickly retrieved through the second-level cache key.
And step 409, directly returning the value in the first-level cache.
In addition, in another embodiment of the present invention, the implementation of the method for optimizing the distributed cache is already described in detail in the method for optimizing the distributed cache, so the description is not repeated here.
FIG. 5 is a schematic diagram of main modules of an apparatus for optimizing distributed caches according to an embodiment of the present invention, and as shown in FIG. 5, the apparatus 500 for optimizing distributed caches includes a cache module 501 and an optimizing module 502. The buffer module 501 is configured to store part of buffer data in the first level buffer into the second level buffer if the first level buffer reaches a maximum data amount or the current time reaches a cleaning time of the first buffer; the optimization module 502 is configured to modify a value of the partial cache data in the primary cache to a key value of the partial cache data in the secondary cache.
Optionally, the first-level cache is a memory type cache, and the second-level cache is a document type cache.
Optionally, the in-memory type cache is Redis or Memcached, and the document type cache is MongoDB, cassandra or elastic search.
Optionally, the first level buffer reaches a maximum data size, including:
the data in the first-level cache reaches the maximum number, or the stored space of the first-level cache reaches the maximum storage space.
Optionally, the cache module 501 is further configured to:
respectively calculating hit rates of all cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold into a secondary cache.
Optionally, the method further comprises an acquisition module 503, configured to:
receiving and analyzing a service request to obtain a key value;
acquiring a value corresponding to the key value from the first-level cache according to the key value;
if the value in the first-level cache is the key value in the second-level cache, acquiring the value corresponding to the key value from the second-level cache, and returning the value in the second-level cache;
otherwise, directly returning the value in the first-level cache.
According to the various embodiments described above, it can be seen that the technical means of storing part of cache data in the primary cache into the secondary cache and modifying the value of the part of cache data in the primary cache into the key value of the part of cache data in the secondary cache solves the technical problem of performance degradation caused by cache degradation strategies under the requirements of large data volume and long time in the prior art. The embodiment of the invention is used for layering the caches, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. The local landing disc is changed into a distributed landing disc, so that the landing disc efficiency is improved, and the retrieval speed is ensured. Meanwhile, computing resources of the first-level cache and the second-level cache are separated, the hit first-level cache is only searched in the memory type cache, the hit second-level cache is mainly computed in the document type cache, and intensive computation at the same node is avoided.
It should be noted that, in the specific implementation of the apparatus for optimizing distributed cache according to the present invention, the method for optimizing distributed cache has been described in detail above, so that the description is not repeated here.
FIG. 6 illustrates an exemplary system architecture 600 of a method of optimizing distributed caches or an apparatus for optimizing distributed caches to which embodiments of the invention may be applied.
As shown in fig. 6, the system architecture 600 may include terminal devices 601, 602, 603, a network 604, and a server 605. The network 604 is used as a medium to provide communication links between the terminal devices 601, 602, 603 and the server 605. The network 604 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 605 via the network 604 using the terminal devices 601, 602, 603 to receive or send messages, etc. Various communication client applications such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 601, 602, 603.
The terminal devices 601, 602, 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 605 may be a server providing various services, such as a background management server (by way of example only) providing support for shopping-type websites browsed by users using terminal devices 601, 602, 603. The background management server may analyze and process the received data such as the article information query request, and feedback the processing result (e.g., the target push information, the article information—only an example) to the terminal device.
It should be noted that, the method for optimizing the distributed cache according to the embodiment of the present invention is generally performed by the server 605, and accordingly, the device for optimizing the distributed cache is generally disposed in the server 605.
It should be understood that the number of terminal devices, networks and servers in fig. 6 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 7, there is illustrated a schematic diagram of a computer system 700 suitable for use in implementing an embodiment of the present invention. The terminal device shown in fig. 7 is only an example, and should not impose any limitation on the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 7, the computer system 700 includes a Central Processing Unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. In the RAM703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, ROM 702, and RAM703 are connected to each other through a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
The following components are connected to the I/O interface 705: an input section 706 including a keyboard, a mouse, and the like; an output portion 707 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage section 708 including a hard disk or the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. The drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read therefrom is mounted into the storage section 708 as necessary.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 709, and/or installed from the removable medium 711. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 701.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer programs according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules involved in the embodiments of the present invention may be implemented in software or in hardware. The described modules may also be provided in a processor, for example, as: a processor includes a caching module, an optimization module, and an acquisition module, where the names of the modules do not constitute a limitation on the module itself in some cases.
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include: if the first level buffer memory reaches the maximum data amount or the current time reaches the cleaning time of the first buffer memory, storing part of buffer memory data in the first level buffer memory into the second level buffer memory; and modifying the value of the partial cache data in the primary cache into a key of the partial cache data in the secondary cache.
According to the technical scheme provided by the embodiment of the invention, the technical means that partial cache data in the first-level cache is stored in the second-level cache, and the value of the partial cache data in the first-level cache is modified into the key value of the partial cache data in the second-level cache is adopted, so that the technical problem of performance degradation caused by cache degradation strategies under the conditions of large data volume and long aging requirements in the prior art is solved. The embodiment of the invention is used for layering the caches, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. The local landing disc is changed into a distributed landing disc, so that the landing disc efficiency is improved, and the retrieval speed is ensured. Meanwhile, computing resources of the first-level cache and the second-level cache are separated, the hit first-level cache is only searched in the memory type cache, the hit second-level cache is mainly computed in the document type cache, and intensive computation at the same node is avoided.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.
Claims (12)
1. A method for optimizing a distributed cache, comprising:
if the first level buffer memory reaches the maximum data amount or the current time reaches the cleaning time of the first buffer memory, storing part of buffer memory data in the first level buffer memory into the second level buffer memory;
modifying the value of the partial cache data in the primary cache into the key value of the partial cache data in the secondary cache;
receiving and analyzing a service request to obtain a key value;
acquiring a value corresponding to the key value from the first-level cache according to the key value;
if the value in the first-level cache is the key value in the second-level cache, acquiring the value corresponding to the key value from the second-level cache, and returning the value in the second-level cache;
otherwise, directly returning the value in the first-level cache.
2. The method of claim 1, wherein the first level cache is a memory type cache and the second level cache is a document type cache.
3. The method of claim 2, wherein the in-memory cache is Redis or Memcached and the document cache is MongoDB, cassandra or elastesearch.
4. The method of claim 1, wherein the level one cache reaches a maximum amount of data, comprising:
the data in the first-level cache reaches the maximum number, or the stored space of the first-level cache reaches the maximum storage space.
5. The method of claim 1, wherein storing the portion of the cache data in the primary cache into the secondary cache comprises:
respectively calculating hit rates of all cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold into a secondary cache.
6. An apparatus for optimizing a distributed cache, comprising:
the buffer memory module is used for storing part of buffer memory data in the first-level buffer memory into the second-level buffer memory if the first-level buffer memory reaches the maximum data amount or the current time reaches the cleaning time of the first buffer memory;
the optimization module is used for modifying the value of the partial cache data in the primary cache into the key value of the partial cache data in the secondary cache;
the device further comprises an acquisition module for:
receiving and analyzing a service request to obtain a key value;
acquiring a value corresponding to the key value from the first-level cache according to the key value;
if the value in the first-level cache is the key value in the second-level cache, acquiring the value corresponding to the key value from the second-level cache, and returning the value in the second-level cache;
otherwise, directly returning the value in the first-level cache.
7. The apparatus of claim 6, wherein the primary cache is a memory-type cache and the secondary cache is a document-type cache.
8. The apparatus of claim 7, wherein the in-memory cache is a dis or Memcached and the document cache is MongoDB, cassandra or elastic search.
9. The apparatus of claim 6, wherein the level one cache reaches a maximum amount of data, comprising:
the data in the first-level cache reaches the maximum number, or the stored space of the first-level cache reaches the maximum storage space.
10. The apparatus of claim 6, wherein the caching module is further configured to:
respectively calculating hit rates of all cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold into a secondary cache.
11. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs,
when executed by the one or more processors, causes the one or more processors to implement the method of any of claims 1-5.
12. A computer readable medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010022449.3A CN111209308B (en) | 2020-01-09 | 2020-01-09 | Method and device for optimizing distributed cache |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010022449.3A CN111209308B (en) | 2020-01-09 | 2020-01-09 | Method and device for optimizing distributed cache |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111209308A CN111209308A (en) | 2020-05-29 |
CN111209308B true CN111209308B (en) | 2023-06-16 |
Family
ID=70788995
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010022449.3A Active CN111209308B (en) | 2020-01-09 | 2020-01-09 | Method and device for optimizing distributed cache |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111209308B (en) |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101546292A (en) * | 2008-03-25 | 2009-09-30 | 北京恒光创新科技股份有限公司 | Memory access method and device |
CN102479207A (en) * | 2010-11-29 | 2012-05-30 | 阿里巴巴集团控股有限公司 | Information search method, system and device |
CN103092775A (en) * | 2013-01-31 | 2013-05-08 | 武汉大学 | Spatial data double cache method and mechanism based on key value structure |
CN103678638A (en) * | 2013-12-20 | 2014-03-26 | 厦门雅迅网络股份有限公司 | Object caching method based on disk |
CN104216838A (en) * | 2013-06-05 | 2014-12-17 | 北京齐尔布莱特科技有限公司 | Double-cache data processing method and system |
CN107748649A (en) * | 2017-09-18 | 2018-03-02 | 北京京东尚科信息技术有限公司 | A kind of data cached method and apparatus |
-
2020
- 2020-01-09 CN CN202010022449.3A patent/CN111209308B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101546292A (en) * | 2008-03-25 | 2009-09-30 | 北京恒光创新科技股份有限公司 | Memory access method and device |
CN102479207A (en) * | 2010-11-29 | 2012-05-30 | 阿里巴巴集团控股有限公司 | Information search method, system and device |
CN103092775A (en) * | 2013-01-31 | 2013-05-08 | 武汉大学 | Spatial data double cache method and mechanism based on key value structure |
CN104216838A (en) * | 2013-06-05 | 2014-12-17 | 北京齐尔布莱特科技有限公司 | Double-cache data processing method and system |
CN103678638A (en) * | 2013-12-20 | 2014-03-26 | 厦门雅迅网络股份有限公司 | Object caching method based on disk |
CN107748649A (en) * | 2017-09-18 | 2018-03-02 | 北京京东尚科信息技术有限公司 | A kind of data cached method and apparatus |
Also Published As
Publication number | Publication date |
---|---|
CN111209308A (en) | 2020-05-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11836533B2 (en) | Automated reconfiguration of real time data stream processing | |
CN109947668B (en) | Method and device for storing data | |
US11727004B2 (en) | Context dependent execution time prediction for redirecting queries | |
EP3436984A1 (en) | Managed function execution for processing data streams in real time | |
US20210216502A1 (en) | System and method for synchronizing delete operations between primary and secondary databases | |
US20200250095A1 (en) | Method, device and computer program product for accessing data | |
CN113568938A (en) | Data stream processing method and device, electronic equipment and storage medium | |
CN112445988A (en) | Data loading method and device | |
CN113760982B (en) | Data processing method and device | |
US20180018089A1 (en) | Storing data in a stub file in a hierarchical storage management system | |
CN111209308B (en) | Method and device for optimizing distributed cache | |
Chen et al. | Optimization research and application of enterprise website based on web service | |
CN111177109B (en) | Method and device for deleting expiration key | |
CN111459980A (en) | Monitoring data storage and query method and device | |
CN115617859A (en) | Data query method and device based on knowledge graph cluster | |
CN113051244B (en) | Data access method and device, and data acquisition method and device | |
CN113138943B (en) | Method and device for processing request | |
US10067678B1 (en) | Probabilistic eviction of partial aggregation results from constrained results storage | |
CN110879818B (en) | Method, device, medium and electronic equipment for acquiring data | |
CN113220981A (en) | Method and device for optimizing cache | |
CN108984431B (en) | Method and apparatus for flushing stale caches | |
US11055266B2 (en) | Efficient key data store entry traversal and result generation | |
CN109213815B (en) | Method, device, server terminal and readable medium for controlling execution times | |
CN113127416A (en) | Data query method and device | |
CN112699116A (en) | Data processing method and system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20220923 Address after: 12 / F, 15 / F, 99 Yincheng Road, China (Shanghai) pilot Free Trade Zone, Pudong New Area, Shanghai, 200120 Applicant after: Jianxin Financial Science and Technology Co.,Ltd. Address before: 25 Financial Street, Xicheng District, Beijing 100033 Applicant before: CHINA CONSTRUCTION BANK Corp. Applicant before: Jianxin Financial Science and Technology Co.,Ltd. |
|
TA01 | Transfer of patent application right | ||
GR01 | Patent grant | ||
GR01 | Patent grant |