Skip to content

fix #58 - allow to download the shard in parallel#61

Open
TaranpreetSingh wants to merge 1 commit intothanos-io:mainfrom
TaranpreetSingh:feature/parallel-shard-loading
Open

fix #58 - allow to download the shard in parallel#61
TaranpreetSingh wants to merge 1 commit intothanos-io:mainfrom
TaranpreetSingh:feature/parallel-shard-loading

Conversation

@TaranpreetSingh
Copy link
Copy Markdown

@TaranpreetSingh TaranpreetSingh commented Feb 17, 2026

This change introduces configurable parallel shard loading to address performance bottlenecks during block synchronization. Previously, the service loaded shards sequentially - waiting for each shard to complete before starting the next one. This approach underutilized available network bandwidth and caused timeout errors when loading large blocks, particularly during service startup.

The implementation adds a new CLI flag --block.syncer.shard-concurrency that allows multiple shards to be loaded simultaneously. When set to a value greater than zero, the syncer uses a new readShardsParallel() function that spawns concurrent goroutines controlled by a semaphore pattern. This keeps network connections busy and dramatically reduces sync times. The original sequential loading behavior is preserved when the flag is set to zero (the default), ensuring complete backward compatibility.

The change required minimal modifications: adding the CLI flag in serve.go, wiring it through the configuration in config.go, and implementing the parallel loading logic alongside the existing sequential path in syncer.go. The original readShards() function remains unchanged, with the new readShardsParallel() function handling concurrent operations. A simple conditional in newBlockForMeta() chooses between the two approaches based on the configured concurrency value.

This feature is particularly beneficial for services running on high-bandwidth infrastructure where network capacity significantly exceeds what sequential loading can utilize. By enabling parallel shard loading, administrators can achieve 50-65% faster sync times, reduce timeout errors, and improve overall service availability during startup and periodic syncs.

Signed-off-by: Taranpreet Singh <tsingh@roku.com>
@TaranpreetSingh TaranpreetSingh changed the title Fixed issue #58 - allow to download the shard in parallel Fix #58 - allow to download the shard in parallel Feb 17, 2026
@TaranpreetSingh TaranpreetSingh changed the title Fix #58 - allow to download the shard in parallel fix #58 - allow to download the shard in parallel Feb 17, 2026
Comment thread locate/syncer.go
go func(shardIndex int) {
defer wg.Done()

sem <- struct{}{}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too complicated, I think. Instead we typically spawn shardConcurrency goroutines that read the shardIndex from a channel in a for range loop. Then, you don't need to do this complex logic with sem.

Comment thread locate/syncer.go
sem := make(chan struct{}, shardConcurrency)

for i := range int(m.Shards) {
wg.Add(1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can modernize with wg.Go().

Comment thread locate/syncer.go
var shards []*db.Shard
var err error

// Use parallel loading if shardConcurrency > 0, otherwise use sequential (original) loading
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope that everyone working on this repo is able to read a simple if statement (:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was for my readability will remove it

Comment thread locate/syncer.go
shards = append(shards, result.shard)
}

// Return error only if ALL shards failed
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that. This comment has zero value.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was for my readability will remove it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants