CN111209308A - Method and device for optimizing distributed cache - Google Patents

Method and device for optimizing distributed cache Download PDF

Info

Publication number
CN111209308A
CN111209308A CN202010022449.3A CN202010022449A CN111209308A CN 111209308 A CN111209308 A CN 111209308A CN 202010022449 A CN202010022449 A CN 202010022449A CN 111209308 A CN111209308 A CN 111209308A
Authority
CN
China
Prior art keywords
cache
level cache
level
data
value
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.)
Granted
Application number
CN202010022449.3A
Other languages
Chinese (zh)
Other versions
CN111209308B (en
Inventor
黄显龙
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CCB Finetech Co Ltd
Original Assignee
China Construction Bank Corp
CCB Finetech Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by China Construction Bank Corp, CCB Finetech Co Ltd filed Critical China Construction Bank Corp
Priority to CN202010022449.3A priority Critical patent/CN111209308B/en
Publication of CN111209308A publication Critical patent/CN111209308A/en
Application granted granted Critical
Publication of CN111209308B publication Critical patent/CN111209308B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • YGENERAL 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
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE 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/00Energy 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: when the first-level cache reaches the maximum data volume or the current time reaches the cleaning time of the first-level cache, storing part of cache data in the first-level cache into a 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. The implementation method can solve the technical problem of performance degradation caused by a cache degradation strategy under the requirements of large data volume and long time efficiency.

Description

Method and device for optimizing distributed cache
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for optimizing distributed cache.
Background
The purpose of caching is mainly as follows:
1) performance is improved: a) in most cases, the select statement in SQL is where the largest performance problem occurs. On one hand, select statements have many rich semantics like join, group, order, like, which are very performance consuming; on the other hand, most applications read more and write less, thus aggravating the problem of slow queries; b) remote invocation in a distributed system may also reduce system performance, which may result in an overall extended response time due to network overhead. To save such performance overhead, it is very necessary to use buffering when traffic allows it (not requiring too real-time data).
2) And the database pressure is relieved, namely when the user requests increase, the pressure of the database is greatly increased, and the pressure of the database can be greatly reduced through cache.
The distributed cache is one of caches, enables data to be shared among processes, increases network access cost, reduces the usage amount of a memory, is an essential 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, as compared to CPU caches and memory, and disk IO consumption is the largest in the overall request-response ratio, especially under IO-intensive computation and high concurrency. In order to improve the efficiency and corresponding instantaneous peak value, most systems select to firstly store the processing process data in a memory buffer area and then asynchronously write the processing process data into a disk. When the memory buffer is full, the completion of the disk dropping process needs to be waited.
At present, most systems cache frequently used data by using a memory, and the size of the memory determines the amount of the cached data. The range of cached data of a distributed system is wider and wider, and the cached data is not only local database data but also comprises a large amount of remote calling data, especially large-data application. The data volume of the cache exceeds the memory volume finally, and the main stream cache middleware avoids the overflow of the memory stack by adopting strategies such as disk dropping or cleaning of the cache which is not used for a long time, which is also a protection mechanism for service degradation.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
redis is a key-value storage system. To ensure efficiency, data is cached in memory. Redis can periodically write updated data into a disk or write modification operation into an additional recording file, so that the cache can be recovered from the disk file after power failure restart.
Memcached is a memory-based key-value store that is used to store arbitrary data (strings, objects) of small blocks. These data may be database calls, interface calls, or the result of page rendering. Unlike Redis, it does not support persistence, i.e., the cache will not recover after a power-down restart.
The cache data volume of the distributed system is very large in demand, the benefit maximization is sought, and the aim cannot be achieved by increasing the physical memory. If the performance of the cache is to be improved, the cost problem must be solved by adopting a disk falling mode, and after all, the disk cost is far lower than that of the memory. If the database pressure is relieved, the problem of performance reduction after the magnetic disk is used must be solved.
However, Memcached does not support data persistence itself, and a power-down cache is lost, which is supposed not to achieve long-term aging of the cache. Redis adopts a data-dropping strategy, solves the problem that the amount of cached data exceeds the physical memory limit, and also solves the long-term efficiency problem, but the performance is reduced when the service is degraded.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an 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 large data volume and long lifetime.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method for optimizing a distributed cache, including:
if the first-level cache reaches the maximum data volume or the current time reaches the cleaning time of the first cache, storing part of cache data in the first-level cache into a 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.
Optionally, the first-level cache is a memory-type cache, and the second-level cache is a document-type cache.
Optionally, the memory-type cache is Redis or Memcached, and the document-type cache is MongoDB, Cassandra, or ElasticSearch.
Optionally, the first-level cache reaching a maximum data size includes:
the cache 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 a part of the cache data in the first-level cache into a second-level cache, including:
respectively calculating the hit rate of each cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold value into a second-level 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, obtaining 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 embodiments of the present invention, there is provided an apparatus for optimizing a distributed cache, including:
the cache module is used for storing part of cache data in the first-level cache into the second-level cache if the first-level cache reaches the maximum data volume or the current time reaches the cleaning time of the first cache;
and the optimization module is used for 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.
Optionally, the first-level cache is a memory-type cache, and the second-level cache is a document-type cache.
Optionally, the memory-type cache is Redis or Memcached, and the document-type cache is MongoDB, Cassandra, or ElasticSearch.
Optionally, the first-level cache reaching a maximum data size includes:
the cache 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 the hit rate of each cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold value into a second-level cache.
Optionally, the system further comprises an obtaining module, 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, obtaining 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 the embodiments of the present invention, there is also provided an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any of the embodiments described above.
According to another aspect of the embodiments of the present invention, there is also provided a computer readable medium, on which a computer program is stored, which when executed by a processor implements the method of any of the above embodiments.
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 reduction caused by a cache degradation strategy under the requirements of large data volume and long time efficiency in the prior art is solved. The embodiment of the invention has the layered cache, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. And the local tray falling is changed into the distributed tray falling, so that the tray falling efficiency is improved, and the retrieval speed is ensured. Meanwhile, the computing resources of the first-level cache and the second-level cache are separated, the first-level cache is hit and only searched in the memory type cache, and the second-level cache is hit and mainly calculated in the document type cache, so that intensive calculation at the same node is avoided.
Further effects of the above-mentioned non-conventional alternatives will be 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 invention;
FIG. 2 is a schematic diagram of an architecture for implementing a method for optimizing distributed caches according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating a main flow of a method of optimizing a distributed cache according to one referenceable embodiment of the present invention;
FIG. 4 is a diagram illustrating a main flow of a method of optimizing a distributed cache according to another referential embodiment of the present invention;
FIG. 5 is a schematic diagram of the main modules of an apparatus for optimizing a distributed cache 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 employed;
fig. 7 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as 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 a main flow of a method for 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 cache reaches the maximum data volume or whether the current time reaches the cleaning time of the first cache; if yes, go to step 102; if not, the process is ended.
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 characteristic and the efficient key-value storage mode of the internal memory type cache such as Redis or Memcached; the secondary cache can use document type databases such as MongoDB, Cassandra or ElasticSearch to store, and the aim of efficient data retrieval is achieved. The first-level cache and the second-level cache can be independently deployed and support distributed deployment, so that the problems of local disk drop, data synchronization and disk IO (input/output) 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 installed 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 size of the first-level cache or the flush time of the first-level cache may be preconfigured, and if the first-level cache reaches the maximum data size or the current time reaches the flush time of the first cache, step 102 is performed. In the embodiment of the present invention, the maximum data amount or the flush time may be used as whether to trigger the cache optimization condition.
Optionally, the reaching of the maximum data amount by the first-level cache includes: the cache 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 present invention, the number of data stored in the first-level cache may be used as a criterion for determining whether the maximum data amount is reached, or the stored space of the first-level cache may be used as a criterion for determining whether the maximum storage space is reached.
And 102, storing part of cache data in the first-level cache into a second-level cache.
If the first-level cache reaches the maximum data volume or the current time reaches the cleaning time of the first cache, storing part of cache data in the first-level cache into a 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. Optionally, in an embodiment of the present invention, the data cached in the first level cache may be a hot word search result cache, a system parameter cache, or the like.
Optionally, step 102 may comprise: respectively calculating the hit rate (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 value into a second-level cache. The embodiment of the invention adopts a reference counting method to clean the cache data with low hit rate and store the cache data with low hit rate into the second-level cache.
Step 103, modifying the value of the part of cache data in the first-level cache to the key value of the part of cache data in the second-level cache.
In order to ensure that when data is queried, cache data can be queried in the second-level cache, and the value of the part of cache data in the first-level cache needs to be modified into the key value of the part of cache data in the second-level cache. That is, the index key of the second level cache is written in the first level cache. Therefore, when a request comes in, even if the hit is the second level cache, 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 problem of performance degradation caused by a cache degradation policy under large data volume and long-term efficiency requirements in the prior art is solved by a technical means of storing part of cache data in a first-level cache into a second-level cache, and modifying a value of the part of cache data in the first-level cache into a key value of the part of cache data in the second-level cache. The embodiment of the invention has the layered cache, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. And the local tray falling is changed into the distributed tray falling, so that the tray falling efficiency is improved, and the retrieval speed is ensured. Meanwhile, the computing resources of the first-level cache and the second-level cache are separated, the first-level cache is hit and only searched in the memory type cache, and the second-level cache is hit and mainly calculated in the document type cache, so that intensive calculation at the same node is avoided.
Fig. 3 is a schematic diagram of a main flow of a method of optimizing a distributed cache according to one referential embodiment of the present invention. As 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 cache reaches the maximum data volume or whether the current time reaches the cleaning time of the first cache; if yes, go to step 302; if not, the process is ended.
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 independently deployed and support distributed deployment, so that the problems of local disk drop, data synchronization and disk IO (input/output) waiting are avoided.
The maximum data size of the first-level cache or the flush time of the first-level cache may be preconfigured, and if the first-level cache reaches the maximum data size or the current time reaches the flush time of the first cache, step 302 is performed. In the embodiment of the present invention, the maximum data amount or the flush time may be used as whether to trigger the cache optimization condition.
Step 302, respectively calculating the hit rate of each cache data in the first-level cache.
Step 303, storing the cache data with the hit rate less than the preset frequency threshold into a second level cache.
The embodiment of the invention adopts a reference counting method to clean the cache data with low hit rate and store the cache data with low hit rate into the second-level cache.
And if the first-level cache reaches the maximum data volume or the current time reaches the cleaning time of the first cache, storing the cache data with the hit rate smaller than a preset frequency threshold value in the first-level cache into a second-level cache. Otherwise, the data is still stored in the level one cache. Optionally, in an embodiment of the present invention, the data cached in the first level cache may be a hot word search result cache, a system parameter cache, or the like.
Step 304, modifying the value of the cache data with the hit rate smaller than the preset frequency threshold in the first-level cache to the key value of the partial cache data in the second-level cache.
In order to ensure that when data is queried, cache data can be queried in the second-level cache, and the value of the part of cache data in the first-level cache needs to be modified into the key value of the part of cache data in the second-level cache. That is, the index key of the second level cache is written in the first level cache. Therefore, when a request comes in, even if the hit is the second level cache, the cache data can be quickly retrieved through the second level cache key.
The existing caching middleware has no persistence function or uses a local disk-dropping mode, and finally, service degradation and performance reduction are caused. The embodiment of the invention has the layered cache, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. And the local tray falling is changed into the distributed tray falling, so that the tray falling efficiency is improved, and the retrieval speed is ensured. Meanwhile, the computing resources of the first-level cache and the second-level cache are separated, the first-level cache is hit and only searched in the memory type cache, and the second-level cache is hit and mainly calculated in the document type cache, so that intensive calculation at the same node is avoided.
In the embodiment of the present invention, the memory type cache of the first-level cache may use common cache such as Redis, Memcached, and the like. The first-level cache provides a memory type cache, and has high access speed but limited quantity. The secondary cache can use MongoDB, Cassandra or ElasticSearch, and the like, as long as the purpose that the value can be quickly indexed by the key value and distributed deployment is supported can be achieved. The second-level cache uses a document cache, is high in speed when the key value is used for searching the index, and supports mass storage.
In addition, in a referential embodiment of the present invention, the detailed implementation content of the method for optimizing a distributed cache is already described in detail in the above-mentioned method for optimizing a distributed cache, so that the repeated content will not be described again.
Fig. 4 is a schematic diagram of a main flow of a method of optimizing a distributed cache according to another referenceable embodiment of the present 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 cache reaches the maximum data volume or whether the current time reaches the cleaning time of the first cache; if yes, go to step 402; if not, the process is ended.
Step 402, respectively calculating the hit rate of each cache data in the first-level cache.
And step 403, storing the cache data with the hit rate smaller than the preset frequency threshold into a second-level cache.
In step 404, the value of the cache data with the hit rate smaller than the preset frequency threshold in the first-level cache is modified to the key value of the partial cache data in the second-level cache.
Step 405, receiving and analyzing the service request to obtain a key value.
When the service request is transmitted, the service request is analyzed to obtain the access parameter of the request, so that the key value is obtained. For example, the key value may be obtained by assembling the parameter.
And step 406, acquiring a value corresponding to the key value from the primary cache according to the key value.
Step 407, determining whether the value in the first-level cache is the key value in the second-level cache; if yes, go to step 408; if not, go to step 409.
And step 408, obtaining a value corresponding to the key value from the second-level cache, and returning the value in the second-level cache.
If the value is the key value in the second-level cache, it indicates that the cache data corresponding to the key has been stored in the second-level cache, so the value corresponding to the key value is obtained from the second-level cache, and then the value in the second-level cache is returned. Therefore, when a request comes in, even if the hit is the second level cache, 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 detailed implementation of the method for optimizing a distributed cache is described in detail in the above-mentioned method for optimizing a distributed cache, and therefore, the repeated content will not be described again.
Fig. 5 is a schematic diagram of main modules of an apparatus for optimizing a distributed cache according to an embodiment of the present invention, and as shown in fig. 5, the apparatus 500 for optimizing a distributed cache includes a cache module 501 and an optimization module 502. The cache module 501 is configured to store a part of cache data in the first-level cache into the second-level cache if the first-level cache reaches a maximum data size or the current time reaches the cleaning time of the first cache; the optimization module 502 is configured to modify a value of the partial cache data in the first-level cache to a key value of the partial cache data in the second-level cache.
Optionally, the first-level cache is a memory-type cache, and the second-level cache is a document-type cache.
Optionally, the memory-type cache is Redis or Memcached, and the document-type cache is MongoDB, Cassandra, or ElasticSearch.
Optionally, the first-level cache reaching a maximum data size includes:
the cache 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 caching module 501 is further configured to:
respectively calculating the hit rate of each cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold value into a second-level cache.
Optionally, an obtaining module 503 is further included, 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, obtaining 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 problem of performance degradation caused by a cache degradation policy under large data volume and long-term efficiency requirements in the prior art is solved by a technical means of storing part of cache data in a first-level cache into a second-level cache, and modifying a value of the part of cache data in the first-level cache into a key value of the part of cache data in the second-level cache. The embodiment of the invention has the layered cache, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. And the local tray falling is changed into the distributed tray falling, so that the tray falling efficiency is improved, and the retrieval speed is ensured. Meanwhile, the computing resources of the first-level cache and the second-level cache are separated, the first-level cache is hit and only searched in the memory type cache, and the second-level cache is hit and mainly calculated in the document type cache, so that intensive calculation at the same node is avoided.
It should be noted that, in the implementation of the apparatus for optimizing a distributed cache according to the present invention, the details of the method for optimizing a distributed cache are already described in detail above, and therefore, the repeated contents are not described again here.
Fig. 6 illustrates an exemplary system architecture 600 to which the method for optimizing distributed caching or the apparatus for optimizing distributed caching of embodiments of the present 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 serves to provide a medium for communication links between the terminal devices 601, 602, 603 and the server 605. Network 604 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use the terminal devices 601, 602, 603 to interact with the server 605 via the network 604 to receive or send messages or the like. The terminal devices 601, 602, 603 may have installed thereon various communication client applications, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 601, 602, 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 605 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 601, 602, 603. The background management server may analyze and otherwise process the received data such as the item information query request, and feed back a processing result (for example, target push information, item information — just an example) to the terminal device.
It should be noted that the method for optimizing the distributed cache provided by the embodiment of the present invention is generally performed by the server 605, and accordingly, the apparatus 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, shown is a block diagram of a computer system 700 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments 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 in accordance with 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 necessary for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM703 are connected to each other via 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 portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and 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. A 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 out therefrom is mounted into the storage section 708 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the 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 illustrated in the flow chart. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 701.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination 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 present invention, 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, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. 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 flowchart 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 described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a caching module, an optimization module, and an acquisition module, where the names of the modules do not in some cases constitute a limitation on the modules themselves.
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 separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: if the first-level cache reaches the maximum data volume or the current time reaches the cleaning time of the first cache, storing part of cache data in the first-level cache into a second-level cache; and modifying the value of the part of cache data in the first-level cache into the key of the part of cache data in the second-level cache.
According to the technical scheme of the embodiment of the invention, because the technical means that part of cache data in the first-level cache is stored into the second-level cache and the value of the part of cache data in the first-level cache is modified into the key value of the part of cache data in the second-level cache is adopted, the technical problem of performance reduction caused by a cache degradation strategy under the requirements of large data volume and long time effectiveness in the prior art is solved. The embodiment of the invention has the layered cache, the memory type cache is used as a first-level cache, and the document type cache is used as a second-level cache. And the local tray falling is changed into the distributed tray falling, so that the tray falling efficiency is improved, and the retrieval speed is ensured. Meanwhile, the computing resources of the first-level cache and the second-level cache are separated, the first-level cache is hit and only searched in the memory type cache, and the second-level cache is hit and mainly calculated in the document type cache, so that intensive calculation at the same node is avoided.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (14)

1. A method for optimizing distributed caching, comprising:
if the first-level cache reaches the maximum data volume or the current time reaches the cleaning time of the first cache, storing part of cache data in the first-level cache into a 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.
2. The method of claim 1, wherein the primary cache is a memory-type cache and the secondary 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 ElasticSearch.
4. The method of claim 1, wherein the level one cache reaching a maximum amount of data comprises:
the cache 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 cached data in the level one cache into a level two cache comprises:
respectively calculating the hit rate of each cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold value into a second-level cache.
6. The method of claim 1, further comprising:
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, obtaining 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. An apparatus for optimizing distributed caching, comprising:
the cache module is used for storing part of cache data in the first-level cache into the second-level cache if the first-level cache reaches the maximum data volume or the current time reaches the cleaning time of the first cache;
and the optimization module is used for 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.
8. The apparatus of claim 7, wherein the primary cache is a memory-type cache and the secondary cache is a document-type cache.
9. The apparatus of claim 8, wherein the in-memory cache is Redis or Memcached, and wherein the document cache is MongoDB, Cassandra, or ElasticSearch.
10. The apparatus of claim 7, wherein the level one cache reaching a maximum amount of data comprises:
the cache data in the first-level cache reaches the maximum number, or the stored space of the first-level cache reaches the maximum storage space.
11. The apparatus of claim 7, wherein the caching module is further configured to:
respectively calculating the hit rate of each cache data in the first-level cache;
and storing the cache data with the hit rate smaller than the preset frequency threshold value into a second-level cache.
12. The apparatus of claim 7, further comprising an acquisition module 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, obtaining 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.
13. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-6.
14. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-6.
CN202010022449.3A 2020-01-09 2020-01-09 Method and device for optimizing distributed cache Active CN111209308B (en)

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 true CN111209308A (en) 2020-05-29
CN111209308B 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)

