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

fix(store): limit dbPageSize #1018

Merged
merged 4 commits into from
Jun 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion waku/v2/node/storage/message/waku_message_store.nim
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,13 @@ method getAll*(db: WakuMessageStore, onData: message_store.DataProc): MessageSto
ok gotMessages

proc adjustDbPageSize(dbPageSize: uint64, matchCount: uint64, returnPageSize: uint64): uint64 {.inline.} =
var ret = if matchCount < 2: dbPageSize * returnPageSize
const maxDbPageSize: uint64 = 20000 # the maximum DB page size is limited to prevent excessive use of memory in case of very sparse or non-matching filters. TODO: dynamic, adjust to available memory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put this constant outside of the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it there because it is part of the heuristic of finding the "optimal" page size. In the future, this could change.
Did not want to clutter the outer scope with it. wdyt? No strong opinion here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then LGTM ✅😁

if dbPageSize >= maxDbPageSize:
return maxDbPageSize
var ret =
if matchCount < 2: dbPageSize * returnPageSize
else: dbPageSize * (returnPageSize div matchCount)
ret = min(ret, maxDbPageSize)
trace "dbPageSize adjusted to: ", ret
ret

Expand Down