In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article is about ways to improve redis cache hit rate. Xiao Bian thinks it is quite practical, so share it for everyone to make a reference. Let's follow the editor and have a look.
Introduction to cache hit ratio
Hit: You can get the data you need directly through the cache.
Missed: Unable to get the desired data directly through the cache, you need to query the database again or perform other operations. This may be because the cache does not exist at all or because the cache has expired.
Generally speaking, the higher the cache hit rate, the higher the profit from using the cache, the better the performance of the application (the shorter the response time, the higher the throughput), and the stronger the anti-concurrency ability.
Thus, in a highly concurrent Internet system, cache hit rate is a crucial indicator.
How to monitor cache hit rates
In memcached, run the state command to view the status information of memcached service, where cmd_get represents the total number of gets, get_hits represents the total number of hits of get, hit rate = get_hits/cmd_get.
Of course, we can also monitor the entire memcached cluster through some open source third-party tools, which will be more intuitive. Typical examples include zabbix, MemAdmin, etc.
Figure: MemAdmin's monitoring statistics on the hit rate of memcached services
Similarly, you can run info command in redis to view the status information of redis service, where keyspace_hits is the total number of hits, keyspace_misses is the total number of misses, hit rate =keyspace_hits/(keyspace_hits+keyspace_misses).
The open source tool Redis-star provides graphical visualization of redis services, while zabbix provides plug-ins for monitoring redis services.
Several factors affecting cache hit rate
We mentioned the importance of cache hit ratio in the previous chapter. Here are a few factors that affect cache hit ratio.
Business scenarios and business requirements
Cache is suitable for business scenarios where there is more reading and less writing. On the contrary, the use of cache is not meaningful, and the hit rate will be very low.
Business requirements dictate timeliness requirements, which directly affect cache expiration times and update policies. The lower the timeliness requirement, the more suitable it is for caching. For the same key and the same number of requests, the longer the cache time, the higher the hit rate.
Most business scenarios for Internet applications are suitable for caching.
Design of cache (granularity and policy)
In general, the smaller the granularity of the cache, the higher the hit rate. A practical example:
When caching a single object (e.g., a single user), we need to update or remove the cache only if the data corresponding to that object changes. When caching a collection (e.g., all user data), the cache needs to be updated or removed when the data corresponding to any of the objects changes.
In another case, assuming that other places also need to obtain the data corresponding to the object (for example, other places also need to obtain single user information), if the cache is a single object, it can hit the cache directly, otherwise, it cannot hit directly. This is more flexible and the cache hit rate will be higher.
In addition, cache update/expiration policy also directly affects cache hit rate. When the data changes, updating the cache value directly will have a higher hit rate than removing the cache (or letting the cache expire), and of course the system complexity will be higher.
Cache capacity and infrastructure
Cache capacity is limited, it is easy to cause cache failure and be eliminated (most of the cache framework or middleware are currently using the LRU algorithm). At the same time, the selection of cache technology is also crucial, for example, the use of built-in local cache is more prone to single bottleneck, and the use of distributed cache is easy to expand after all. Therefore, it is necessary to plan the system capacity and consider whether it can be expanded. In addition, different cache frameworks or middleware have different efficiency and stability.
other factors
When a cache node fails, the need to avoid cache failures and minimize the impact is also a special case that the architect needs to consider. A typical approach in the industry is to use consistent Hash algorithms or node redundancy.
Some friends may have this misunderstanding: since the business requirements for data timeliness requirements are very high, and cache time will affect the cache hit rate, then the system should not use cache. In fact, this ignores an important factor-concurrency. In general, for the same cache time and key, the higher the concurrency, the higher the cache revenue, even if the cache time is short.
A Method to Improve Cache Hit Rate
From the architect's perspective, applications need to fetch data directly through the cache as much as possible and avoid cache invalidation. This is also a test of the architect's ability, which needs to be considered and weighed in terms of business requirements, cache granularity, cache strategy, technology selection, etc. Focus as much as possible on the hot spot services with high frequency access and low timeliness requirements, and improve the hit rate by means of cache preloading (preheating), increasing storage capacity, adjusting cache granularity, updating cache, etc.
For applications with high timeliness (or limited cache space), large content span (or random access), and low access volume, the cache hit rate may be low for a long time, and the warmed cache may expire before it is accessed.
Thank you for reading! The method of improving redis cache hit rate is shared here. I hope the above content can be of some help to everyone, so that everyone can learn more knowledge. If you think the article is good, you can share it so that more people can see it!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.