grandecola / bigqueue

Embedded, Fast and Persistent bigqueue implementation
MIT License
443 stars 32 forks source link

Why mmap? #43

Closed JensRantil closed 5 years ago

JensRantil commented 5 years ago

Just curious, why mmap the files? It seems like simply writing serially and reading serially also should work, no? Would also give higher control over flushing and buffering.

mangalaman93 commented 5 years ago

A couple of reasons -

JensRantil commented 5 years ago

I see. Some quick thoughts:

It avoids the copy of data from page cache (disk page cache that kernel maintains) to application memory. mmap directly maps the files into application virtual memory.

Looks like you can do that with a regular file, also: https://askubuntu.com/a/159012

We plan to build more data structures in future, such as BigArray, and plan to reuse some of the components that we have built for bigqueue. mmap will work better in that case.

👍