Skip to content
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

feat: Update concurrency formula. #1907

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,16 @@ func NewScheduler(opts ...Option) *Scheduler {
for _, opt := range opts {
opt(&s)
}

actualMinResourceConcurrency := minResourceConcurrency
if s.concurrency <= minResourceConcurrency {
actualMinResourceConcurrency = max(s.concurrency/10, 1)
}

// This is very similar to the concurrent web crawler problem with some minor changes.
// We are using DFS/Round-Robin to make sure memory usage is capped at O(h) where h is the height of the tree.
tableConcurrency := max(s.concurrency/minResourceConcurrency, minTableConcurrency)
resourceConcurrency := tableConcurrency * minResourceConcurrency
tableConcurrency := max(s.concurrency/actualMinResourceConcurrency, minTableConcurrency)
resourceConcurrency := tableConcurrency * actualMinResourceConcurrency
s.tableSems = make([]*semaphore.Weighted, s.maxDepth)
for i := uint64(0); i < s.maxDepth; i++ {
s.tableSems[i] = semaphore.NewWeighted(int64(tableConcurrency))
Expand Down
Loading