Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the characteristics of the distributed system cache in the server

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "what are the characteristics of distributed system caching in the server". Many people will encounter this dilemma in the operation of actual cases. next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. The significance of caching

When it comes to distributed systems, caching is basically inseparable, and caching plays an important role in high concurrency and high traffic scenarios. Therefore, as a distributed system developer must be proficient in the use and design of cache. Here is a simple system architecture diagram

From the figure, we know the location of the cache at the system level, either inside or outside the application system. So what is the meaning of caching?

1. Shorten the response time of the system and improve the user experience. If the results required by user requests are already cached inside the system, then it is no longer necessary to perform subsequent operations such as external RPC,DB queries, and directly return the results to give users a smooth system experience.

2. Withstand more traffic and protect key system components. For example, if there is no cache protection in the scenario of high concurrency and high traffic, all requests will penetrate directly into our underlying DB. DB is basically unbearable. Once DB goes down, the whole system will basically over, but many caching middleware such as redis,memcache can handle it.

3. Improve the stability of the system and improve the overall throughput. The third point is actually summed up from the previous two points.

2. Classification of caches

According to the storage situation of the cache can be divided into: centralized cache, local cache, distributed cache.

Centralized caching: all caches are managed in one place.

Advantages: the data set is easy to manage, good consistency, good real-time, as long as you modify one place, you can see the effect immediately.

Disadvantages: centralized caches are usually stored outside the system, and bandwidth can easily become a bottleneck under high concurrent requests.

Optimization: reduce unnecessary data and store only the data you really need. Compress the data that is put into the cache, take it out and decompress it. The purpose is to reduce the occupation of tape completion in data transmission.

Local caching: also known as localCache, each application keeps a complete cached copy locally.

Advantages: good performance, no external access and no bandwidth pressure compared to centralized caching.

Disadvantages: the data is scattered and not easy to manage. Data consistency is poor and there is a delay in data synchronization between multiple replicas.

Optimization: it is necessary to add an expiration time to the local cache and establish a set of relatively real-time data update mechanism to ensure that the data of the copy can be updated effectively and timely.

Distributed caching: build caches in a cluster way, such as redis clusters.

Advantages: high performance, support for dynamic expansion, support for high availability

Distributed cache clusters are distributed to multiple machines to store data in the form of sharding, including client-side sharding (memcahed) and server-side sharding (redis). The hash algorithm used for sharding usually uses consistent hash. This section involves a lot of content, and I intend to discuss it independently later if I have time.

3. Characteristics of cache

Caching is also a data model object, so it must have some characteristics:

hit rate

Hit rate = number of correct results returned / number of requests for cache. Hit rate is a very important issue in cache, and it is an important indicator to measure the effectiveness of cache. The higher the hit rate, the higher the cache usage.

Maximum element (or maximum space)

The maximum number of elements that can be stored in the cache, once the number of elements in the cache exceeds this value (or the space occupied by the cache data exceeds its maximum supporting space), then it will trigger the cache emptying strategy to set the maximum element value reasonably according to different scenarios can improve the cache hit ratio to a certain extent, so as to cache more effectively.

4. Cache emptying strategy

As described above, the storage space of the cache is limited. When the cache space is full, how to effectively improve the hit rate while stabilizing the service? This is handled by the cache emptying strategy, and the design of an emptying strategy suitable for its own data characteristics can effectively improve the hit rate. Common general strategies are:

FIFO (first in first out)

In the first-in-first-out strategy, the data that first enters the cache will be cleared first when there is not enough cache space (exceeding the maximum element limit) to make room for new data. The policy algorithm mainly compares the creation time of cache elements. This kind of strategy can be selected in scenarios where data effectiveness is required, and priority is given to ensuring the availability of the latest data.

LFU (less frequently used)

At least use the policy, regardless of whether it is out of date or not, according to the number of times the element is used, clear the less frequently used element to release space. The policy algorithm mainly compares the hitCount (number of hits) of elements. In the scenario of ensuring the validity of high-frequency data, this kind of strategy can be selected.

LRU (least recently used)

Using the least recent policy, regardless of whether it is out of date or not, clears the element that uses the timestamp farthest to free space based on the timestamp that was last used by the element. The policy algorithm mainly compares the last time the element was used by get. It is more suitable in hot data scenarios, and priority is given to ensuring the validity of hot data.

In addition, there are some simple strategies such as:

Based on the expiration time, clean up the elements with the longest expiration time

Clean up the most recent elements that are about to expire based on the expiration time

Random cleaning

Clean up according to the length of keywords (or element contents), etc.

This is the end of the content of "what are the characteristics of distributed system caching in the server". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report