Skip to content

perf(cubejs): scheduler reads model code once per version, not every interval - #95

Merged
acmeguy merged 1 commit into
mainfrom
perf/scheduler-slim-datasources
Oct 12, 2026
Merged

acmeguy merged 1 commit into
mainfrom
perf/scheduler-slim-datasources

Conversation

@acmeguy

@acmeguy acmeguy commented Oct 12, 2026

Copy link
Copy Markdown

Why

Every refresh-scheduler interval (≈1/min) fetched the full source of every active model for all 75 datasources: 5.1 MB from Hasura, then YAML-parsed on the worker's main thread. It did this only to re-check the legacy FILTER_PARAMS-partition quarantine. Versions are immutable, so that verdict never changes for a given version.

This large per-minute response is also the one that has been cut off in transit (2026-10-08, and again on 2026-10-12 at 18:17). #93 turned that from a multi-day hang into a single failed interval; this change shrinks the response itself.

What

  • getDataSources (scheduler-only) carries model ids only.
  • New getVersionModelCode(versionId) reads one version's model code.
  • scheduledRefreshContexts caches the unsafe-model count per active version id and reads code only for versions it hasn't seen. Inactive versions are evicted each interval.
  • buildScheduledRefreshContexts takes an injectable unsafeSchemaCount. It defaults to the old code-based check, so existing callers and tests are unchanged.

Verified against dev Hasura (read-only)

before after
per-interval query 5.14 MB 0.06 MB
model code reads 5.1 MB every interval once per new version (5.1 MB total at startup, max 702 KB per request)
quarantine verdicts 2 datasources / 4 models 2 / 4, identical
model ids (drive schemaVersion / cache isolation) identical for every datasource

Test

scheduledRefreshQuarantineCache.test.js checks three things: two intervals read each version's code once; a newly published version is read and its datasource un-quarantined; quarantined datasources stay excluded. The existing scheduler tests pass. Cubejs suite: 703/705; the 2 failures are the existing runtimeDependencyHardening local-install checks.

🤖 Generated with Claude Code

…interval

Every refresh interval fetched the full source of every active model for all
75 datasources (5.1 MB from Hasura, then YAML-parsed on the main thread) only
to re-check the legacy FILTER_PARAMS-partition quarantine. Versions are
immutable, so that verdict never changes for a version.

The interval query now carries model ids only (0.06 MB on dev). Model code is
read once per newly active version (largest 702 KB) and the verdict cached;
versions that are no longer active are dropped from the cache. The smaller
per-interval response also shrinks the window for the in-transit cut-offs
seen between Hasura and the worker.

Verified against dev Hasura: identical quarantine verdicts (2 datasources /
4 models) and identical model ids for every datasource.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@acmeguy
acmeguy merged commit 1841b7d into main Oct 12, 2026
3 checks passed
@acmeguy
acmeguy deleted the perf/scheduler-slim-datasources branch October 12, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant