Skip to content

Commit

Permalink
lease: rate limit revoke runLoop
Browse files Browse the repository at this point in the history
Fix #8097.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Jun 14, 2017
1 parent e6d2667 commit 1e5a8ac
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lease/lessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package lease

import (
"context"
"encoding/binary"
"errors"
"math"
Expand All @@ -26,11 +27,17 @@ import (
"github.com/coreos/etcd/lease/leasepb"
"github.com/coreos/etcd/mvcc/backend"
"github.com/coreos/etcd/pkg/monotime"

"golang.org/x/time/rate"
)

const (
// NoLease is a special LeaseID representing the absence of a lease.
NoLease = LeaseID(0)

// maximum number of leases to revoke per second
// TODO: make this configurable?
leaseRevokesPerSecond = 1000
)

var (
Expand Down Expand Up @@ -412,7 +419,8 @@ func (le *lessor) Stop() {
func (le *lessor) runLoop() {
defer close(le.doneC)

for {
revokerLimiter := rate.NewLimiter(rate.Limit(leaseRevokesPerSecond), leaseRevokesPerSecond)
for revokerLimiter.Wait(context.Background()) == nil {
var ls []*Lease

le.mu.Lock()
Expand Down

0 comments on commit 1e5a8ac

Please sign in to comment.