selectpollepoll select Select first appeared in 4.2BSD in 1983. It monitors an array of multiple file descriptors through a select() system call. When select() returns, the ready file descriptors in the array will be modif... Read Linux Select, Poll and Epoll difference
Redis is a non-relational database based on memory. Although memory is fast, data is more likely to be lost, so Redis provides two persistence methods, namely RDB and AOF. Today, I will introduce these two persistence methods and their principles.
Rdb is a kind of snapshot storage and also the default persistence strategy of Redis. It persists the data in memory to disk without affecting the performance of Redis; it has two persistence methods, one is blocking Persistence (save) The other is non-blocking background persistence (bgSave);
Using the concept of Linux parent-child process, fork a child process when persisting, but it does not copy all the data in the memory of the parent process, but only moves the pointer, and uses the copy-on-write mechanism to actually copy the data only when writing, and the speed Fast; the parent process does not need to do other IO operations so that the RDB persistence method can maximize the performance of Redis.
Note: It needs to be clear that the parent and child processes of linux are isolated from each other. After the save is enabled, the child process only focuses on the file storage operation. At this time, the main process can still receive client requests, but use the copyonwrite mechanism to copy data when there is a write operation.
RDB restores data quickly, and bgsave will not affect the performance provided by Redis, but there will be a greater risk of data loss; it does not support zipper storage, that is, the latest rdb file will overwrite the historical version of the file, the hard disk There is always only one persistent file
A write-based persistence method that can achieve almost real-time configuration through configuration, which will affect the performance of the system correspondingly;
Write each Redis command into the aof file, and has the ability to rewrite: with more and more synchronization operations, the size of the aof file will become larger and larger, and the rewrite mechanism will be triggered at this time; Redis can be used without interruption In the case of serving clients, rebuild the AOF file. Execute the BGREWRITEAOF command, and Redis will generate a new AOF file, this file contains the minimum commands needed to rebuild the current dataset. It should be noted that the rewriting after redis4.0 will write the rdb file into the aof file, and only add the commands after the rdb; this greatly improves the efficiency
You can configure how long Redis will fsync data to disk; Redis provides three methods:
AOF is safer and less likely to lose data, but AOF restores data not as fast as RDB, and AOF theoretically has the possibility that the file will always grow infinitely, even if there is a rewriting and merging RDB mechanism, but when Redis runs long enough There will be problems with too large files
Analysis: When redis is restarted, the main process will inevitably have a large number of write operations, both of which will operate the disk and affect performance; this configuration means whether to use the no brushing mechanism, the above is also over, no this This mechanism is the fastest but least reliable writing method; redis defaults to no, which means that it still does not use the no method when rewriting, and would rather block and wait than lose data; if it is yes, it means the master will rewrite The process uses no to wipe the disk witty;
Note: if the aof file is corrupted in the middle, redis will still exit with an error.
When our software starts, the computer will assign a process to the program we are running, and the process contains multiple threads to improve the speed of the software. In the android network request, we know that in da...
Review LinkedList In terms of data structure, LinkedList not only implements the same List interface as ArrayList, but also implements the Deque interface, and the ArrayDeque we are going to talk about today is a dynamic a...