seaweedfs/weed/filer/redis3/kv_directory_children_test.go

211 lines
4.1 KiB
Go
Raw Normal View History

2021-10-06 15:03:54 +08:00
package redis3
import (
2021-10-06 15:37:57 +08:00
"context"
2021-10-07 09:18:24 +08:00
"fmt"
2021-10-06 15:37:57 +08:00
"github.com/go-redis/redis/v8"
2021-10-06 15:03:54 +08:00
"github.com/stvp/tempredis"
2021-10-06 15:37:57 +08:00
"strconv"
2021-10-06 15:03:54 +08:00
"testing"
2021-10-07 09:18:24 +08:00
"time"
2021-10-06 15:03:54 +08:00
)
var names = []string{
"cassandra.in.sh",
"cassandra",
"debug-cql.bat",
"nodetool",
"nodetool.bat",
"source-conf.ps1",
"sstableloader",
"sstableloader.bat",
"sstablescrub",
"sstablescrub.bat",
"sstableupgrade",
"sstableupgrade.bat",
"sstableutil",
"sstableutil.bat",
"sstableverify",
"sstableverify.bat",
"stop-server",
"stop-server.bat",
"stop-server.ps1",
"cassandra.in.bat",
"cqlsh.py",
"cqlsh",
"cassandra.ps1",
"cqlsh.bat",
"debug-cql",
"cassandra.bat",
}
func TestNameList(t *testing.T) {
server, err := tempredis.Start(tempredis.Config{})
if err != nil {
panic(err)
}
defer server.Term()
2021-10-06 15:37:57 +08:00
client := redis.NewClient(&redis.Options{
2021-10-06 15:03:54 +08:00
Network: "unix",
Addr: server.Socket(),
})
store := newSkipListElementStore("/yyy/bin", client)
var data []byte
for _, name := range names {
2021-10-07 09:18:24 +08:00
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
2021-10-06 15:03:54 +08:00
nameList.WriteName(name)
nameList.ListNames("", func(name string) bool {
2021-10-07 11:40:16 +08:00
println(name)
2021-10-06 15:03:54 +08:00
return true
})
if nameList.HasChanges() {
data = nameList.ToBytes()
}
2021-10-07 11:40:16 +08:00
println()
2021-10-06 15:03:54 +08:00
}
2021-10-07 09:18:24 +08:00
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
2021-10-06 15:03:54 +08:00
nameList.ListNames("", func(name string) bool {
println(name)
return true
})
2021-10-06 15:37:57 +08:00
}
2021-10-07 11:40:16 +08:00
func BenchmarkNameList(b *testing.B) {
2021-10-06 15:37:57 +08:00
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++ {
2021-10-07 09:18:24 +08:00
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
2021-10-06 15:37:57 +08:00
2021-10-07 09:18:24 +08:00
nameList.WriteName(strconv.Itoa(i)+"namexxxxxxxxxxxxxxxxxxx")
2021-10-06 15:37:57 +08:00
if nameList.HasChanges() {
data = nameList.ToBytes()
}
}
}
2021-10-07 11:40:16 +08:00
func BenchmarkRedis(b *testing.B) {
2021-10-06 15:37:57 +08:00
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++ {
2021-10-07 09:18:24 +08:00
client.ZAddNX(context.Background(),"/yyy/bin", &redis.Z{Score: 0, Member: strconv.Itoa(i)+"namexxxxxxxxxxxxxxxxxxx"})
2021-10-06 15:37:57 +08:00
}
}
2021-10-07 11:40:16 +08:00
func xTestNameListAdd(t *testing.T) {
2021-10-07 09:18:24 +08:00
server, err := tempredis.Start(tempredis.Config{})
if err != nil {
panic(err)
}
defer server.Term()
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
client.FlushAll(context.Background())
N := 364800
ts0 := time.Now()
store := newSkipListElementStore("/y", client)
var data []byte
nameList := LoadItemList(data, "/y", client, store, 100000)
for i := 0; i < N; i++ {
nameList.WriteName(fmt.Sprintf("%8d", i))
}
ts1 := time.Now()
for i := 0; i < N; i++ {
client.ZAddNX(context.Background(),"/x", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)})
}
ts2 := time.Now()
fmt.Printf("%v %v", ts1.Sub(ts0), ts2.Sub(ts1))
/*
keys := client.Keys(context.Background(), "/*m").Val()
for _, k := range keys {
println("key", k)
for i, v := range client.ZRangeByLex(context.Background(), k, &redis.ZRangeBy{
Min: "-",
Max: "+",
}).Val() {
println(" ", i, v)
}
}
*/
}
2021-10-07 11:40:16 +08:00
func xBenchmarkNameList(b *testing.B) {
server, err := tempredis.Start(tempredis.Config{})
if err != nil {
panic(err)
}
defer server.Term()
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
store := newSkipListElementStore("/yyy/bin", client)
var data []byte
for i := 0; i < b.N; i++ {
2021-10-07 09:18:24 +08:00
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
2021-10-07 09:18:24 +08:00
nameList.WriteName(fmt.Sprintf("name %8d", i))
if nameList.HasChanges() {
data = nameList.ToBytes()
}
}
}
2021-10-07 11:40:16 +08:00
func xBenchmarkRedis(b *testing.B) {
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
})
for i := 0; i < b.N; i++ {
2021-10-07 09:18:24 +08:00
client.ZAddNX(context.Background(),"/xxx/bin", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)})
}
}