-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] *: Fully concurrent large reads #10472
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7e2c528
*: allow fully concurrent large read
xiang90 26cc354
tools/benchmark: Add --prefix support to tools/benchmark range
jpbetz 51e6dce
mvcc: add metrics to characterize large reads
jingyih ba48da9
Merge pull request #1 from jingyih/expensive_read_instrumentation
jpbetz 72f0b2e
*: add flag for backend expensive read limit
jingyih 1baaac0
Merge pull request #2 from jingyih/expensive_read_instrumentation
jpbetz b96249a
mvcc: Limit number of bbolt read transactions opened by committed reads
jpbetz c616f7c
Merge pull request #3 from jpbetz/read-txn-limit
jpbetz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2019 The etcd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package backend | ||
|
||
// ReadTxRequest is a channel to send a requested ReadTx to when it becomes available. | ||
type ReadTxRequest = chan ReadTx | ||
|
||
// concurrentReadScheduler accumulates requests to begin concurrent ReadTxs and waits until | ||
// BeginConcurrentReadTxs is called to begin them. It also limits the number of | ||
// concurrent ReadTxs running at any point in time to the provided maxConcurrentReadTxs. | ||
type concurrentReadScheduler struct { | ||
maxConcurrentReadTxs uint64 | ||
readTxCh chan ReadTxRequest | ||
b *backend | ||
pendingReadCounter *GaugedCounter | ||
openReadCounter *GaugedCounter | ||
} | ||
|
||
func newConcurrentReadScheduler(b *backend, maxConcurrentReadTxs uint64) *concurrentReadScheduler { | ||
return &concurrentReadScheduler{ | ||
maxConcurrentReadTxs: maxConcurrentReadTxs, | ||
readTxCh: make(chan ReadTxRequest), | ||
b: b, | ||
pendingReadCounter: &GaugedCounter{0, pendingReadGauge}, | ||
openReadCounter: &GaugedCounter{0, openReadGauge}, | ||
} | ||
} | ||
|
||
// RequestConcurrentReadTx requests a new ReadTx and blocks until it is available. | ||
func (r *concurrentReadScheduler) RequestConcurrentReadTx() ReadTx { | ||
rch := make(chan ReadTx) | ||
r.pendingReadCounter.Inc() | ||
defer r.pendingReadCounter.Dec() | ||
r.readTxCh <- rch | ||
return <-rch | ||
} | ||
|
||
// BeginConcurrentReadTxs begins pending read transactions and sends them | ||
// to the channels of all blocked RequestReadTx() callers. | ||
// Ensures more than maxConcurrentReadTxns are running at the same time. | ||
func (r *concurrentReadScheduler) BeginConcurrentReadTxs() { | ||
// TODO(jpbetz): This has the potential to backlog indefinitely under heavly load. | ||
// If we're going to impose a limit here. We might want to do more to ensure we're | ||
// managing context deadlines and cancelations also. | ||
|
||
concurrentReadTxs := r.openReadCounter.Value() | ||
for i := uint64(0); i < (r.maxConcurrentReadTxs - concurrentReadTxs); i++ { | ||
select { | ||
case rch := <-r.readTxCh: | ||
rtx, err := r.b.db.Begin(false) | ||
if err != nil { | ||
plog.Fatalf("cannot begin read tx (%s)", err) | ||
} | ||
rch <- &MonitoredReadTx{r.openReadCounter, &concurrentReadTx{tx: rtx}} | ||
default: | ||
// no more to create. | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2018 The etcd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package backend | ||
|
||
import ( | ||
bolt "go.etcd.io/bbolt" | ||
) | ||
|
||
type concurrentReadTx struct { | ||
tx *bolt.Tx | ||
} | ||
|
||
func (rt *concurrentReadTx) Lock() {} | ||
func (rt *concurrentReadTx) Unlock() { rt.tx.Rollback() } | ||
|
||
func (rt *concurrentReadTx) UnsafeRange(bucketName, key, endKey []byte, limit int64) ([][]byte, [][]byte) { | ||
bucket := rt.tx.Bucket(bucketName) | ||
if bucket == nil { | ||
plog.Fatalf("bucket %s does not exist", bucketName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
} | ||
return unsafeRange(bucket.Cursor(), key, endKey, limit) | ||
} | ||
|
||
func (rt *concurrentReadTx) UnsafeForEach(bucketName []byte, visitor func(k, v []byte) error) error { | ||
return unsafeForEach(rt.tx, bucketName, visitor) | ||
} | ||
|
||
func (m *MonitoredReadTx) UnsafeRange(bucketName, key, endKey []byte, limit int64) ([][]byte, [][]byte) { | ||
return m.Tx.UnsafeRange(bucketName, key, endKey, limit) | ||
} | ||
func (m *MonitoredReadTx) UnsafeForEach(bucketName []byte, visitor func(k, v []byte) error) error { | ||
return m.Tx.UnsafeForEach(bucketName, visitor) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to also add zap here capnslog will be dropped in 3.4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I'll add it.