go/vt/topo: enable concurrency for FindAllShardsInKeyspace#14670
go/vt/topo: enable concurrency for FindAllShardsInKeyspace#14670vmg merged 7 commits intovitessio:mainfrom
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
|
Signed-off-by: Matt Layher <mdlayher@planetscale.com>
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 <mdlayher@planetscale.com>
|
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 <mdlayher@planetscale.com>
|
Ready to go! |
ajm188
left a comment
There was a problem hiding this comment.
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.
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.
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 <mdlayher@planetscale.com>
Signed-off-by: Matt Layher <mdlayher@planetscale.com>
Signed-off-by: Matt Layher <mdlayher@planetscale.com>
Signed-off-by: Matt Layher <mdlayher@planetscale.com>
cc6f01b to
3ba7551
Compare
…14670) Signed-off-by: Matt Layher <mdlayher@planetscale.com>
Description
Speed up
FindAllShardsInKeyspaceby 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
CreateShardshould 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