-
Notifications
You must be signed in to change notification settings - Fork 2k
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
LFU Cache Fixes #7479
Merged
Merged
LFU Cache Fixes #7479
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a2e6f52
bloom: fix constructor
vmg 8c3580a
query_engine: Implement contention benchmark
vmg a21d244
query_engine: add a throughput benchmark
vmg e04aa3f
cache: enable LFU by default
vmg cf525df
dev: ensure dev.env is posix compatible
vmg 2cd3611
cache: make endtoend tests more resilient
vmg a5b9f1b
endtoend: delay execution
vmg b197d61
query_engine: typo
vmg e1d8a81
endtoend: uncomment test
vmg File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,6 @@ | |
package bloom | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"log" | ||
"math" | ||
"unsafe" | ||
) | ||
|
@@ -43,26 +40,16 @@ func getSize(ui64 uint64) (size uint64, exponent uint64) { | |
return size, exponent | ||
} | ||
|
||
func calcSizeByWrongPositives(numEntries, wrongs float64) (uint64, uint64) { | ||
size := -1 * numEntries * math.Log(wrongs) / math.Pow(float64(0.69314718056), 2) | ||
locs := math.Ceil(float64(0.69314718056) * size / numEntries) | ||
return uint64(size), uint64(locs) | ||
// NewBloomFilterWithErrorRate returns a new bloomfilter with optimal size for the given | ||
// error rate | ||
func NewBloomFilterWithErrorRate(numEntries uint64, wrongs float64) *Bloom { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
size := -1 * float64(numEntries) * math.Log(wrongs) / math.Pow(0.69314718056, 2) | ||
locs := math.Ceil(0.69314718056 * size / float64(numEntries)) | ||
return NewBloomFilter(uint64(size), uint64(locs)) | ||
} | ||
|
||
// NewBloomFilter returns a new bloomfilter. | ||
func NewBloomFilter(params ...float64) (bloomfilter *Bloom) { | ||
var entries, locs uint64 | ||
if len(params) == 2 { | ||
if params[1] < 1 { | ||
entries, locs = calcSizeByWrongPositives(params[0], params[1]) | ||
} else { | ||
entries, locs = uint64(params[0]), uint64(params[1]) | ||
} | ||
} else { | ||
log.Fatal("usage: New(float64(number_of_entries), float64(number_of_hashlocations))" + | ||
" i.e. New(float64(1000), float64(3)) or New(float64(number_of_entries)," + | ||
" float64(number_of_hashlocations)) i.e. New(float64(1000), float64(0.03))") | ||
} | ||
func NewBloomFilter(entries, locs uint64) (bloomfilter *Bloom) { | ||
size, exponent := getSize(entries) | ||
bloomfilter = &Bloom{ | ||
sizeExp: exponent, | ||
|
@@ -162,49 +149,3 @@ func (bl *Bloom) IsSet(idx uint64) bool { | |
r := ((*(*uint8)(ptr)) >> (idx % 8)) & 1 | ||
return r == 1 | ||
} | ||
|
||
// bloomJSONImExport | ||
// Im/Export structure used by JSONMarshal / JSONUnmarshal | ||
type bloomJSONImExport struct { | ||
FilterSet []byte | ||
SetLocs uint64 | ||
} | ||
|
||
// NewWithBoolset takes a []byte slice and number of locs per entry, | ||
// returns the bloomfilter with a bitset populated according to the input []byte. | ||
func newWithBoolset(bs *[]byte, locs uint64) *Bloom { | ||
bloomfilter := NewBloomFilter(float64(len(*bs)<<3), float64(locs)) | ||
for i, b := range *bs { | ||
*(*uint8)(unsafe.Pointer(uintptr(unsafe.Pointer(&bloomfilter.bitset[0])) + uintptr(i))) = b | ||
} | ||
return bloomfilter | ||
} | ||
|
||
// JSONUnmarshal takes JSON-Object (type bloomJSONImExport) as []bytes | ||
// returns bloom32 / bloom64 object. | ||
func JSONUnmarshal(dbData []byte) (*Bloom, error) { | ||
bloomImEx := bloomJSONImExport{} | ||
if err := json.Unmarshal(dbData, &bloomImEx); err != nil { | ||
return nil, err | ||
} | ||
buf := bytes.NewBuffer(bloomImEx.FilterSet) | ||
bs := buf.Bytes() | ||
bf := newWithBoolset(&bs, bloomImEx.SetLocs) | ||
return bf, nil | ||
} | ||
|
||
// JSONMarshal returns JSON-object (type bloomJSONImExport) as []byte. | ||
func (bl Bloom) JSONMarshal() []byte { | ||
bloomImEx := bloomJSONImExport{} | ||
bloomImEx.SetLocs = bl.setLocs | ||
bloomImEx.FilterSet = make([]byte, len(bl.bitset)<<3) | ||
for i := range bloomImEx.FilterSet { | ||
bloomImEx.FilterSet[i] = *(*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&bl.bitset[0])) + | ||
uintptr(i))) | ||
} | ||
data, err := json.Marshal(bloomImEx) | ||
if err != nil { | ||
log.Fatal("json.Marshal failed: ", err) | ||
} | ||
return data | ||
} |
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
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.
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.
👍