Skip to content

Commit

Permalink
*: avoid thundering herd problem when timeout the stats sync load (#5…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Feb 13, 2024
1 parent 2ec7e32 commit 0bca811
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion statistics/handle/handle_hist.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package handle

import (
"fmt"
"math/rand"
"sync"
"time"

Expand Down Expand Up @@ -204,7 +205,10 @@ func (h *Handle) SubLoadWorker(ctx sessionctx.Context, exit chan struct{}, exitW
case errExit:
return
default:
time.Sleep(h.Lease() / 10)
// To avoid the thundering herd effect
// thundering herd effect: Everyone tries to retry a large number of requests simultaneously when a problem occurs.
r := rand.Intn(500)
time.Sleep(h.Lease()/10 + time.Duration(r)*time.Microsecond)
continue
}
}
Expand Down

0 comments on commit 0bca811

Please sign in to comment.