Whenever we want to relax reading, what usually comes to mind?

Prefetch, cache

The cache

Cache is to store frequently accessed data in memory to reduce the number of disk reads.

To improve memory utilization, MySQL also creates a buffer pool, or buffer pool, to store the hottest data pages and index pages.

Read ahead

As we know from the Linux file system, computer reads are page by page. So, can we take out the next page ahead of time, anyway, a disk IO.

LRU(Least recently used)

When it comes to caches and prefetches, LRU can’t get away with it. In short, it’s about flushing out the oldest memory in the pool and putting in new data.

  • Inside is a linked list structure, new at the head, out at the tail.
  • When you visit, if you’re in the pool, move to the head, if you’re not, move to the head and get rid of the tail.

So, are there any disadvantages?

Preread invalid: you put me do not read. It’s a waste of memory.

To optimize the

If you want to discriminate, separate them.

What we want to do is actually cache the data that we read, and cache the data that we read at a lower level.

So, quite simply, divide the memory pool into two parts, one for real read and one for preread.

This is the New sublist and the old sublist. The new tail is the head of the old.

The logic remains the same, but the length can be configured, such as 70% for the new station and 30% for the old one. The old one will be eliminated faster because it is shorter.

So, is it perfect?

Cache pool contamination: If THE SQL needs to scan a large number of rows, all data may be replaced, which means the cache is invalidated.

Optimization of 2.0

Whenever you want to prevent discriminating transactions from being forced to mix, add thresholds so that lower levels don’t pass.

All the data are first thrown into the old inside, stay longer than T, can enter the new generation, so that the old is constantly refreshed, and the real need will gradually enter the new generation.

Related parameters

  • Cache pool size
  • Old generation ratio
  • Residence time of old generation

conclusion

  • If something is wrong, please point it out.
  • If you don’t understand, please point out and LET me add chestnuts.
  • If you feel OK, you can like it and let more people see it.