Difference: LRU is the least recently used page replacement algorithm, which eliminates the pages that have not been used for the longest time; while LFU is the least recently used page replacement algorithm, which eliminates the pages that have been visited the fewest times in a certain period. The key to LRU is to look at the length of time from when the page was last used until scheduling occurs; while the key to LFU is to look at the frequency of page use within a certain period of time.
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
For web development, caching is essential and is also the most common way to improve performance. Whether it is the browser cache (if it is a chrome browser, you can view it through chrome:://cache), or the server-side cache (through an in-memory database such as memcached or redis). Caching can not only speed up user access, but also reduce server load and pressure. Then, it is particularly important to understand the strategies and principles of common cache elimination algorithms.
The cache strategy of browsers and memcached cache strategies all use the LRU algorithm. The LRU algorithm will cache the least accessed data in the near future. The data is eliminated. The reason why LRU is so popular is that it is relatively simple to implement, and it is also very practical for practical problems, with good runtime performance and high hit rate. Let’s talk about how to implement LRU cache:
LRU Cache has the following operations:
LRU is the least recently used page replacement algorithm (Least Recently Used), that is, it is eliminated first and has not been used for the longest time. Use the page!
LFU is the least frequently used page replacement algorithm (Least Frequently Used), which means to eliminate the page with the least number of visits within a certain period of time!
For example, the period T of the second method is 10 minutes. If paging is performed every minute, the main memory block is 3, and if the required page direction is 2 1 2 1 2 3 4
Note that when page 4 is adjusted, a page fault interrupt will occur.
If the LRU algorithm is used, page 1 should be changed (page 1 has not been used for the longest time), but page 3 should be changed according to the LFU algorithm (within ten minutes, Page 3 has only been used once)
It can be seen that the key to LRU is to look at the length of time between the last time the page was used and the scheduling;
And The key to LFU is to look at how often a page is used within a certain period of time!
For more related knowledge, please visit the FAQ column!
The above is the detailed content of What is the difference between lru and lfu algorithms?. For more information, please follow other related articles on the PHP Chinese website!