Skip to content

Commit 1245657

Browse files
committed
benchmark: Connect to all endpoints instead of polling them
Signed-off-by: hwdef <[email protected]>
1 parent aeb47ee commit 1245657

File tree

1 file changed

+1
-46
lines changed

1 file changed

+1
-46
lines changed

tools/benchmark/cmd/util.go

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package cmd
1616

1717
import (
18-
"context"
1918
"crypto/rand"
2019
"fmt"
2120
"os"
@@ -29,44 +28,11 @@ import (
2928
)
3029

3130
var (
32-
// dialTotal counts the number of mustCreateConn calls so that endpoint
33-
// connections can be handed out in round-robin order
34-
dialTotal int
35-
36-
// leaderEps is a cache for holding endpoints of a leader node
37-
leaderEps []string
38-
3931
// cache the username and password for multiple connections
4032
globalUserName string
4133
globalPassword string
4234
)
4335

44-
func mustFindLeaderEndpoints(c *clientv3.Client) {
45-
resp, lerr := c.MemberList(context.TODO())
46-
if lerr != nil {
47-
fmt.Fprintf(os.Stderr, "failed to get a member list: %s\n", lerr)
48-
os.Exit(1)
49-
}
50-
51-
leaderID := uint64(0)
52-
for _, ep := range c.Endpoints() {
53-
if sresp, serr := c.Status(context.TODO(), ep); serr == nil {
54-
leaderID = sresp.Leader
55-
break
56-
}
57-
}
58-
59-
for _, m := range resp.Members {
60-
if m.ID == leaderID {
61-
leaderEps = m.ClientURLs
62-
return
63-
}
64-
}
65-
66-
fmt.Fprint(os.Stderr, "failed to find a leader endpoint\n")
67-
os.Exit(1)
68-
}
69-
7036
func getUsernamePassword(usernameFlag string) (string, string, error) {
7137
if globalUserName != "" && globalPassword != "" {
7238
return globalUserName, globalPassword, nil
@@ -88,14 +54,9 @@ func getUsernamePassword(usernameFlag string) (string, string, error) {
8854
}
8955

9056
func mustCreateConn() *clientv3.Client {
91-
connEndpoints := leaderEps
92-
if len(connEndpoints) == 0 {
93-
connEndpoints = []string{endpoints[dialTotal%len(endpoints)]}
94-
dialTotal++
95-
}
9657
cfg := clientv3.Config{
9758
AutoSyncInterval: autoSyncInterval,
98-
Endpoints: connEndpoints,
59+
Endpoints: endpoints,
9960
DialTimeout: dialTimeout,
10061
}
10162
if !tls.Empty() || tls.TrustedCAFile != "" {
@@ -118,12 +79,6 @@ func mustCreateConn() *clientv3.Client {
11879
}
11980

12081
client, err := clientv3.New(cfg)
121-
if targetLeader && len(leaderEps) == 0 {
122-
mustFindLeaderEndpoints(client)
123-
client.Close()
124-
return mustCreateConn()
125-
}
126-
12782
grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, os.Stderr, os.Stderr))
12883

12984
if err != nil {

0 commit comments

Comments
 (0)