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

Use memory footprint of sugardb.store to compare against max memory for eviction policies #133

Merged
merged 9 commits into from
Oct 4, 2024

Conversation

osteensco
Copy link
Contributor

Addresses #121

  • Added memUsed field to SugarDB struct.
  • Added GetMem() method to KeyData struct.
  • Added GetMem() methods to Set and SortedSet structs.
  • Added CompositeType interface to constants. CompositeType are types that implement the GetMem() method.
  • Added MemoryUsed and MaxMemory fields to ServerInfo struct.

So I spent a good amount of time trying to understand the nuances with various data types in go and the amount of memory they take up. I think I've come up with a strong enough solution but I'm not sure any implementation would be perfect due to some limitations within go.

Some of the more primitive data types like int64 are straight forward in the amount of bytes occupied in memory, others not so much. Slices and strings have headers, structs will include padding between their various fields, and maps have a header consisting of a pointer, but also have several other components under the hood. I couldn't find an up to date method for accurately accounting for these other components since they have apparently changed over the years. So maps will be underreported, but my understanding is that the difference would be trivial for our use case anyway.

Open to feedback and happy to make adjustments or go a different direction on the implementation if needed.

Copy link
Collaborator

@kelvinmwinuka kelvinmwinuka left a comment

Choose a reason for hiding this comment

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

Thanks for the work @osteensco. This solution looks good to me. I think due to some limitations in Go, we are limited in how accurately we can report mem usage anyways. We can always revisit this if we run into an issue in the future.

For now, I will approve and merge this.

@kelvinmwinuka kelvinmwinuka merged commit ff96d45 into EchoVault:main Oct 4, 2024
2 checks passed
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.

2 participants