1
0
mirror of https://github.com/FloatTech/zbpdata.git synced 2024-09-29 17:36:28 +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" "unicode"
"unsafe" "unsafe"
"github.com/FloatTech/zbputils/process"
"github.com/fumiama/go-registry" "github.com/fumiama/go-registry"
"github.com/wdvxdr1123/ZeroBot/utils/helper" "github.com/wdvxdr1123/ZeroBot/utils/helper"
) )
@ -47,31 +46,23 @@ func main() {
panic(err) panic(err)
} }
defer r.Close() defer r.Close()
for i := 0; i < 1024; i++ { do1024 := func(k, v string) {
err = r.Set("__setlock__", "fill") for i := 0; i < 1024; i++ {
if err == nil { err = r.Set(k, v)
break 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 var wg sync.WaitGroup
wg.Add(len(files)) wg.Add(len(files))
for i, fn := range files { for i, fn := range files {
go func(i int, fn string) { go func(i int, fn string) {
defer wg.Done() do1024("data/"+fn, md5s[i])
for c := 0; c < 5; c++ { fmt.Println("set", "data/"+fn, "=", hex.EncodeToString(helper.StringToBytes(md5s[i])))
err = r.Set("data/"+fn, md5s[i]) wg.Done()
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()
}
}(i, fn) }(i, fn)
} }
wg.Wait() wg.Wait()