Skip to content

Remove forced PK_NewTasks index hint in _LockNextTask; add covering index for lock-next scan#313

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-high-cpu-issue-locknexttask
Draft

Remove forced PK_NewTasks index hint in _LockNextTask; add covering index for lock-next scan#313
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-high-cpu-issue-locknexttask

Conversation

Copy link
Copy Markdown

Copilot AI commented May 8, 2026

_LockNextTask hard-coded WITH (INDEX (PK_NewTasks)) forcing a clustered index scan for every dequeue. With a backlog of locked/invisible tasks this scans large numbers of ineligible rows on every poll — under high concurrency (N workers × M cores × ~20 polls/sec) this produces severe CPU amplification on Azure SQL.

Changes

  • logic.sql — Remove WITH (INDEX (PK_NewTasks)) from the UPDATE TOP (1) in _LockNextTask, allowing the optimizer to choose the plan freely (consistent with _LockNextOrchestration, which has no forced hint):

    -- Before
    FROM NewTasks WITH (INDEX (PK_NewTasks))
    
    -- After
    FROM NewTasks
  • schema-1.7.0.sql (new) — Add a covering index over the exact WHERE predicates used by _LockNextTask, giving the optimizer an efficient seek path to unlocked, visible tasks:

    CREATE NONCLUSTERED INDEX IX_NewTasks_LockNext
    ON NewTasks (TaskHub, LockExpiration, VisibleTime)
    INCLUDE (SequenceNumber, LockedBy, DequeueCount)
  • common.props — Version bump 1.6.0 → 1.7.0 to trigger schema migration on upgrade and apply the new index to existing deployments.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.nuget.org
    • Triggering command: /usr/bin/dotnet dotnet build src/DurableTask.SqlServer/DurableTask.SqlServer.csproj (dns block)
    • Triggering command: /usr/bin/dotnet dotnet build src/DurableTask.SqlServer/DurableTask.SqlServer.csproj --no-restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix high CPU consumption in _LockNextTask due to forced index hint Remove forced PK_NewTasks index hint in _LockNextTask; add covering index for lock-next scan May 8, 2026
Copilot AI requested a review from berndverst May 8, 2026 03:58
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.

Forced PK_NewTasks index hint in _LockNextTask causes high CPU under concurrency

2 participants