Skip to content

ataul443/sweep

Repository files navigation

Sweep

Sweep is an in-memory cache. It uses sharding techinque to store millions of entries inside it. Even with millions of entries inside it the GC pause takes only a few milliseconds.

Note: It is a toy project, not intended to be used in production. I was practicing for an LLD interview and I ended up writing this.

Usage

package main

import (
	"fmt"
	"github.com/ataul443/sweep"
)

func main() {
	cache := sweep.Default()
	defer cache.Close()
	
	err := cache.Put("pikachu", []byte("value of pikachu"))
	if err != nil {
		panic(err)
	}
	
	val, err := cache.Get("pikachu")
	if err != nil {
		panic(err)
	}
	
	fmt.Println(string(val))
}

How GC Pause minimized ?

Starting GC Pause benchmark....
Going to put 20000000 entries in sweep.
Time took in inserting 20000000 entries in sweep: 18.93 seconds
GC Pause took: 85 milliseconds
Total entries in cache: 20000000

Instead of storing (key, val) pair directly in map[string]*entry, Sweep stores the val in a queue and stores the index in a map[uint64]uint64 as an (key, index) pair. Large map containing pointers causes huge GC pause time, however this is not same with map containing integers. You can read up more about this at issue-9477.

Releases

No releases published

Packages

No packages published

Languages