why does redis use fork to create child process other than create a thread to rewrite aof or rdb? fork usually takes more time than just create a thread right ? . it would help me a lot if you guys help explain it . thank you .
Comment From: zhihao1996
is it because thread would use main process's memory space ?
Comment From: oranagra
Redis relies on the OS CopyOnWrite to guarantee that the generated snapshot is point in time consistent, and does not contain any database changes that were done after the dumping process started.
Comment From: zhihao1996
Redis relies on the OS CopyOnWrite to guarantee that the generated snapshot is point in time consistent, and does not contain any database changes that were done after the dumping process started.
@oranagra i understand that , but it still need to generate page table etc right? it would be more lightweight to use thread right? it is because thread would consume main process's memory that redis has to choose to fork another process to decrease main process's memory usage ?
Comment From: oranagra
@zhihao1996 if you do it in a thread, you'll have to implement COW in user space, which is a lot of work.
doing user space COW per object would mean that even if one byte changed in that object you clone the entire object (possibly very large) rather than just a 4kb page..
anyway, it has some advantages and some disadvantages, and mainly a lot more code.
Comment From: zhihao1996
@oranagra oh i see ,thank you so much and happy new year .
Comment From: xiaofanshifu
@oranagra Hi, I have a question! Are both RDB and AOF completed by a child process from the parent process frok()? How can I remember that AOF uses a bgrewriteaof thread from the main thread fork() of redis to rewrite the log?
Comment From: oranagra
@thissuper yes, they both normally use fork, redis doesn't use threads for these things.
fork is used for persistence (both AOF and RDB), and for replication.
however, there are cases where the main process does a save too, these are:
1. on shutdown
2. the SAVE command
Comment From: xiaofanshifu
@oranagra thanks