11 / 6 notes supplement (redis persistence, RDB & AOF)

Anthony-bird 2020-11-07 21:19:23
notes supplement redis persistence rdb


11/6 Add notes

modify redis-6379.conf Inside save10 second 2 Data changes (save 10 2)

Once the data is modified, the data does not change , modify 2 It's only when the data changes

Continue to modify the data , The discovery is still the same pattern

All additions and deletions should be changed , Besides checking .

save Configuration principle

Return results , To have an impact on the data , The data has changed , Or the variable meets the setting requirements ,rdb Will change .save The configuration should be set according to the real scene , Otherwise, there may be performance problems ,save After configuration, the execution is bgsave operation .

RDB2 Comparison of different starting modes

save Instructions are synchronized in the process of reading and writing , And dare not save It's asynchronous ,save The command blocks the customer service ,bgsave The process of reading and writing is asynchronous , Will create child threads ( It's like starting a new process ), It will not cause customer service congestion , But it will cause extra memory consumption .

rdb Special start command

Restart the server while it is running

debug reload

To shut down the server is to specify the data to be saved

shutdown save( Whether it's open enough , Automatic execution bgsave)

RDB Advantages and disadvantages

advantage :

RDB It's a compact compression Binary system file , representative Redis stay Some point in time Data snapshot on . Ideal for backup , Full scale replication and other scenarios . Like every 2 Hours to perform bgsave Backup , And put RDB Copy files to a remote machine or file system ( Such as hdfs), For disaster recovery .RDB Recover data much faster than AOF The way .

shortcoming :

RDB Mode data can't be done Real time persistence / Second persistence , Maybe the data saved is not very complete . because bgsave Run every time fork Action create subprocess , Meeting Additional consumption performance , Frequent execution cost is too high .RDB Files are saved in a specific binary format ,Redis There are multiple formats in the version update process RDB edition , There is an old version Redis Service data format Not compatible new edition RDB Format The problem of .

AOF

Use AOF Why : in the light of RDB Problems that are not suitable for real-time persistence ,Redis Provides AOF Persistent way to solve .

Concept

AOF(append only file) Persistence : Log the process of data generation ( Command every time you write ), Reexecute on reboot AOF The command in the file restores the data .AOF The main effect It solves the real-time problem of data persistence , So far Redis persistent Main stream The way

AOF Three strategies for writing data (appendfsync)

always( Every time ), Synchronize write operations to AOF In file , Data integrity , Low performance .

everysec( Per second ), Synchronize buffers to... Per second AOF In file , High data accuracy and performance , This command is usually used , Is also the default configuration

no( System control ), The operating system controls each synchronization to AOF in , The whole thing is out of control

Practice :

To configure :appendfilename Configure to appendonly.aof, If it's a multi port number , Recommended configuration is appendonly- Port number .aof

1. Get into conf Directory configuration redis-6379 Of conf file

2. Add the following command , Turn on persistence (appendonly yes|no), Configure write data policy (appendfsync always |everysec|no)

3. Kill the original service process first , Restart with the configuration file

4. Get into data, Check to see if there is one more in the document aof The file of

5. Add data and find that the file is getting bigger

6. In the use of everysec Instructions , Restart the server , Check the file size before modifying the data

7. After writing data , View file size , and cat file .aof journal , It was found that the data log was modified successfully

AOF rewrite

With AOF The files are getting bigger , It needs to be done regularly AOF File rewriting , Achieve the purpose of compression .

It is to convert the execution results of several commands of the same data into the corresponding instructions of the final result data .

Purpose :AOF Rewriting saves file space , Improve data recovery efficiency , Smaller AOF Files can be made faster by Redis load .

AOF Override method : Manual and automatic

Manual :bgrewriteaof( Background rewriting aof)

Automatically : auto-aof-rewrite-min-size size

 `auto-aof-rewrite-percentage` *percentage*

Modify the configuration file

Start the customer service to modify the data

View files and view aof Document data

After the modification , start-up bgrewriteaof The following prompt appears

Again, the file size is significantly smaller

When I look at aof Data processing is garbled , Anyway, the file is compressed .

AOF Manual rewriting :bgrewriteaof How commands work

And bgsave The instructions are similar , The first is to send instructions ( The console will feed back Background append only file rewriting started), call fork Function generation subprocess , rewrite .aof file , Return message .

AOF Automatic override

Automatically override trigger condition settings auto-aof-rewrite-min-size size Automatically rewrite minimum volume , The default is 64MB.

auto-aof-rewrite-percentage percent On behalf of the current AOF File space And after the last rewrite AOF The ratio of file space .

aof_current_size AOF File space aof_base_size After the last rewrite AOF File space

Auto override trigger time

aof_current_size>auto-aof-rewrite-min-size &&(aof_current_size-aof_base_size)/aof_base_size>=auto-aof-rewrite-percentage

Enter... On the customer service side info, You can see Persistence( Persistence ), Something about persistence ,

AOF Rewrite process

RDB And AOF difference

RDB The resulting file has a higher compact compression ratio , It takes up less storage space , So read RDB Faster recovery . Because every time I generate RDB It's expensive , Storage is slow , Data may be lost ,RDB The consumption of resources is heavy , be relative to AOF Start priority is low .

AOF Persistence is achieved by appending write commands to files , adopt appendfsync Parameters can be controlled in real time / Second persistence . Because you need to keep adding commands , therefore AOF The volume of the file is getting larger , You need to perform rewriting operations on a regular basis to reduce the file size . Because of its large size , So it takes up a lot of storage space , And RDB comparison , It's the opposite , It takes up a lot of storage space , Storage speed is very fast , Recovery is slow , Because it's the storage of recorded data , It will be smaller after rewriting ,AOF It's lightweight in terms of resource consumption , Changing policies in different scenarios can improve data security .

RDB And AOF The electors of

Sensitive to the process of data , And if you don't ask for recovery speed , It is recommended to use AOF,

Data integrity is required , It is recommended to use RDB Persistence scheme , It's fast to recover .

If you can tolerate data loss within a few minutes , And pursue recovery speed , choose RDB

If you can't afford to lose data within a few minutes , Very sensitive to business data , choose AOF

Or both , priority of use AOF Restore data , Reduce the amount of data loss .

Persistent application scenarios

It's applied to rush buying , Limited purchase 、 A limited number of coupons will be issued 、 Data storage design of activation code and other services , Applied to data control with sequence of operations , Apply to the latest news display , Service control applied to control blacklist settings , Applied to the ranking of the counter combination sorting function .

版权声明
本文为[Anthony-bird]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云