This file contains hidden or 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
func (n *Node) join(joinNode *internal.Node) error { | |
// First check if node already present in the circle | |
// Join this node to the same chord ring as parent | |
var foo *internal.Node | |
// // Ask if our id already exists on the ring. | |
if joinNode != nil { | |
remoteNode, err := n.findSuccessorRPC(joinNode, n.Id) | |
if err != nil { | |
return err | |
} |
This file contains hidden or 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
/* | |
NewNode creates a new Chord node. Returns error if node already | |
exists in the chord ring | |
*/ | |
func NewNode(cnf *Config, joinNode *internal.Node) (*Node, error) { | |
if err := cnf.Validate(); err != nil { | |
return nil, err | |
} | |
node := &Node{ | |
Node: new(internal.Node), |
This file contains hidden or 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
func (c *CuckooFilter) getCuckooParams(data []byte) (uint, uint, []byte) { | |
hash := c.computeHash(data) | |
f := hash[0:c.fpSize] | |
i1 := uint(binary.BigEndian.Uint32(hash2(hash))) % c.numbuckets | |
i2 := (i1 ^ uint(binary.BigEndian.Uint32(hash1(f)))) % c.numbuckets | |
return i1, i2, f | |
} | |
This file contains hidden or 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
func (c *CuckooFilter) Lookup(data []byte) bool { | |
// f = fingerprint(x); | |
// i1 = hash(x); | |
// i2 = i1 ⊕ hash(f); | |
// if bucket[i1] or bucket[i2] has f then | |
// return True; | |
// return False; | |
i1, i2, f := c.getCuckooParams(data) | |
if c.buckets[i1].contains(f) || c.buckets[i2].contains(f) { |
This file contains hidden or 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
func (c *CuckooFilter) Delete(data []byte) bool { | |
i1, i2, f := c.getCuckooParams(data) | |
if c.buckets[i1].delete(f) || c.buckets[i2].delete(f) { | |
return true | |
} | |
return false | |
} |
This file contains hidden or 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
Bloom: | |
BenchmarkCuckooInsert-4 3000000 433 ns/op | |
Alloc = 207 MiB TotalAlloc = 526 MiB Sys = 240 MiB NumGC = 16 | |
BenchmarkCuckooLookup-4 5000000 371 ns/op | |
Alloc = 336 MiB TotalAlloc = 788 MiB Sys = 429 MiB NumGC = 24 | |
Cuckoo: |
This file contains hidden or 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
Cuckoo filter | |
(Insertion) | |
Alloc = 825 MiB TotalAlloc = 1008 MiB Sys = 880 MiB NumGC = 6 | |
Elements: 5000000 | |
Time taken: 4.329194242s | |
(Search post insertion) | |
Alloc = 681 MiB TotalAlloc = 1580 MiB Sys = 1108 MiB NumGC = 7 | |
Elements: 5000000 |
This file contains hidden or 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
ab -c 4 -n 10000 0.0.0.0:8089/ping | |
Concurrency Level: 4 | |
Time taken for tests: 40.032 seconds | |
Complete requests: 10000 | |
Failed requests: 0 | |
Total transferred: 1200000 bytes | |
HTML transferred: 40000 bytes | |
Requests per second: 249.80 [#/sec] (mean) | |
Time per request: 16.013 [ms] (mean) |
This file contains hidden or 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
ab -c 40 -n 10000 0.0.0.0:8089/ping | |
Concurrency Level: 40 | |
Time taken for tests: 41.060 seconds | |
Complete requests: 10000 | |
Failed requests: 0 | |
Total transferred: 1200000 bytes | |
HTML transferred: 40000 bytes | |
Requests per second: 243.55 [#/sec] (mean) | |
Time per request: 164.240 [ms] (mean) |
This file contains hidden or 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
type service struct { | |
storage db.DB | |
logger log.Logger | |
db *sql.DB | |
cache *zizou.Cache | |
} | |
func (s *service) GetEcpm(data getEcpmRequest) (float64, error) { | |
key := NewKey(data.GetCountryId(), data.GetPartner(), data.GetGameId()) | |
icVal, found := s.cache.Get(key.Id()) |