Commit 94a698f6 authored by 李伟@五瓣科技's avatar 李伟@五瓣科技

print Sending batchTxs to redis

parent 36f9fd66
......@@ -8,12 +8,15 @@ import (
"runtime"
"time"
"code.wuban.net.cn/multisend/internal/logging"
"github.com/go-redis/redis/v8"
"golang.org/x/time/rate"
)
var (
jobnum = runtime.NumCPU()
loggerRedis = logging.NewLogrusLogger("redis")
)
type Job struct {
......@@ -46,15 +49,12 @@ func Start(redisAddr, passwd string) {
limiter := rate.NewLimiter(rate.Every(time.Millisecond*100), 1)
cxt, _ := context.WithCancel(context.TODO())
logTicker := time.NewTicker(5 * time.Second)
for {
limiter.Wait(cxt)
select {
case batchTxs := <-batchTxsForRedis:
//startTime := time.Now()
// data, err := proto.Marshal(txs)
// if err != nil {
// panic(err)
// }
batchTxsAsBytes, err := json.Marshal(batchTxs)
......@@ -65,9 +65,11 @@ func Start(redisAddr, passwd string) {
if err := client.LPush(context.Background(), "list", batchTxsAsBytes).Err(); err != nil {
panic(err)
}
count += 1
//fmt.Printf("count %d txs size: %d takes %v time: %s \n", count, len(batchTxsAsBytes), time.Since(startTime), time.Now())
case <-logTicker.C:
loggerRedis.Info("Sending batchTxs to redis", "idx", count, "toRedis", redisAddr, "totaltxsCount", batchTxSize*count, "now", time.Now().Format("15:04:05"))
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment