Remove forced PK_NewTasks index hint in _LockNextTask; add covering index for lock-next scan#313
Draft
Remove forced PK_NewTasks index hint in _LockNextTask; add covering index for lock-next scan#313
Conversation
…ing index Agent-Logs-Url: https://github.com/microsoft/durabletask-mssql/sessions/8ca0a940-d65f-45e4-96c8-2f6de7571ad6 Co-authored-by: berndverst <4535280+berndverst@users.noreply.github.com>
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_LockNextTaskhard-codedWITH (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— RemoveWITH (INDEX (PK_NewTasks))from theUPDATE TOP (1)in_LockNextTask, allowing the optimizer to choose the plan freely (consistent with_LockNextOrchestration, which has no forced hint):schema-1.7.0.sql(new) — Add a covering index over the exactWHEREpredicates 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 bump1.6.0 → 1.7.0to 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/usr/bin/dotnet dotnet build src/DurableTask.SqlServer/DurableTask.SqlServer.csproj(dns block)/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: