Skip to content

Commit 1e5a8ac

Browse files
committed
lease: rate limit revoke runLoop
Fix #8097. Signed-off-by: Gyu-Ho Lee <[email protected]>
1 parent e6d2667 commit 1e5a8ac

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lease/lessor.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package lease
1616

1717
import (
18+
"context"
1819
"encoding/binary"
1920
"errors"
2021
"math"
@@ -26,11 +27,17 @@ import (
2627
"github.com/coreos/etcd/lease/leasepb"
2728
"github.com/coreos/etcd/mvcc/backend"
2829
"github.com/coreos/etcd/pkg/monotime"
30+
31+
"golang.org/x/time/rate"
2932
)
3033

3134
const (
3235
// NoLease is a special LeaseID representing the absence of a lease.
3336
NoLease = LeaseID(0)
37+
38+
// maximum number of leases to revoke per second
39+
// TODO: make this configurable?
40+
leaseRevokesPerSecond = 1000
3441
)
3542

3643
var (
@@ -412,7 +419,8 @@ func (le *lessor) Stop() {
412419
func (le *lessor) runLoop() {
413420
defer close(le.doneC)
414421

415-
for {
422+
revokerLimiter := rate.NewLimiter(rate.Limit(leaseRevokesPerSecond), leaseRevokesPerSecond)
423+
for revokerLimiter.Wait(context.Background()) == nil {
416424
var ls []*Lease
417425

418426
le.mu.Lock()

0 commit comments

Comments
 (0)