perf: fast console pages for organizations with many monitors #160

Merged
Sebi merged 3 commits from perf/console-many-monitors into main 2026-11-26 16:47:32 +00:00
Owner

Console pages (monitors, incidents, monitor details, status page editor) became slow for organizations with many monitors.

Cause

Every page showing monitor status ran one loader that read, for all monitors of the organization:

  • the newest result per monitor and region, by scanning a day of raw results,
  • the bars of the selected range, from raw results up to 24h, although only one page of monitors is shown,
  • when each monitor first reported, scanning two days of raw results.

In addition, monitor, region and incident queries relied on row security alone, which keeps Postgres from using an index: they filtered the whole table across all organizations.

Changes

  • latest_results (migration 00055): the newest result per monitor and region, upserted with every stored result. A late result does not replace a newer one. The migration fills the table from the last day.
  • Bars are loaded only for the monitors a page shows. Search and filter load them only for the hits.
  • First data is loaded per monitor on its page. The monitor list asks only for the organization's earliest data, through an index lookup per monitor.
  • ListMonitors, AllMonitorRegions, OpenIncidents and IncidentsSince name the organization. New indexes monitor_regions (org_id) and incidents (org_id) WHERE open.
  • Public status pages read the latest results and hourly buckets of their own monitors only.
  • Status page editor: only monitors on the page carry a group select and label field. Others get them from a <template> when ticked. A filter field appears above 15 monitors, and "Add all" ticks only visible monitors.

Measured (test DB, 3000 monitors, 2 h of results each)

Page before after
Monitors / ~900 ms ~240 ms
Incidents ~1000 ms ~270 ms
Monitor detail — ~160 ms
Status page editor HTML 2.2 MB 1.0 MB (50 on page)

In production the gain is larger: the old queries grew with the number of results (1440 per monitor and region per day at a 1-minute interval). The seed had only 120.

Public status pages

Status page servers fetch snapshots with a 15 s timeout. For large organizations the build took longer (prod logs: /agent/v1/pages 500 after 15 s, context canceled), so pages such as /hetzner kept serving an old copy with the "live updates unavailable" notice. The build spent its time on the same full-day scan of raw results for every monitor of the organization.

  • The snapshot reads latest_results of its own monitors (see above) and incidents by organization, which uses incidents_org_idx.
  • Status page servers asking for the same page at once share one build, which does not end when one of them gives up.

Measured on the test DB (1000 monitors, a page with 200 and component details, 90 days of history): ~2.4 s → ~0.23 s per snapshot. The old time grew with the results per day. The new time does not depend on them.

Tests

  • TestLatestResultsKeepTheNewest: batch, late result, newer result, API and page.
  • The page editor test checks that only the template and included monitors carry fields.
  • regionwatch_test also seeds latest_results, as ingest does.
  • Editor JS checked in headless Chromium: ticking adds fields once, the filter hides rows, "Add all" acts on visible rows only.
  • go test -p 1 ./... green, golangci-lint v2.15.0: 0 issues. Migration and live ingest checked on the dev stack.

🤖 Generated with Claude Code

https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3

