lease: rate limit revoke runLoop

Fix https://github.com/coreos/etcd/issues/8097.

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyu-Ho Lee 2017-06-14 12:54:50 -07:00
parent 91ccc93042
commit c14aad0ba6

View File

@ -31,6 +31,10 @@ import (
const ( const (
// NoLease is a special LeaseID representing the absence of a lease. // NoLease is a special LeaseID representing the absence of a lease.
NoLease = LeaseID(0) NoLease = LeaseID(0)
// maximum number of leases to revoke per iteration
// TODO: make this configurable?
leaseRevokeRate = 1000
) )
var ( var (
@ -422,6 +426,10 @@ func (le *lessor) runLoop() {
le.mu.Unlock() le.mu.Unlock()
if len(ls) != 0 { if len(ls) != 0 {
// rate limit
if len(ls) > leaseRevokeRate/2 {
ls = ls[:leaseRevokeRate/2]
}
select { select {
case <-le.stopC: case <-le.stopC:
return return