Skip to content

Optimize indexMaxBlobs for lower memory usage#2631

Closed
MichaelEischer wants to merge 1 commit intorestic:masterfrom
MichaelEischer:opt-max-blobs
Closed

Optimize indexMaxBlobs for lower memory usage#2631
MichaelEischer wants to merge 1 commit intorestic:masterfrom
MichaelEischer:opt-max-blobs

Conversation

@MichaelEischer
Copy link
Copy Markdown
Member

What is the purpose of this change? What does it change?

Reduce the memory required to load preliminary index files. If an preliminary index is uploaded during backup and it is considered as full because its blob count reached indexMaxBlobs, then the hashmap used to loaded this index wastes a lot of memory:

Go hashmaps use a load factor of 6.5/8 and allocate an array whose size is a power of two. For 2000 entries this requires a array with 4096 slots which wastes a lot of memory. The maximum number of entries for that array size would be 3328. However, leave some headroom as the index_uploader only runs every 30 seconds.

I'm not sure whether a changelog entry is required. The memory usage of restic should be slightly lower when running backups without calling rebuild-index inbetween, but it's hard to tell by how much.

Was the change discussed in an issue or in the forum before?

No. I noticed the problem during the discussions in #2523.

Checklist

  • I have read the Contribution Guidelines
  • I have enabled maintainer edits for this PR
  • [ ] I have added tests for all changes in this PR
  • [ ] I have added documentation for the changes (in the manual)
  • There's a new file in changelog/unreleased/ that describes the changes for our users (template here)
  • I have run gofmt on the code in all commits
  • All commit messages are formatted in the same style as the other commits in the repo
  • I'm done, this Pull Request is ready for review

Each index file is currently loaded into a separate hashmap. Go hashmaps
use a load factor of 6.5/8 and allocate an array whose size is a power
of two. For 2000 entries this requires a array with 4096 slots which
wastes a lot of memory. The maximum number of entries for that array
size would be 3328. However, leave some headroom as the index_uploader
only runs every 30 seconds.
@MichaelEischer
Copy link
Copy Markdown
Member Author

Obsoleted by #2749.

@MichaelEischer MichaelEischer deleted the opt-max-blobs branch June 10, 2020 18:40
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.

1 participant