Console pages (monitors, incidents, monitor details, status page editor) became slow for organizations with many monitors. ## Cause Every page showing monitor status ran one loader that read, for **all** monitors of the organization: - the newest result per monitor and region, by scanning a day of raw results, - the bars of the selected range, from raw results up to 24h, although only one page of monitors is shown, - when each monitor first reported, scanning two days of raw results. In addition, monitor, region and incident queries relied on row security alone, which keeps Postgres from using an index: they filtered the whole table across all organizations. ## Changes - **`latest_results`** (migration 00055): the newest result per monitor and region, upserted with every stored result. A late result does not replace a newer one. The migration fills the table from the last day. - Bars are loaded only for the monitors a page shows. Search and filter load them only for the hits. - First data is loaded per monitor on its page. The monitor list asks only for the organization's earliest data, through an index lookup per monitor. - `ListMonitors`, `AllMonitorRegions`, `OpenIncidents` and `IncidentsSince` name the organization. New indexes `monitor_regions (org_id)` and `incidents (org_id) WHERE open`. - Public status pages read the latest results and hourly buckets of their own monitors only. - Status page editor: only monitors on the page carry a group select and label field. Others get them from a `<template>` when ticked. A filter field appears above 15 monitors, and "Add all" ticks only visible monitors. ## Measured (test DB, 3000 monitors, 2 h of results each) | Page | before | after | |---|---|---| | Monitors `/` | ~900 ms | ~240 ms | | Incidents | ~1000 ms | ~270 ms | | Monitor detail | — | ~160 ms | | Status page editor HTML | 2.2 MB | 1.0 MB (50 on page) | In production the gain is larger: the old queries grew with the number of results (1440 per monitor and region per day at a 1-minute interval). The seed had only 120. ## Public status pages Status page servers fetch snapshots with a 15 s timeout. For large organizations the build took longer (prod logs: `/agent/v1/pages` 500 after 15 s, `context canceled`), so pages such as `/hetzner` kept serving an old copy with the "live updates unavailable" notice. The build spent its time on the same full-day scan of raw results for every monitor of the organization. - The snapshot reads `latest_results` of its own monitors (see above) and incidents by organization, which uses `incidents_org_idx`. - Status page servers asking for the same page at once share one build, which does not end when one of them gives up. Measured on the test DB (1000 monitors, a page with 200 and component details, 90 days of history): **~2.4 s → ~0.23 s** per snapshot. The old time grew with the results per day. The new time does not depend on them. ## Tests - `TestLatestResultsKeepTheNewest`: batch, late result, newer result, API and page. - The page editor test checks that only the template and included monitors carry fields. - `regionwatch_test` also seeds `latest_results`, as ingest does. - Editor JS checked in headless Chromium: ticking adds fields once, the filter hides rows, "Add all" acts on visible rows only. - `go test -p 1 ./...` green, golangci-lint v2.15.0: 0 issues. Migration and live ingest checked on the dev stack. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added 2 commits 2026-11-26 07:01:15 +00:00
The editor rendered a group select and label field for every monitor of
the organization, about 2 MB of HTML for 3000 monitors. Only monitors on
the page carry their fields now; others get them from a template when
ticked. A filter field narrows long lists, and "Add all" ticks only the
monitors it leaves visible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
perf: load console pages in time for organizations with many monitors
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 11m10s
ci / test (pull_request) Successful in 12m19s
ci / build (pull_request) Successful in 18m13s
ci / image (pull_request) Successful in 5m20s
1138d555aa
Every console page that shows monitor status (monitors, incidents,
monitor details, evidence) went through one loader that read, for all of
the organization's monitors:

- the newest result per monitor and region, by scanning a day of raw
  results;
- the bars of the selected range, from raw results for ranges up to 24h,
  though only one page of monitors is shown;
- when each monitor first reported, scanning two days of results.

With 3000 monitors that took about a second, growing with the number of
results. Now:

- latest_results keeps the newest result per monitor and region,
  updated as results are stored (migration 00055 fills it from the last
  day);
- bars are loaded only for the monitors a page shows;
- first data is loaded per monitor on its page, and the monitor list asks
  only for the organization's earliest data, by index;
- monitor, region and incident queries name the organization, so their
  indexes are used instead of row security filtering whole tables.

Public status pages also read only their own monitors' latest results
and hourly buckets instead of the whole organization's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi added 1 commit 2026-11-26 16:04:25 +00:00
perf(statuspages): build page snapshots in time for large organizations
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m29s
ci / test (pull_request) Successful in 12m37s
ci / build (pull_request) Successful in 18m14s
ci / image (pull_request) Successful in 5m39s
27338f0557
The snapshot read the incidents of a page without the organization, which
row level security keeps from using an index, and every status page
server asking for a page built it on its own. Snapshots now filter by the
organization and servers asking at the same time share one build, which
does not end when one of them gives up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
Sebi merged commit 26e7275dd3 into main 2026-11-26 16:47:32 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ZB-Server/uptimesebi#160