Skip to content

Commit

Permalink
track original and hedged datastore request durations separately
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Moshenko <jacob.moshenko@gmail.com>
  • Loading branch information
jakedt committed Oct 15, 2021
1 parent 364708f commit 3250215
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions internal/datastore/proxy/hedging.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,34 @@ func newHedger(
slowRequestThreshold := time.Duration(slowRequestThresholdSeconds * float64(time.Second))

timer := timeSource.Timer(slowRequestThreshold)
start := timeSource.Now()
originalStart := timeSource.Now()

ctx, cancel := context.WithCancel(ctx)
defer cancel()
hedgeableCount.Inc()
go req(ctx, responseReady)

var duration time.Duration

select {
case <-responseReady:
duration = timeSource.Since(originalStart)
case <-timer.C:
log.Debug().Dur("after", slowRequestThreshold).Msg("sending hedged datastore request")
hedgedCount.Inc()
go req(ctx, responseReady)
<-responseReady

hedgedResponseReady := make(chan struct{})
hedgedStart := timeSource.Now()
go req(ctx, hedgedResponseReady)

select {
case <-responseReady:
duration = timeSource.Since(originalStart)
case <-hedgedResponseReady:
duration = timeSource.Since(hedgedStart)
}
}

// Compute how long it took for us to get any answer
duration := timeSource.Since(start)
digestLock.Lock()
defer digestLock.Unlock()

Expand Down

0 comments on commit 3250215

Please sign in to comment.