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

Original vs hedged request metrics #46

Merged
merged 5 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions hedged.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func (ht *hedgedTransport) RoundTrip(req *http.Request) (*http.Response, error)
switch {
case resp.Resp != nil:
resultIdx = resp.Index
if resultIdx == 0 {
ht.metrics.originalRequestWinsInc()
cristaloleg marked this conversation as resolved.
Show resolved Hide resolved
} else {
ht.metrics.hedgedRequestWinsInc()
}
return resp.Resp, nil
case mainCtx.Err() != nil:
ht.metrics.canceledByUserRoundTripsInc()
Expand Down
14 changes: 14 additions & 0 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Stats struct {
requestedRoundTrips atomicCounter
actualRoundTrips atomicCounter
failedRoundTrips atomicCounter
originalRequestWins atomicCounter
hedgedRequestWins atomicCounter
canceledByUserRoundTrips atomicCounter
canceledSubRequests atomicCounter
_ cacheLine
Expand All @@ -24,6 +26,8 @@ type Stats struct {
func (s *Stats) requestedRoundTripsInc() { atomic.AddUint64(&s.requestedRoundTrips.count, 1) }
func (s *Stats) actualRoundTripsInc() { atomic.AddUint64(&s.actualRoundTrips.count, 1) }
func (s *Stats) failedRoundTripsInc() { atomic.AddUint64(&s.failedRoundTrips.count, 1) }
func (s *Stats) originalRequestWinsInc() { atomic.AddUint64(&s.originalRequestWins.count, 1) }
func (s *Stats) hedgedRequestWinsInc() { atomic.AddUint64(&s.hedgedRequestWins.count, 1) }
func (s *Stats) canceledByUserRoundTripsInc() { atomic.AddUint64(&s.canceledByUserRoundTrips.count, 1) }
func (s *Stats) canceledSubRequestsInc() { atomic.AddUint64(&s.canceledSubRequests.count, 1) }

Expand All @@ -42,6 +46,16 @@ func (s *Stats) FailedRoundTrips() uint64 {
return atomic.LoadUint64(&s.failedRoundTrips.count)
}

// OriginalRequestWins returns count of original requests that were faster than the original.
func (s *Stats) OriginalRequestWins() uint64 {
return atomic.LoadUint64(&s.originalRequestWins.count)
}

// HedgedRequestWins returns count of hedged requests that were faster than the original.
func (s *Stats) HedgedRequestWins() uint64 {
return atomic.LoadUint64(&s.hedgedRequestWins.count)
}

// CanceledByUserRoundTrips returns count of requests that were canceled by user, using request context.
func (s *Stats) CanceledByUserRoundTrips() uint64 {
return atomic.LoadUint64(&s.canceledByUserRoundTrips.count)
Expand Down