Skip to content

Index concurrency limit checks when assigning tasks - #7322

Closed
6543 wants to merge 2 commits into
woodpecker-ci:mainfrom
6543-forks:less-gc-queue
Closed

6543 wants to merge 2 commits into
woodpecker-ci:mainfrom
6543-forks:less-gc-queue

Conversation

@6543

@6543 6543 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

assignToWorker checked the concurrency limit of every pending task, and each check scanned all running, pending and waiting tasks again. so a backlog in a concurrency group made every scheduling pass quadratic while holding the queue lock, ~1s per pass at 10k tasks.

now the check uses an index of the queue built once per attempt: running tasks counted per group, queued ones sorted by creation order per group and per group+pipeline, so "how many are ahead of me" is a binary search. the limit is still checked before looking for a worker, so blocked tasks never loop over all agents and it stays fast with many agents too. result stays the same as before.

BenchmarkAssignToWorker before after
unmatched 1k 5.2ms 387µs
unmatched 10k 1015ms 4.3ms
reserved 1k 5.2ms 376µs
reserved 10k 978ms 4.2ms
1000 agents, 10k tasks 1045ms 4.5ms

tradeoff: once a task with a limit is checked, the index gets built (~20k allocs at 10k tasks per call), still way cheaper than holding the lock for a second.

Both shapes hit the same worst case: the whole backlog is blocked, so assignToWorker checks every pending task and returns nothing. The only difference is why each task is skipped.

unmatched: the worker's filter rejects every task
reserved: the worker accepts every task, but the slot is taken

@6543 6543 added server enhancement improve existing features skip-changelog labels Oct 16, 2026
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.64%. Comparing base (5161bd5) to head (3ed8004).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7322      +/-   ##
==========================================
+ Coverage   66.61%   66.64%   +0.02%     
==========================================
  Files         449      449              
  Lines       22516    22524       +8     
==========================================
+ Hits        14999    15011      +12     
+ Misses       7517     7513       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread server/queue/fifo_blackbox_test.go Resolved
@6543 6543 added optimization improving runtime, memory, CPU, or I/O efficiency and removed skip-changelog labels Oct 27, 2026
@6543 6543 changed the title Queue scheduling causes less GC Check workers before concurrency limits when assigning tasks Nov 11, 2026
With the index the limit check is a binary search, while looking for a
worker loops over all idle agents. Checking workers first made every
blocked task pay tasks x agents filter calls: 110 ms per pass for 10k
tasks and 1000 agents, and with 1000 tasks and 1000 agents it was twice
as slow as before the index.

Check the limit first again, as before the index. Blocked tasks then
never reach the worker loop, so a pass stays at about 4 ms for 10k
tasks no matter how many agents are idle. Tasks without a limit still
skip the index.
@6543 6543 changed the title Check workers before concurrency limits when assigning tasks Index concurrency limit checks when assigning tasks Nov 11, 2026
@6543

6543 commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

close in fafour of #7425

Scenario main #7322 #7425
blocked, unmatched, 10k 993 ms 5.2 ms 3.9 ms
blocked, reserved, 10k 1021 ms 5.0 ms 4.1 ms
hands out 10 (limit 10), 10k 3.1 ms 33 ms 3.9 ms
hands out 100 (limit 100), 10k 21.7 ms 285 ms 3.6 ms
allocations, 100 handed out, 10k 112 2,020,794 203

@6543 6543 closed this Nov 11, 2026
@6543
6543 deleted the less-gc-queue branch November 11, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement improve existing features optimization improving runtime, memory, CPU, or I/O efficiency server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants