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

fix(store): limit dbPageSize #1018

merged 4 commits into from
Jun 23, 2022

Conversation

kaiserd
Copy link
Contributor

@kaiserd kaiserd commented Jun 23, 2022

This PR limits dbPageSize avoiding excessive use of memory in case of sparse or non-matching filters.
This PR partly solves #1017

@kaiserd kaiserd requested review from LNSD and jm-clius June 23, 2022 11:10
@kaiserd kaiserd marked this pull request as ready for review June 23, 2022 11:10
Copy link
Contributor

@LNSD LNSD left a comment

Choose a reason for hiding this comment

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

Sorry if my comments sound a little nitpicked 🙏🏼

@@ -267,8 +267,12 @@ 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 ✅😁

waku/v2/node/storage/message/waku_message_store.nim Outdated Show resolved Hide resolved
waku/v2/node/storage/message/waku_message_store.nim Outdated Show resolved Hide resolved
@kaiserd kaiserd requested a review from LNSD June 23, 2022 13:01
Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

LGTM. No strong opinion about where the const resides, but since it is a workaround "stand-in" for a heuristic I'm fine with it hiding in scope.

Copy link
Contributor

@LNSD LNSD left a comment

Choose a reason for hiding this comment

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

LGTM ✅

@kaiserd
Copy link
Contributor Author

kaiserd commented Jun 23, 2022

Just as info: Most likely, the dbPageSize will be replaced by putting the filtering into the WHERE clause in the future.

@kaiserd kaiserd merged commit a2749c4 into master Jun 23, 2022
@kaiserd kaiserd deleted the fix/store-db-page-limit branch June 23, 2022 15:05
jakubgs pushed a commit to status-im/infra-nim-waku that referenced this pull request Jun 23, 2022
There is a known issue in `v0.10` where certain store queries
can slow down nodes: waku-org/nwaku#1017

A possible (partial?) fix has been merged and deployed to `wakuv2.test`:
waku-org/nwaku#1018
But the SQLite store can be disable on `prod` in the meantime.

Signed-off-by: Jakub Sokołowski <[email protected]>
jakubgs added a commit to status-im/infra-nim-waku that referenced this pull request Oct 19, 2022
Otherwise nodes try to load all messages into memory at startup.

And the issue that originally caused this to be disabled is closed:
waku-org/nwaku#1017
waku-org/nwaku#1018

Signed-off-by: Jakub Sokołowski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants