From 6b31f3c97a5d12b29e93182db10fdddd82e198b5 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 6 Oct 2021 00:37:57 -0700 Subject: [PATCH] add benchmark test --- .../redis3/kv_directory_children_test.go | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/weed/filer/redis3/kv_directory_children_test.go b/weed/filer/redis3/kv_directory_children_test.go index 7c086bdfb..1b97d8aaf 100644 --- a/weed/filer/redis3/kv_directory_children_test.go +++ b/weed/filer/redis3/kv_directory_children_test.go @@ -1,9 +1,11 @@ package redis3 import ( + "context" "github.com/chrislusf/seaweedfs/weed/util/skiplist" - goredislib "github.com/go-redis/redis/v8" + "github.com/go-redis/redis/v8" "github.com/stvp/tempredis" + "strconv" "testing" ) @@ -43,7 +45,7 @@ func TestNameList(t *testing.T) { } defer server.Term() - client := goredislib.NewClient(&goredislib.Options{ + client := redis.NewClient(&redis.Options{ Network: "unix", Addr: server.Socket(), }) @@ -55,12 +57,10 @@ func TestNameList(t *testing.T) { nameList.WriteName(name) nameList.ListNames("", func(name string) bool { - println(" * ", name) return true }) if nameList.HasChanges() { - println("has some changes") data = nameList.ToBytes() } println() @@ -72,4 +72,48 @@ func TestNameList(t *testing.T) { return true }) -} \ No newline at end of file +} + +func BenchmarkNameList(b *testing.B) { + + server, err := tempredis.Start(tempredis.Config{}) + if err != nil { + panic(err) + } + defer server.Term() + + client := redis.NewClient(&redis.Options{ + Network: "unix", + Addr: server.Socket(), + }) + + store := newSkipListElementStore("/yyy/bin", client) + var data []byte + for i := 0; i < b.N; i++ { + nameList := skiplist.LoadNameList(data, store, maxNameBatchSizeLimit) + + nameList.WriteName("name"+strconv.Itoa(i)) + + if nameList.HasChanges() { + data = nameList.ToBytes() + } + } +} + +func BenchmarkRedis(b *testing.B) { + + server, err := tempredis.Start(tempredis.Config{}) + if err != nil { + panic(err) + } + defer server.Term() + + client := redis.NewClient(&redis.Options{ + Network: "unix", + Addr: server.Socket(), + }) + + for i := 0; i < b.N; i++ { + client.ZAddNX(context.Background(),"/yyy/bin", &redis.Z{Score: 0, Member: "name"+strconv.Itoa(i)}) + } +}