* Cited by examiner, † Cited by third party
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

Patent Citations (6)

* Cited by examiner, † Cited by third party
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
CN111209308B (en) 2023-06-16

Similar Documents

Publication Publication Date Title
US11580176B2 (en) Search infrastructure
CN109947668B (en) Method and device for storing data
US9369332B1 (en) In-memory distributed cache
US20200250095A1 (en) Method, device and computer program product for accessing data
CN111782692A (en) Frequency control method and device
CN112445988A (en) Data loading method and device
US20180018089A1 (en) Storing data in a stub file in a hierarchical storage management system
CN107748649B (en) Method and device for caching data
CN111459980A (en) Monitoring data storage and query method and device
CN111209308B (en) Method and device for optimizing distributed cache
CN113051244B (en) Data access method and device, and data acquisition method and device
US10067678B1 (en) Probabilistic eviction of partial aggregation results from constrained results storage
CN113821461B (en) Domain name resolution caching method, DNS server and computer readable storage medium
US11681680B2 (en) Method, device and computer program product for managing index tables
CN113138943B (en) Method and device for processing request
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
CN113448957A (en) Data query method and device
CN113127416A (en) Data query method and device
Cheng et al. Improving LSM‐trie performance by parallel search
CN112699116A (en) Data processing method and system
CN112783925B (en) Paging retrieval method and device
US11586604B2 (en) In-memory data structure for data access

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