Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View arriqaaq's full-sized avatar
🎯
Focusing

Farhan arriqaaq

🎯
Focusing
View GitHub Profile
/*
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),
@arriqaaq
arriqaaq / chord-3.go
Last active September 12, 2018 10:44
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
}
@arriqaaq
arriqaaq / insert.go
Last active September 28, 2018 15:11
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
}
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) {
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
}
@arriqaaq
arriqaaq / perf
Last active September 28, 2018 15:38
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:
@arriqaaq
arriqaaq / perf-time
Last active September 28, 2018 20:39
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
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)
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)
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())