Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement maintaining multiple lease support for benchmark #18927

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions tools/benchmark/cmd/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,40 @@ var leaseKeepaliveCmd = &cobra.Command{

var (
leaseKeepaliveTotal int
leaseCount int
)

func init() {
RootCmd.AddCommand(leaseKeepaliveCmd)
leaseKeepaliveCmd.Flags().IntVar(&leaseCount, "leases", 1, "Number of lease objects")
leaseKeepaliveCmd.Flags().IntVar(&leaseKeepaliveTotal, "total", 10000, "Total number of lease keepalive requests")
}

func leaseKeepaliveFunc(_ *cobra.Command, _ []string) {
requests := make(chan struct{})
func leaseKeepaliveFunc(cmd *cobra.Command, args []string) {
requests := make(chan v3.LeaseID)
clients := mustCreateClients(totalClients, totalConns)

bar = pb.New(leaseKeepaliveTotal)
bar.Format("Bom !")

leases := []v3.LeaseID{}
for i := 0; i < leaseCount; i++ {
resp, err := clients[i%len(clients)].Grant(context.Background(), 100)
if err != nil {
panic(err)
}
leases = append(leases, resp.ID)
}
bar.Start()

r := newReport()
for i := range clients {
wg.Add(1)
go func(c v3.Lease) {
defer wg.Done()
resp, err := c.Grant(context.Background(), 100)
if err != nil {
panic(err)
}
for range requests {
for leaseID := range requests {
st := time.Now()
_, err := c.KeepAliveOnce(context.TODO(), resp.ID)
_, err := c.KeepAliveOnce(context.TODO(), leaseID)
r.Results() <- report.Result{Err: err, Start: st, End: time.Now()}
bar.Increment()
}
Expand All @@ -71,7 +79,7 @@ func leaseKeepaliveFunc(_ *cobra.Command, _ []string) {
go func() {
defer wg.Done()
for i := 0; i < leaseKeepaliveTotal; i++ {
requests <- struct{}{}
requests <- leases[i%len(leases)]
}
close(requests)
}()
Expand Down