Skip to content

Commit

Permalink
update gigacache (#29)
Browse files Browse the repository at this point in the history
* update gigacache

* go mod tidy

* wrap file locker

* add zset test cases
  • Loading branch information
xgzlucario committed Jan 2, 2024
1 parent 2993844 commit f9240b4
Show file tree
Hide file tree
Showing 24 changed files with 597 additions and 765 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ pprof:
heap:
go tool pprof http://localhost:6060/debug/pprof/heap

gen-proto:
rm -rf proto && protoc --go_out=. --go_opt=Mrotom.proto=proto/ rotom.proto

run-bench:
rm -rf *.db benchmark/*.db
go run benchmark/*.go
Expand Down
80 changes: 40 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,79 +84,79 @@ cpu: 13th Gen Intel(R) Core(TM) i5-13600KF
========== Set ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes
cost: 337.164876ms
50th: 242 ns
90th: 307 ns
99th: 905 ns
cost: 291.413216ms
50th: 214 ns
90th: 262 ns
99th: 509 ns
db file size: 838.5KB

========== Set 8 parallel ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes
cost: 192.458463ms
50th: 358 ns
90th: 1373 ns
99th: 29922 ns
db file size: 4.1MB
cost: 188.082777ms
50th: 352 ns
90th: 857 ns
99th: 22406 ns
db file size: 4.0MB

========== SetEx ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes, ttl 1min
cost: 349.705129ms
50th: 246 ns
90th: 310 ns
99th: 935 ns
db file size: 1.9MB
cost: 302.246712ms
50th: 225 ns
90th: 272 ns
99th: 556 ns
db file size: 790.9KB

========== Get ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes
cost: 295.173803ms
50th: 237 ns
90th: 321 ns
99th: 593 ns
cost: 260.6399ms
50th: 224 ns
90th: 280 ns
99th: 533 ns

========== Get 8 parallel ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes
cost: 43.818633ms
50th: 272 ns
90th: 423 ns
99th: 659 ns
cost: 48.348878ms
50th: 248 ns
90th: 393 ns
99th: 638 ns

========== LRPush ==========
size: 100*10000 enties
desc: value 10 bytes
cost: 226.683466ms
50th: 191 ns
90th: 210 ns
99th: 395 ns
db file size: 277.9KB
cost: 228.933463ms
50th: 192 ns
90th: 211 ns
99th: 321 ns
db file size: 260.0KB

========== HSet ==========
size: 100*10000 enties
desc: field 10 bytes, value 10 bytes
cost: 386.041763ms
50th: 215 ns
90th: 282 ns
99th: 493 ns
cost: 398.351779ms
50th: 224 ns
90th: 278 ns
99th: 443 ns
db file size: 835.2KB

========== HGet ==========
size: 100*10000 enties
desc: field 10 bytes, value 10 bytes
cost: 277.690778ms
50th: 220 ns
90th: 304 ns
99th: 572 ns
cost: 254.612279ms
50th: 211 ns
90th: 262 ns
99th: 534 ns

========== BitSet ==========
size: 100*10000 enties
desc: offset uint32
cost: 117.428111ms
50th: 97 ns
90th: 101 ns
99th: 121 ns
db file size: 907.3KB
cost: 141.778962ms
50th: 108 ns
90th: 115 ns
99th: 137 ns
db file size: 898.2KB
```

80 changes: 40 additions & 40 deletions README_ZN.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,79 +86,79 @@ cpu: 13th Gen Intel(R) Core(TM) i5-13600KF
========== Set ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes
cost: 337.164876ms
50th: 242 ns
90th: 307 ns
99th: 905 ns
cost: 291.413216ms
50th: 214 ns
90th: 262 ns
99th: 509 ns
db file size: 838.5KB

========== Set 8 parallel ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes
cost: 192.458463ms
50th: 358 ns
90th: 1373 ns
99th: 29922 ns
db file size: 4.1MB
cost: 188.082777ms
50th: 352 ns
90th: 857 ns
99th: 22406 ns
db file size: 4.0MB

========== SetEx ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes, ttl 1min
cost: 349.705129ms
50th: 246 ns
90th: 310 ns
99th: 935 ns
db file size: 1.9MB
cost: 302.246712ms
50th: 225 ns
90th: 272 ns
99th: 556 ns
db file size: 790.9KB

========== Get ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes
cost: 295.173803ms
50th: 237 ns
90th: 321 ns
99th: 593 ns
cost: 260.6399ms
50th: 224 ns
90th: 280 ns
99th: 533 ns

========== Get 8 parallel ==========
size: 100*10000 enties
desc: key 10 bytes, value 10 bytes
cost: 43.818633ms
50th: 272 ns
90th: 423 ns
99th: 659 ns
cost: 48.348878ms
50th: 248 ns
90th: 393 ns
99th: 638 ns

========== LRPush ==========
size: 100*10000 enties
desc: value 10 bytes
cost: 226.683466ms
50th: 191 ns
90th: 210 ns
99th: 395 ns
db file size: 277.9KB
cost: 228.933463ms
50th: 192 ns
90th: 211 ns
99th: 321 ns
db file size: 260.0KB

========== HSet ==========
size: 100*10000 enties
desc: field 10 bytes, value 10 bytes
cost: 386.041763ms
50th: 215 ns
90th: 282 ns
99th: 493 ns
cost: 398.351779ms
50th: 224 ns
90th: 278 ns
99th: 443 ns
db file size: 835.2KB

========== HGet ==========
size: 100*10000 enties
desc: field 10 bytes, value 10 bytes
cost: 277.690778ms
50th: 220 ns
90th: 304 ns
99th: 572 ns
cost: 254.612279ms
50th: 211 ns
90th: 262 ns
99th: 534 ns

========== BitSet ==========
size: 100*10000 enties
desc: offset uint32
cost: 117.428111ms
50th: 97 ns
90th: 101 ns
99th: 121 ns
db file size: 907.3KB
cost: 141.778962ms
50th: 108 ns
90th: 115 ns
99th: 137 ns
db file size: 898.2KB
```

2 changes: 1 addition & 1 deletion benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func benchBitSet() {
for i := 0; i < 100*10000; i++ {
t1 := time.Now()

db.BitSet("bm", uint32(i), true)
db.BitSet("bm", true, uint32(i))

if i%10 == 0 {
td.Add(float64(time.Since(t1)), 1)
Expand Down
36 changes: 0 additions & 36 deletions codeman/bench_test.go

This file was deleted.

26 changes: 10 additions & 16 deletions codeman/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ import (
"fmt"
"math"
"reflect"
"sync"

"github.com/xgzlucario/rotom/base"
cache "github.com/xgzlucario/GigaCache"
)

const (
_true = 1
_false = 0
)

var codecPool = sync.Pool{
New: func() any { return &Codec{b: make([]byte, 0, 16)} },
}
var codecPool = cache.NewBufferPool()

// Codec is the primary type for encoding data into a specific format.
type Codec struct {
Expand All @@ -26,12 +23,11 @@ type Codec struct {

// NewCodec
func NewCodec() *Codec {
return codecPool.Get().(*Codec)
return &Codec{b: codecPool.Get(16)[:0]}
}

func (s *Codec) Recycle() {
s.b = s.b[:0]
codecPool.Put(s)
codecPool.Put(s.b)
}

func (s *Codec) Content() []byte {
Expand Down Expand Up @@ -97,6 +93,7 @@ func (s *Codec) formatString(v string) *Codec {
return s
}

// Any encodes any type of data.
func (s *Codec) Any(v any) (*Codec, error) {
buf, err := s.encode(v)
if err != nil {
Expand All @@ -108,19 +105,16 @@ func (s *Codec) Any(v any) (*Codec, error) {

func (s *Codec) encode(v any) ([]byte, error) {
switch v := v.(type) {
case base.Binarier:
case Binarier:
return v.MarshalBinary()
case base.Jsoner:
case Jsoner:
return v.MarshalJSON()
default:
return nil, fmt.Errorf("%w: %v", base.ErrUnSupportDataType, reflect.TypeOf(v))
return nil, fmt.Errorf("%w: %v", ErrUnSupportDataType, reflect.TypeOf(v))
}
}

func formatVarint[T base.Integer](buf []byte, n T) []byte {
if buf == nil {
buf = make([]byte, 0, binary.MaxVarintLen64)
}
func formatVarint[T Integer](buf []byte, n T) []byte {
return binary.AppendUvarint(buf, uint64(n))
}

Expand All @@ -134,7 +128,7 @@ func formatStrSlice(s []string) []byte {
return data
}

func formatNumberSlice[T base.Integer](s []T) []byte {
func formatNumberSlice[T Integer](s []T) []byte {
data := make([]byte, 0, len(s)+1)
data = binary.AppendUvarint(data, uint64(len(s)))
for _, v := range s {
Expand Down
Loading

0 comments on commit f9240b4

Please sign in to comment.