-
Notifications
You must be signed in to change notification settings - Fork 193
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
Size aware cache #924
Merged
cody-littley
merged 52 commits into
Layr-Labs:master
from
cody-littley:size-aware-cache
Nov 27, 2024
Merged
Size aware cache #924
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
02e9069
Added rate limiting.
cody-littley dc39c21
Properly handle blob sizes.
cody-littley d99fd39
Incremental progress.
cody-littley e39eaf9
Incremental progress.
cody-littley 876ec69
Merge branch 'master' into relay-rate-limits2
cody-littley 9500f4f
unit tests
cody-littley ffe18c6
Unit tests.
cody-littley 79d9614
Fix tests.
cody-littley c1d83e6
Cleanup.
cody-littley ed4daca
Added get chunks request hashing.
cody-littley 3438b92
Start work on authenticator.
cody-littley b5dc37c
Fix test issue.
cody-littley b420cca
Cleanup
cody-littley 517b78e
Merge branch 'master' into relay-rate-limits2
cody-littley 7982aec
Convert config to flag pattern.
cody-littley 366fdf7
Simplify rate limiter classes.
cody-littley f2c10e4
Made suggested changes.
cody-littley 0f95ce4
Merge branch 'relay-rate-limits2' into relay-authentication
cody-littley c2bb9c3
Shorten package name.
cody-littley 151305b
Started testing
cody-littley 29fd940
Finished unit tests.
cody-littley 3993af4
Nil authenticator test.
cody-littley d094b80
Test with authentication saving disabled.
cody-littley d8691e1
Tie together config.
cody-littley 8b9512b
Add method for convenient signing.
cody-littley fb7ec51
Made requested changes.
cody-littley 6325f0c
Merge branch 'master' into relay-authentication
cody-littley 5f853e0
Revert unintentional changes.
cody-littley f22544c
Fix bug.
cody-littley 7a26c27
Made requested changes.
cody-littley d21e0bc
Update proto documentation.
cody-littley 98a8469
Add key caching.
cody-littley 5948e73
lint
cody-littley 2f2209c
Added sane timeouts for relay.
cody-littley 4204ea0
Added moar timeouts.
cody-littley 0892c9c
Add flags.
cody-littley e6f4e8e
Unit tests.
cody-littley 7f95615
Added base framework.
cody-littley e11bcf6
Add unit test for queue.
cody-littley 0948a5c
Unit tests.
cody-littley a23b905
Merge branch 'master' into relay-timeouts
cody-littley 3f06fff
fix bugs
cody-littley 43d8c91
lint
cody-littley 57ea072
Merge branch 'relay-timeouts' into size-aware-cache
cody-littley 0903529
Rename cached accessor to cache accessor.
cody-littley 04480ff
Integrate new cache.
cody-littley 1db3a74
Merge branch 'master' into size-aware-cache
cody-littley 9100eac
Use queue for authenticator because it's a lot clener.
cody-littley 71a5aaa
Cleanup.
cody-littley f8327df
Use gods library for data structures.
cody-littley e925517
Made suggested changes.
cody-littley a9d3329
Cleanup
cody-littley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cache | ||
|
||
// WeightCalculator is a function that calculates the weight of a key-value pair in a Cache. | ||
// By default, the weight of a key-value pair is 1. Cache capacity is always specified in terms of | ||
// the weight of the key-value pairs it can hold, rather than the number of key-value pairs. | ||
type WeightCalculator[K comparable, V any] func(key K, value V) uint64 | ||
|
||
// Cache is an interface for a generic cache. | ||
// | ||
// Unless otherwise noted, Cache implementations are not required to be thread safe. | ||
type Cache[K comparable, V any] interface { | ||
// Get returns the value associated with the key, and a boolean indicating whether the key was found in the cache. | ||
Get(key K) (V, bool) | ||
|
||
// Put adds a key-value pair to the cache. After this operation, values may be dropped if the total weight | ||
// exceeds the configured maximum weight. Will ignore the new value if it exceeds the maximum weight | ||
// of the cache in and of itself. | ||
Put(key K, value V) | ||
|
||
// Size returns the number of key-value pairs in the cache. | ||
Size() int | ||
|
||
// Weight returns the total weight of the key-value pairs in the cache. | ||
Weight() uint64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this generality or just give the cache a total memory limit will work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generalization is needed to support the current use case. There isn't a trivial and cheap way we can determine the size of an arbitrary data structure, so we need the ability to compute the size for different data types. For things like blobs that are just an array of bytes, it's easy. For things like the chunks that are in a complex data structure, we need an abstraction like this.