-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
go/vt/topo: enable concurrency for FindAllShardsInKeyspace #14670
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
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.
Looks good!
Signed-off-by: Matt Layher <[email protected]>
cb25918
to
3485022
Compare
In the 256 shard case, we might end up with 256*8 concurrent requests to the topo. Is that expected to be safe? |
Edit: my read was was incorrect, see Deepthi's reply below. I don't believe that's true based on my read here: func (ts *Server) FindAllShardsInKeyspace(ctx context.Context, keyspace string) (map[string]*ShardInfo, error) {
shards, err := ts.GetShardNames(ctx, keyspace) This accepts a single keyspace name as input and fetches its component shards. eg, ctx := errgroup.WithContext(ctx)
eg.SetLimit(8)
for _, shard := range shards {
shard := shard
eg.Go(func() error { The loop here will begin iterating over those shards while 8 goroutines execute concurrently to fetch the shard records. It's the same number of total calls as before, but by scheduling 8 calls at a time rather than 1, we should see a significant speedup. edit: do you mean that each tablet invokes this code as well? |
That is what the original issue was running into. Tablet initialization -> CreateShard -> FindAllShardsInKeyspace |
One option would be to expose the concurrency as a parameter to the call. The CreateShard uses can use a concurrency of 1 to avoid an already thundering herd while vtctld uses can use 8 instead. |
I can't say that I like this idea, but on the other hand, I don't think there's a better way than this though :( |
Signed-off-by: Matt Layher <[email protected]>
I have retitled the PR and updated the description to note that the concurrency is now tunable on a per-call-site basis. The two places I can think of that really benefit from this based on what we've seen are:
Any objections to setting a concurrency of 8 for both of those as a starting point? See the TODOs. |
Signed-off-by: Matt Layher <[email protected]>
Ready to go! |
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.
fix the potential panic and we're good to go! everything else is nitpicks, take it or leave it :)
go/vt/topo/keyspace.go
Outdated
if cfg == nil { | ||
cfg = &FindAllShardsInKeyspaceConfig{} | ||
} | ||
if cfg.Concurrency == 0 { | ||
cfg.Concurrency = 1 | ||
} |
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.
extreme nit: can technically skip one extra statement by setting the default when cfg
is nil
if cfg == nil { | |
cfg = &FindAllShardsInKeyspaceConfig{} | |
} | |
if cfg.Concurrency == 0 { | |
cfg.Concurrency = 1 | |
} | |
if cfg == nil { | |
cfg = &FindAllShardsInKeyspaceConfig{Concurrency: 1} | |
} | |
if cfg.Concurrency == 0 { | |
cfg.Concurrency = 1 | |
} |
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.
Ack, the one reason I didn't do this is because you'd have to duplicate any future options in the same manner. I'll leave this as is.
Signed-off-by: Matt Layher <[email protected]>
Signed-off-by: Matt Layher <[email protected]>
Signed-off-by: Matt Layher <[email protected]>
Signed-off-by: Matt Layher <[email protected]>
cc6f01b
to
3ba7551
Compare
…14670) Signed-off-by: Matt Layher <[email protected]>
Description
Speed up
FindAllShardsInKeyspace
by employing caller-controlled concurrency to avoid 30+ second runtimes for this call.I've added a new struct for configuration here since certain cases such as
CreateShard
should not make concurrent calls in order to avoid a thundering herd on the topo.Related Issue(s)
Fixes #14669.
Introduces some limited concurrency rather than the unbounded concurrency which was removed in #5436.
Checklist
Deployment Notes
n/a