-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
reproduce write latency #18121
base: main
Are you sure you want to change the base?
reproduce write latency #18121
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,11 @@ import ( | |
"context" | ||
"fmt" | ||
"os" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/cheggaaa/pb/v3" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/time/rate" | ||
|
||
clientv3 "go.etcd.io/etcd/client/v3" | ||
"go.etcd.io/etcd/pkg/v3/report" | ||
|
@@ -61,31 +61,23 @@ func init() { | |
} | ||
|
||
func watchLatencyFunc(_ *cobra.Command, _ []string) { | ||
key := string(mustRandBytes(watchLKeySize)) | ||
key := "/registry/pods" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How this impacts the results? If it doesn't then please remove. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not. Will remove. Just to demonstrate that it could happen on pods, and it's a generic problem (not limited to events) |
||
value := string(mustRandBytes(watchLValueSize)) | ||
wchs := setupWatchChannels(key) | ||
putClient := mustCreateConn() | ||
|
||
bar = pb.New(watchLPutTotal * len(wchs)) | ||
bar.Start() | ||
|
||
limiter := rate.NewLimiter(rate.Limit(watchLPutRate), watchLPutRate) | ||
|
||
putTimes := make([]time.Time, watchLPutTotal) | ||
eventTimes := make([][]time.Time, len(wchs)) | ||
|
||
for i, wch := range wchs { | ||
for _, wch := range wchs { | ||
wch := wch | ||
i := i | ||
eventTimes[i] = make([]time.Time, watchLPutTotal) | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
eventCount := 0 | ||
for eventCount < watchLPutTotal { | ||
resp := <-wch | ||
for range resp.Events { | ||
eventTimes[i][eventCount] = time.Now() | ||
eventCount++ | ||
bar.Increment() | ||
} | ||
|
@@ -95,40 +87,30 @@ func watchLatencyFunc(_ *cobra.Command, _ []string) { | |
|
||
putReport := newReport() | ||
putReportResults := putReport.Run() | ||
watchReport := newReport() | ||
watchReportResults := watchReport.Run() | ||
for i := 0; i < watchLPutTotal; i++ { | ||
// limit key put as per reqRate | ||
if err := limiter.Wait(context.TODO()); err != nil { | ||
break | ||
} | ||
start := time.Now() | ||
if _, err := putClient.Put(context.TODO(), key, value); err != nil { | ||
fmt.Fprintf(os.Stderr, "Failed to Put for watch latency benchmark: %v\n", err) | ||
os.Exit(1) | ||
} | ||
end := time.Now() | ||
putReport.Results() <- report.Result{Start: start, End: end} | ||
putTimes[i] = end | ||
|
||
var putCount atomic.Uint64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify what is the goal of the changes? From what I see you removed measuring watch latency, parallelized the puts, and you measure put latency. Maybe I'm just surprised you modified watch latency benchmark and not put one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about that == I was meant to demonstrate that write latency could be impacted by slow Hopefully we can find a balance between write and watch latency. |
||
for i := 0; i < watchLPutRate; i++ { | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
for { | ||
if putCount.Load() >= uint64(watchLPutTotal) { | ||
return | ||
} | ||
start := time.Now() | ||
if _, err := putClient.Put(context.TODO(), key, value); err != nil { | ||
fmt.Fprintf(os.Stderr, "Failed to Put for watch latency benchmark: %v\n", err) | ||
} | ||
end := time.Now() | ||
putReport.Results() <- report.Result{Start: start, End: end} | ||
putCount.Add(1) | ||
} | ||
}() | ||
} | ||
wg.Wait() | ||
close(putReport.Results()) | ||
bar.Finish() | ||
fmt.Printf("\nPut summary:\n%s", <-putReportResults) | ||
|
||
for i := 0; i < len(wchs); i++ { | ||
for j := 0; j < watchLPutTotal; j++ { | ||
start := putTimes[j] | ||
end := eventTimes[i][j] | ||
if end.Before(start) { | ||
start = end | ||
} | ||
watchReport.Results() <- report.Result{Start: start, End: end} | ||
} | ||
} | ||
|
||
close(watchReport.Results()) | ||
fmt.Printf("\nWatch events summary:\n%s", <-watchReportResults) | ||
} | ||
|
||
func setupWatchChannels(key string) []clientv3.WatchChan { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How this impacts the results? If it doesn't then please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not. Will remove.