client exponential backoff

This commit is contained in:
Stephen McQuay 2018-01-26 18:05:04 -08:00
parent 5997dc44d8
commit 82946a1480
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5

View File

@ -3,9 +3,11 @@ package main
import (
"context"
"fmt"
"math/rand"
"net/http"
"os"
"strings"
"time"
"github.com/twitchtv/twirp"
@ -36,12 +38,18 @@ func main() {
for i := 0; ; i++ {
s <- true
go func(j int) {
resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")})
if err != nil {
fmt.Fprintf(os.Stderr, "hello: %#v\n", err)
os.Exit(1)
sleep := time.Duration(250+rand.Intn(500)) * time.Millisecond
for {
resp, err := c.Hello(ctx, &pb.HelloReq{Subject: strings.Join(os.Args[2:], " ")})
if err == nil {
fmt.Printf("0x%08x: %#v\n", j, resp)
break
}
fmt.Fprintf(os.Stderr, "sleeping %v because: %v\n", sleep, err)
time.Sleep(sleep)
sleep *= 2
continue
}
fmt.Printf("0x%08x: %#v\n", j, resp)
<-s
}(i)
}