Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache the entire bolt backend into memory before restoring index #3786

Closed
xiang90 opened this issue Oct 31, 2015 · 5 comments
Closed

cache the entire bolt backend into memory before restoring index #3786

xiang90 opened this issue Oct 31, 2015 · 5 comments
Assignees
Milestone

Comments

@xiang90
Copy link
Contributor

xiang90 commented Oct 31, 2015

etcd has an in-mem secondary index for the entire db. Reading the entire boltdb without moving the db file into page cache is slow. It is OK for etcd to scan the entire file first and let os move all file into page cache. It increase the throughput of read from 6K/second to 2M/second with very little overhead (pre read ingthe whole db has a throughput around 300MB/second on SSD)

@benbjohnson Do you have any suggestion? If boltdb just supports warm-up, it would be great. But I still wonder why doing a seq read on a seq written db without warm-up is so slow.

@benbjohnson
Copy link
Contributor

@xiang90 Even though the keys are written sequentially, bolt may write them randomly since it reuses old pages when available. One easy fix, if you're targeting Linux 2.6.23+, is to add an DB.MmapFlags parameter that would allow you to set MAP_POPULATE which should do the readahead. Would that work?

@xiang90
Copy link
Contributor Author

xiang90 commented Oct 31, 2015

@benbjohnson

Even though the keys are written sequentially, bolt may write them randomly since

Actually, this is a newly created db with all seq writes.

One easy fix, if you're targeting Linux 2.6.23+, is to add an DB.MmapFlags parameter that would allow you to set MAP_POPULATE which should do the readahead. Would that work?

I will give it a try.

@xiang90
Copy link
Contributor Author

xiang90 commented Oct 31, 2015

@benbjohnson

Thanks btw. I will let you know the result soon!

@benbjohnson
Copy link
Contributor

@xiang90

this is a newly created db with all seq writes

Even with sequential writes, bolt will still have pages it will reuse because of the freelist being written and partially filled data pages. Those will get filled on the next transaction and the old half filled page will be available for reuse.

I will give it a try.

You'll need to add the MmapFlags as a field on bolt.Options since it's needed during bolt.Open(). Then copy that over to a DB.MmapFlags so it can be OR'd on each mmap() call. Let me know if you need any help with it.

https://github.com/boltdb/bolt/blob/master/db.go#L662-L675

@xiang90
Copy link
Contributor Author

xiang90 commented Nov 16, 2015

Fixed by #3865

@xiang90 xiang90 closed this as completed Nov 16, 2015
passiondev2024 added a commit to passiondev2024/bbolt that referenced this issue Mar 20, 2024
This adds MmapFlags to DB.Options in case we need syscall.MAP_POPULATE
flag in Linux 2.6.23+ to do the sequential read-ahead, as discussed in [1].

---

[1]: etcd-io/etcd#3786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants