Skip to content

gs: bound the load of sheet exports on /gs/db (slow full-scans, process stalls) #4227

Description

@Danswar

Problem

POST /v1/gs/db serves the sheet-export tooling (~100 distinct consumers, identified via the identifier field in the slow-query logs). The syncs run on timed triggers around the clock against PRD, and their query shape makes them far heavier than they need to be:

  • 10,754 queries >3s in the last 7 days (~1,500/day), runtimes up to 12.6s, PRD only.
  • Every observed sync passes updatedSince: 1970-01-01 — the DTO's incremental capability is unused, so each run re-scans from epoch with joins and DESC sorts (maxLine 100–500 + multi-table joins).
  • Requests up to 8 MB response size were observed; one query ran 98s.

Impact

  1. Ingress errors: exports that outlive the origin's patience die mid-flight and surface as 502/EOF at the edge (tracked infra-side in DFXServer/server#744, which asks for this exact follow-up triage).
  2. Process stalls: of 4 clean (non-deploy) container restarts checked, 2 were preceded by a ~5x burst of slow /gs/db queries in the prior 10 minutes (27 resp. 25 vs ~5 baseline). Contributing stressor — not proven sole cause.
  3. Steady DB load on the serving path for reporting reads.

Fix options (not mutually exclusive)

  1. Consumer-side (biggest win, no API change): make the sheet syncs pass a real updatedSince so pulls are incremental. Needs an owner for the sheet scripts + a doc note in the GS module.
  2. Server-side guardrails: limit concurrent /gs/db exports (queue, e.g. 2 in flight), and/or per-identifier rate limit; consider a hard runtime cap with a clear 429/503 so a heavy query fails fast instead of stalling the process.
  3. Structural: serve GS reads from a read replica so reporting load cannot touch the serving path.

Acceptance

  • Slow-query volume (>3s) on /v1/gs/db reduced by an order of magnitude (baseline: ~1,500/day).
  • No /gs/db-attributable ingress EOF/502s in the edge logs (verification via DFXServer/server#744).
  • Container restarts show no correlation with export bursts over a 2-week window.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions