1
0
mirror of https://github.com/FloatTech/zbpdata.git synced 2024-11-17 17:47:14 +09:00

增加竞争速度

This commit is contained in:
源文雨 2022-04-17 20:32:57 +08:00
parent 7aa2cbd0f5
commit 365b1a915a

31
main.go
View File

@ -14,7 +14,6 @@ import (
"unicode"
"unsafe"
"github.com/FloatTech/zbputils/process"
"github.com/fumiama/go-registry"
"github.com/wdvxdr1123/ZeroBot/utils/helper"
)
@ -47,31 +46,23 @@ func main() {
panic(err)
}
defer r.Close()
for i := 0; i < 1024; i++ {
err = r.Set("__setlock__", "fill")
if err == nil {
break
do1024 := func(k, v string) {
for i := 0; i < 1024; i++ {
err = r.Set(k, v)
if err == nil {
break
}
fmt.Println("accqiring set lock, retry times:", i)
}
fmt.Println("accqiring set lock, retry times:", i)
}
do1024("__setlock__", "fill")
var wg sync.WaitGroup
wg.Add(len(files))
for i, fn := range files {
go func(i int, fn string) {
defer wg.Done()
for c := 0; c < 5; c++ {
err = r.Set("data/"+fn, md5s[i])
fmt.Println("set", "data/"+fn, "=", hex.EncodeToString(helper.StringToBytes(md5s[i])))
if err == nil {
break
}
if c >= 4 {
panic("ERROR:" + err.Error() + "max retry times exceeded")
} else {
fmt.Println("ERROR:", err, ", retry times:", c)
}
process.SleepAbout1sTo2s()
}
do1024("data/"+fn, md5s[i])
fmt.Println("set", "data/"+fn, "=", hex.EncodeToString(helper.StringToBytes(md5s[i])))
wg.Done()
}(i, fn)
}
wg.Wait()