<!-- Add the related story/sub-task/bug number, like Resolves#123, or
remove if NA -->
**Related issue:** Resolves#45635
Moved profile reconciler work from SQL to code, similar to what Apple
MDM team did last sprint.
The Windows MDM loadtest for 40 profiles with 30K hosts looks much
better.
```
┌──────────────────────────┬─────────────────────────────────────────┬───────────────────────────────────────────┐
│ │ Pre-fix baseline │ This branch │
├──────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────────┤
│ Transfer wall time │ ~40–42 min │ ~15.5 min │
├──────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────────┤
│ Per work tick │ 215–257s (host-finding query dominated) │ ~48s (host-finding gone; now bulk writes) │
├──────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────────┤
│ Ticks > 30s (work ticks) │ ~all │ ~all (16/17, ~48s) │
├──────────────────────────┼─────────────────────────────────────────┼───────────────────────────────────────────┤
│ Pacing governor │ the host-finding query │ the 2000-host delivery cap + 30s interval │
└──────────────────────────┴─────────────────────────────────────────┴───────────────────────────────────────────┘
```
The writer spikes briefly to 16 AAS, but has CPU headroom, so I'd say we
can claim to support 40 profies on 30K hosts.
```
┌───────────────┬───────────────┬───────────────────────────┬───────────────────────────────────────┐
│ Instance │ CPU avg / max │ DBLoad avg / max (4 vCPU) │ Read / Write / Commit latency │
├───────────────┼───────────────┼───────────────────────────┼───────────────────────────────────────┤
│ writer -two │ 67.9% / 74.9% │ 4.84 / 16.0 │ 0.28ms / 2.07ms / 10.6ms (max 12.2ms) │
├───────────────┼───────────────┼───────────────────────────┼───────────────────────────────────────┤
│ reader -one │ 46.1% / 52.7% │ 1.19 / 5.0 │ 1.59ms / — / — │
├───────────────┼───────────────┼───────────────────────────┼───────────────────────────────────────┤
│ reader -three │ 65.4% / 70.1% │ 1.77 / 5.0 │ 1.72ms / — / — │
└───────────────┴───────────────┴───────────────────────────┴───────────────────────────────────────┘
```
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.
## Testing
- [x] Added/updated automated tests
- [x] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)
- [x] QA'd all new/changed functionality manually
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Refactor**
* Reworked Windows MDM reconciliation to a snapshot-based, batched
drain-loop, improving responsiveness and reducing database load during
large profile operations.
* **Performance / Reliability**
* Windows MDM profile changes now reach hosts faster; large team-wide
profile additions/removals (including host transfers) complete more
quickly with lower DB impact.
* **Chore / Configuration**
* Added tunables to control per-tick delivery caps and scan budgets.
* **Tests**
* Expanded end-to-end and property tests for install/remove, team/label
gating, and multi-window drain behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->