Skip to content

repo.stat reads entire of blockstore into memory #180

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

Closed
alanshaw opened this issue Oct 25, 2018 · 2 comments
Closed

repo.stat reads entire of blockstore into memory #180

alanshaw opened this issue Oct 25, 2018 · 2 comments
Labels
exp/wizard Extensive knowledge (implications, ramifications) required help wanted Seeking public contribution on this issue P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked

Comments

@alanshaw
Copy link
Member

In IPFS repo.stat takes about 5s per call for me. I found that that the entire blockstore is read into memory every time this function is called to get the count and size:

js-ipfs-repo/src/index.js

Lines 301 to 317 in 3611043

blocks: (cb) => this.blocks.query({}, (err, list) => {
list = list || []
const count = new Big(list.length)
let size = new Big(0)
list.forEach(block => {
size = size
.plus(block.value.byteLength)
.plus(block.key._buf.byteLength)
})
cb(err, {
count: count,
size: size
})
}),

This needs to be streamed and/or calculated once, cached, and kept up to date.

@jacobheun
Copy link
Contributor

Getting that stats definitely needs to return a snapshot of the blockstore (even if it still processing). Running through the whole blockstore on each stats request is bad times.

We should probably also add some indicator that the stats are still processing while the blockstore is being read. Ideally we'd also persist this so that nodes with large blockstores that are restarted don't have to read through the entire thing if there is already a stats object in store.

@jacobheun jacobheun added exp/expert Having worked on the specific codebase is important status/deferred Conscious decision to pause or backlog P2 Medium: Good to have, but can wait until someone steps up labels Oct 25, 2018
@daviddias daviddias added status/ready Ready to be worked help wanted Seeking public contribution on this issue exp/wizard Extensive knowledge (implications, ramifications) required and removed status/deferred Conscious decision to pause or backlog exp/expert Having worked on the specific codebase is important labels Dec 9, 2018
@achingbrain
Copy link
Member

This was fixed by #199 Phew!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp/wizard Extensive knowledge (implications, ramifications) required help wanted Seeking public contribution on this issue P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked
Projects
None yet
Development

No branches or pull requests

4 participants