seaweedfs/weed/filer/redis3/kv_directory_children_test.go

211 lines
4.1 KiB
Go
Raw Normal View History

2021-10-06 07:03:54 +00:00
package redis3
import (
2021-10-06 07:37:57 +00:00
"context"
2021-10-07 01:18:24 +00:00
"fmt"
2021-10-06 07:37:57 +00:00
"github.com/go-redis/redis/v8"
2021-10-06 07:03:54 +00:00
"github.com/stvp/tempredis"
2021-10-06 07:37:57 +00:00
"strconv"
2021-10-06 07:03:54 +00:00
"testing"
2021-10-07 01:18:24 +00:00
"time"
2021-10-06 07:03:54 +00: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",
}
2021-10-11 05:14:13 +00:00
func yTestNameList(t *testing.T) {
2021-10-06 07:03:54 +00:00
server, err := tempredis.Start(tempredis.Config{})
if err != nil {
panic(err)
}
defer server.Term()
2021-10-06 07:37:57 +00:00
client := redis.NewClient(&redis.Options{
2021-10-06 07:03:54 +00:00
Network: "unix",
Addr: server.Socket(),
})
store := newSkipListElementStore("/yyy/bin", client)
var data []byte
for _, name := range names {
2021-10-07 01:18:24 +00:00
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
2021-10-06 07:03:54 +00:00
nameList.WriteName(name)
nameList.ListNames("", func(name string) bool {
2021-10-07 03:40:16 +00:00
println(name)
2021-10-06 07:03:54 +00:00
return true
})
if nameList.HasChanges() {
data = nameList.ToBytes()
}
2021-10-07 03:40:16 +00:00
println()
2021-10-06 07:03:54 +00:00
}
2021-10-07 01:18:24 +00:00
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
2021-10-06 07:03:54 +00:00
nameList.ListNames("", func(name string) bool {
println(name)
return true
})
2021-10-06 07:37:57 +00:00
}
2021-10-11 05:14:13 +00:00
func yBenchmarkNameList(b *testing.B) {
2021-10-06 07:37:57 +00: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 01:18:24 +00:00
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
2021-10-06 07:37:57 +00:00
2021-10-08 04:13:31 +00:00
nameList.WriteName(strconv.Itoa(i) + "namexxxxxxxxxxxxxxxxxxx")
2021-10-06 07:37:57 +00:00
if nameList.HasChanges() {
data = nameList.ToBytes()
}
}
}
2021-10-07 03:40:16 +00:00
func BenchmarkRedis(b *testing.B) {
2021-10-06 07:37:57 +00: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-08 04:13:31 +00:00
client.ZAddNX(context.Background(), "/yyy/bin", &redis.Z{Score: 0, Member: strconv.Itoa(i) + "namexxxxxxxxxxxxxxxxxxx"})
2021-10-06 07:37:57 +00:00
}
}
2021-10-07 03:40:16 +00:00
func xTestNameListAdd(t *testing.T) {
2021-10-07 01:18:24 +00: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++ {
2021-10-08 04:13:31 +00:00
client.ZAddNX(context.Background(), "/x", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)})
2021-10-07 01:18:24 +00:00
}
ts2 := time.Now()
fmt.Printf("%v %v", ts1.Sub(ts0), ts2.Sub(ts1))
/*
2021-10-08 04:13:31 +00:00
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 01:18:24 +00:00
}
2021-10-08 04:13:31 +00:00
*/
2021-10-07 01:18:24 +00:00
}
2021-10-07 03:40:16 +00: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 01:18:24 +00:00
nameList := LoadItemList(data, "/yyy/bin", client, store, maxNameBatchSizeLimit)
2021-10-07 01:18:24 +00:00
nameList.WriteName(fmt.Sprintf("name %8d", i))
if nameList.HasChanges() {
data = nameList.ToBytes()
}
}
}
2021-10-07 03:40:16 +00: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-08 04:13:31 +00:00
client.ZAddNX(context.Background(), "/xxx/bin", &redis.Z{Score: 0, Member: fmt.Sprintf("name %8d", i)})
}
}