Skip to content

Commit

Permalink
chore: pool size
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Apr 23, 2020
1 parent 9fab1ed commit 2461faf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Cache struct {
func New(setters ...Setter) (*Cache, error) {
c := new(Cache)
c.GCInterval = 120 * time.Second
c.BucketNum = 1024
c.BucketNum = 16

for _, setter := range setters {
if err := setter(c); err != nil {
Expand All @@ -40,7 +40,10 @@ func New(setters ...Setter) (*Cache, error) {
monitor := func(err error) {}

var err error
c.dispatcher, err = curlew.New(curlew.WithMonitor(monitor))
c.dispatcher, err = curlew.New(
curlew.WithMonitor(monitor),
curlew.WithMaxWorkerNum(16),
)
if err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ func TestCache_Set(t *testing.T) {
}
t.Log(c.Get("one"))
}

func BenchmarkBucket_Get(b *testing.B) {
b.ResetTimer()
c, err := New()
if err != nil {
b.Fatalf("new cache failed")
}
for i := 0; i < b.N; i++ {
c.Get("sssssssssssssssssssssssss")
}
}
14 changes: 13 additions & 1 deletion hash_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package roc

import "testing"
import (
"testing"
)

func TestBucket_hashIndex(t *testing.T) {
cache, err := New(WithBucketNum(16))
Expand Down Expand Up @@ -37,5 +39,15 @@ func TestBucket_hashIndex(t *testing.T) {
t.Fatalf("key = %s, want = %d, got = %d", tt.In, tt.Out, idx)
}
}
}

func BenchmarkBucket_hashIndex(b *testing.B) {
b.ResetTimer()
cache, err := New(WithBucketNum(16))
if err != nil {
b.Fatalf("cache err = %+v", err)
}
for i := 0; i < b.N; i++ {
cache.hashIndex("nfjndjfndsjfnjdnjfndjscds")
}
}

0 comments on commit 2461faf

Please sign in to comment.