Technology Sharing

Redis thread model

2024-07-08

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

0. Reference

[Redis thread model]
【Big key troubleshooting and solutions】

1. Understanding of Redis single thread

Why single thread: CPU is not the performance bottleneck (memory and network), single thread can meet business requirements

Network IO and key-value pair reading and writing are all done by one thread

insert image description here

2. Understanding Redis multithreading

Persistence (aof, rdb), asynchronous deletion (big key), data replication (master-slave, sentinel, cluster) use multithreading

insert image description here

3. Challenges of single-threaded IO: big key problem

detailed:【Big key troubleshooting and solutions】

Normally, the del command can quickly delete data. However, when the key to be deleted is a very large object, such as a hash set containing tens of thousands of elements, the del command will cause the Redis main thread to freeze.

The Big Key problem is essentially a Big Value problem

insert image description here

3.0 Simulate inserting 1 million data

for((i=1;i