Skip to content

Consolidate per-profile INSERT operations in ReconcileWindowsProfiles #44804

@ksykulev

Description

@ksykulev

Problem

In ReconcileWindowsProfiles at https://github.com/fleetdm/fleet/blob/main/server/service/microsoft_mdm.go#L3046, the install loop iterates per profile:

for profUUID, target := range installTargets {
    ds.MDMWindowsInsertCommandAndUpsertHostProfilesForHosts(ctx, target.hostUUIDs, command, payloads)
}

With 30 profiles, this is 30 separate calls each doing: 1 command INSERT + batched queue INSERT + batched profile upsert. Each call is ~100ms = 2.7s total.

Solution

Consolidate queries.

  1. INSERT INTO windows_mdm_commands — n, where n is number of profiles, rows in one multi-row INSERT (easy)
  2. INSERT INTO windows_mdm_command_queue — n (where n is number of profiles) × 2,000 (reconcileWindowsProfilesBatchSize ) = 54K rows across fewer batched transactions grouped by batch size, not by profile
  3. UPSERT host_mdm_windows_profiles — same 54K rows in unified batches

The number of db trips would Number of DB round-trips reduced from n, where n is number of profiles, to ~3-5 per cron tick

Found as a part of #44656

Metadata

Metadata

Assignees

Type

No type

Projects

Status

🐣 In progress

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions