Commit 978ae51
Reduce SQL Server queue length monitoring query volume (#5555)
* ✨ Reduce SQL Server queue length monitoring query volume
Replace the per-queue length probe (one IF EXISTS + max-min(RowVersion)
statement per tracked queue, every 200ms) with a single catalog-view query
per catalog that reads approximate row counts from sys.partitions. This reads
no queue table data, takes no locks, and needs only SELECT on the queue tables.
Also make the poll interval configurable via the QueueLengthQueryDelayInterval
connection string part (default 200ms), and add optional adaptive back-off up
to QueueLengthQueryMaxDelayInterval while all monitored queues are empty
(disabled by default; base interval is always used while any queue has work,
preserving the fix for #4556).
* ♻️ Address PR review: Unquoted* naming, primary ctor, concurrent pacing
SqlTable: rename Name/Schema/Catalog to Unquoted* to make the
quoted-vs-unquoted contract explicit (review feedback), and convert to a
primary constructor. The now-dead per-table LengthQuery's duplicated
if/else is collapsed into BuildFullTableName/BuildLengthQuery helpers.
QueueLengthProvider: pace the poll interval concurrently with the query
so the effective cadence is max(interval, queryDuration) instead of
interval + queryDuration. The additive query-time term was what let the
cadence drift past the 1s monitoring bucket and starve buckets of
samples (#4556 false-zero sawtooth). With drift removed, restore sane
defaults — base 1s (matches the finest monitoring bucket) ramping to a
10s idle ceiling — superseding the #4557 200ms oversampling workaround.
Adaptive back-off is now ON by default.
* ♻️ Address review: throttle error loop, immediate back-off snap-back, NOLOCK, validation
- Pace after the query (subtracting iteration time) instead of pre-starting Task.Delay:
a fast persistent failure no longer spins the loop with zero delay, and a back-off
snap-back to base takes effect on the current wait instead of one backed-off wait later.
- Reject non-positive QueueLengthQuery(Max)DelayInterval up front (a negative value
previously threw inside Task.Delay mid-loop; zero meant no pacing).
- Record 0 for a not-found table so a dropped queue no longer pins the cadence at base.
- Statement-scoped WITH (NOLOCK) on the catalog views instead of a connection-scoped
SET TRANSACTION ISOLATION LEVEL that would persist on the pooled connection.
- Guard BuildBulkLengthQuery against an empty table set (would emit invalid `AND ()`).
- Remove now-dead per-table LengthQuery/BuildLengthQuery.
Co-authored-by: Mauro Servienti <mauro.servienti@gmail.com>1 parent c2a00a5 commit 978ae51
5 files changed
Lines changed: 388 additions & 69 deletions
File tree
- src
- ServiceControl.Transports.SqlServer.Tests
- ServiceControl.Transports.SqlServer
Lines changed: 164 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
14 | 48 | | |
15 | 49 | | |
16 | 50 | | |
| |||
30 | 64 | | |
31 | 65 | | |
32 | 66 | | |
| 67 | + | |
| 68 | + | |
33 | 69 | | |
34 | 70 | | |
0 commit comments