Skip to content

Serialize the jobs of one analysis across analysis_wrappers workers - #897

Open
anchapin wants to merge 1 commit into
developfrom
fix/serialize-batch-run-start
Open

anchapin wants to merge 1 commit into
developfrom
fix/serialize-batch-run-start

Conversation

@anchapin

Copy link
Copy Markdown
Contributor

Problem

Analysis#start enqueues one InitializeAnalysis per job on the analysis_wrappers queue — for an LHS analysis
submitted through openstudio-analysis ServerApi#run, first lhs (creates the data points) and then batch_run
(runs them). With a single analysis_wrappers worker the FIFO queue keeps them in order. With more than one worker
they run concurrently: batch_run can finish its initialization and enqueue RunAnalysis before lhs has created
the data points, and the analysis then completes with every data point left na.

Observed on a k8s deployment with 4 analysis_wrappers workers: InitializeAnalysis for lhs and batch_run of the
same analysis started at the same second; batch_run finished first, and the analysis completed with 2,000 of 2,000
data points never run.

Why more than one worker: under load a single lhs initialization took 8–15 min (vs ~1 min idle), so analysis
starts are serial and become the throughput limit for large sweeps.

Change

  • ResqueJobs::StartOrder.wait — waits until a condition holds, with a timeout; clock and sleep injectable.
  • InitializeAnalysis.perform — for a batch_run* job, waits until every earlier job of the same analysis
    (jobs.where(:index.lt => job.index)) has status completed, then continues as before. After
    ANALYSIS_START_ORDER_TIMEOUT seconds (default 3600) it logs a warning and continues (the old behaviour).
  • No change for single-worker deployments beyond one quick status check per batch_run start.

Tests

  • server/spec/jobs/start_order_spec.rb (plain Ruby, no database): returns at once when done, waits until done,
    gives up after the timeout, applies only to batch_run*. 4 examples, 0 failures locally.
  • Not run locally: the Rails/Mongo integration specs (docker CI) and a multi-worker cluster run. A follow-up
    throughput test with 4 analysis_wrappers workers is planned once an image with this change is deployed.

https://claude.ai/code/session_01UUVWoXiezqFGv1aXdu6DCT

Analysis#start enqueues one InitializeAnalysis per job (e.g. lhs, then batch_run).
With more than one analysis_wrappers worker, batch_run could initialize and enqueue
RunAnalysis before lhs had made the data points, so the analysis completed with
every point never run. A batch_run start now waits until every earlier job of its
analysis is completed (timeout ANALYSIS_START_ORDER_TIMEOUT, default 3600 s, then
it logs and goes on as before). Plain-Ruby spec for the wait.

Claude-Session: https://claude.ai/code/session_01UUVWoXiezqFGv1aXdu6DCT
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