当前位置:网站首页>Redis big key problem
Redis big key problem
2022-06-22 22:39:00 【miaoao611】
1 What is big key
Redis There are several common data structures in , Each structure has a large key The definition of is different , such as :
value yes String Type ,size exceed 10KB For big key;
value yes ZSET、Hash、List、Set Is equal to the collection type , It has more members than 1 Ten thousand is big key.
2 Big key What's the impact?
We all know ,Redis A typical feature of is : The core worker thread is a single thread .
The processing of request tasks in a single thread is serial : If the front is not finished , I can't handle it later . At the same time, it also leads to memory data and data in distributed architecture CPU The imbalance of .
- Large execution key The client of the command itself , Time consuming has increased significantly , Even overtime ;
- Large execution key Related read or delete operations , It will seriously occupy bandwidth and CPU, Affect other clients ;
- Big key Its own storage leads to the imbalance of piecewise data in distributed system ,CPU The utilization rate is also uneven ;
- Big key Sometimes it's hot key, Frequent read operations , The impact will be great ;
- Large execution key deleted , In low version Redis Threads may be blocked in .
So it looks big key The impact of is still obvious , The most typical is blocking threads , Concurrency is down , Cause client timeout , The business success rate of the service side decreased .
3. Big key How did it come about
Big key It is often caused by the unreasonable design of the business party , Not foreseen vaule The dynamic growth of :
(1) Keep going value Plug data , There is no deletion mechanism , It will explode sooner or later ;
(2) The data is not segmented reasonably , Will be big key Become small key.
- How to find big key
4.1 Increase memory 、 Traffic 、 Timeout and other indicators monitoring
Because of the big key Of value It's big , Threads may be blocked while reading . Lead to Redis whole QPS falling , And the client timeout will increase , Network bandwidth will rise . Configuring these alarms allows us to find large key The existence of .
- bigkeys command
Use bigkeys The command parses... In a traversal manner Redis All in the instance key, And return the overall statistical information and the number one in each data type key. - redis-rdb-tools
Use redis-rdb-tools Offline analysis tools to scan RDB Persistent files , Although the real-time performance is slightly poor , But being completely offline has no impact on performance .
redis-rdb-tools Yes, it is Python Compiling Redis rdb Snapshot file analysis tool , It can be rdb Snapshot file generation JSON file , Or generate reports for analysis Redis Details of the use of . - Integrated visualization tools
Based on some public cloud or internal structure of the company ,Redis There are usually visual pages and analysis tools , To help locate large key, Of course, the bottom layer of the page may also be based on bigkey s perhaps rdb The results of offline analysis of files .
- How to solve the problem of big key problem
According to the big key The practical use of can be divided into two cases : Can and cannot be deleted .
5.1 Delete big key
If you find something big key Not hot key, Can be in DB Query in the use of , Can be in Redis Delete :
When Redis The version is greater than 4.0 when , You can use UNLINK The command safely deletes large files key, This command can be used in a non blocking manner , Gradually clean up incoming key.
Redis UNLINK Command similar DEL command , Means to delete the specified key. If specified key non-existent , The command ignores this .UNLINK Orders are different from DEL The command lies in , It is executed asynchronously , So it doesn't block .UNLINK The command is non blocking delete , Nonblocking deletion, in short , Is to put the deletion operation into another thread to process .
When Redis Version less than 4.0 when , Avoid blocking commands KEYS. It's a proposal to pass SCAN Command to perform an incremental iterative scan key, Then judge to delete .
Redis Scan The command iterates over the database keys in the database .SCAN Command is a cursor based iterator , After each call , Will return a new cursor to the user , The user needs to use this new cursor as the SCAN Cursor parameters for the command , To continue the previous iteration process .
- Compress and split key
When vaule yes string when , It's hard to split . Serialization can be used 、 The compression algorithm will key The size of is controlled within a reasonable range , But both serialization and deserialization are more time consuming ;
When value yes string, And it is still large after compression key, It needs to be split . A big key Divided into different parts , Record the of each section key, Use multiget And other operations to achieve transaction reading ;
When value yes list/set Is equal to the collection type , Slice according to the estimated data scale . Different elements are divided into different pieces after calculation .
边栏推荐
- The required reading for candidates | PMP the test on June 25 is approaching. What should we pay attention to?
- Half optimized SQL
- Mask image modeling for self supervised representation pre training: CAE and its relationship with Mae and Beit
- Rapideye, spot satellite remote sensing image data
- How much do you know about the cause of amplifier distortion?
- Implementation of depth traversal adjacency table in Figure 6-7
- RapidEye快鸟、SPOT卫星遥感影像数据
- Icml2022 | using virtual nodes to promote graph structure learning
- [ROS introduction] cmakelist Txt and packages XML interpretation
- sitl_ gazebo/include/gazebo_ opticalflow_ plugin. h:43:18: error: ‘TRUE’ was not declared in this scope
猜你喜欢
![Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]](/img/88/3a07589bf8edab618139b1bf1680e8.png)
Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]

Query es page subscript exceeds 10000

leetcode. 11 --- container with the most water

Technology cloud report: East to West computing is not only about "computing", but also needs "new storage"

The mental process and understanding of visual project code design

June 25 PMI certification examination site epidemic prevention requirements and examination room arrangement

自助图书馆系统-Tkinter界面和openpyxl表格综合设计案例
![[geometric vision] 4.2 piecewise linear transformation](/img/1e/a810f4d7e9a6a34647b5cb56fdde67.png)
[geometric vision] 4.2 piecewise linear transformation

British teddy bear joins the pubg mobile game

Why do you perform performance tests before the software goes online? How to find a software performance testing organization
随机推荐
June25,2022 PMP Exam clearance manual-6
Delphi SOAP WebService 服务器端多个 SoapDataModule 要注意的问题
7-9 super Mary
[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design
MySQL multi table operation exercise
MySQL functions
liunx 安装mysql
MySQL multi table operation
SPA项目开发之CRUD+表单验证
Which is the higher priority of V-IF or V-for?
leetcode. 11 --- container with the most water
VS代码一键整理快捷键
CSV add a new column
Las point cloud data thinning in ArcGIS
[interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV
v-if和v-for哪个优先级更高?
Lua -- iterator, module, meta table
Makefile:1860: recipe for target ‘cmake_ check_ build_ system‘ failed make: *** [cmake_check_build_syst
R language builds a binary classification model based on H2O package: using H2O GLM constructs regularized logistic regression model and uses H2O AUC value of AUC calculation model
Shell (34): time