How consul deal with thundering herd in distributed locking?
- Dominant language
- Go
- Stars
- 30.1k
- Forks
- 4.6k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 43
Description
after looking into the code of consul's lock function:
in https://github.com/hashicorp/consul/blob/master/api/lock.go 200
`// Look for an existing lock, blocking until not taken`
` pair, meta, err := kv.Get(l.opts.Key, &qOpts)`
` if err != nil {`
` return nil, fmt.Errorf("failed to read lock: %v", err)`
` }`
when the lock is release by other clients or services, the others clients will wake up (modify index is update) and then do the following:
`locked, _, err = kv.Acquire(pair, &wOpts)`
If there are many clients waiting for the lock,they will wake up at the same time and then try to acquire the lock。This may result in a large number of api calls at the same time。
I don’t know if it ’s something wrong with my understanding,please help:)
Contributor guide
Assessment
This issue has not been assessed yet.