Skip to content

M9-S1 — Diagnose performance across the engines

Section titled “M9-S1 — Diagnose performance across the engines”
ModuleM9 — Performance and operations
After this session you canGo from a slow screen, a growing queue or a reaction storm to the engine that causes it, and plan capacity for the program.
TimeFacilitated: 63 min · On your own: 63 min
Before you startM3 (the read engines) and M4 (the process engines; reaction runs from M4-S2). Your strand’s capability in Larkspur Lab. The workbench, and the metrics port-forwards from ACDE M5-S1.
Go deeperEngine: query and aggregation, performance · Observability · Deployment capacity

◆ Orientation (1 min) — More pods is an answer, rarely the first

Section titled “◆ Orientation (1 min) — More pods is an answer, rarely the first”

ACDE taught you to find the bottleneck among the workloads and to scale the right one (ACDE M6-S1): more indexing workers when indexing is busy, more data-pod replicas when its CPU is high. That answers “which pod”. A master must answer the question before it: which engine, doing what, because of which design? A slow page caused by a relation filter on 300,000 records gets slower however many pods you add, and a reaction that triggers itself fills any number of workers. You now know every engine from the inside; this session turns that into a diagnosis method, and into a capacity plan for Larkspur that starts from its design and its people.

▤ Concept (9 min) — Symptom, engine, design, decision

Section titled “▤ Concept (9 min) — Symptom, engine, design, decision”

Every performance investigation in this course follows the same four steps, and the order matters:

  1. Symptom. What exactly is slow, for whom, when, and since when? “The portal is slow” is not a symptom; “Operations Command takes eight seconds between 08:00 and 08:15 for everyone” is.
  2. Engine. Which engine does that work? A screen is read-side (M3); a backlog is a queue’s consumer (M2-S2); late or repeated automation is the scheduler or the reaction engine (M4). The engine trace map tells you where each leaves evidence (job aid).
  3. Design. Which configuration makes that engine work hard? A relation filter, an unanchored search, a widget-heavy landing page, a reaction with no narrowing criteria, a calculated field with a relation look-up, a mapped field on a supplier referenced by 80,000 orders.
  4. Decision. Fix the design if a design causes the load; add capacity if the load is legitimate. Write down which, and why, because the next person will be tempted to do the other.

In production you will not switch on a profiler. The platform’s own metrics, scraped by the monitoring you set up in ACDE, are enough to locate the engine and often the design. Besides the request and queue metrics ACDE taught, five families matter here.

MetricLabelsIt tells you
osos_message_duration_seconds, osos_message_processed_totalmessage, space_id, statusHow long each kind of bus message takes to handle, and how many fail
osos_bus_handler_duration_seconds, osos_bus_handler_db_callsmessage, handlerWhich handler of a message is slow, and how many database calls it makes per run; for jobs, message is the queue and handler the job
osos_job_duration_seconds, osos_job_processed_totalqueue, statusBackground jobs (BullMQ) by queue: reindex chunks, bulk updates, exports
osos_aggregation_duration_secondsentity, space_idEvery list read and statistic, by entity: which entity’s reads are expensive
osos_tenant_aggregations_total, osos_tenant_reactions_total, osos_tenant_messages_total, osos_tenant_jobs_totalstatusCoarse per-tenant counts of each kind of work, for trends and capacity

Two habits make them useful. Compare rates, not totals: the reaction count rising from 2 a minute to 400 a minute is the storm. And use the handler level: a slow data-entry-updated message is not a diagnosis, but “the aggregate-refresh handler of data-entry-updated takes 900 ms with 34 database calls per run” is.

What each engine costs: the fan-out arithmetic

Section titled “What each engine costs: the fan-out arithmetic”

Load on a Osos program is not “requests per second”. One action fans out across the engines, and the fan-out is decided by design. Count it for Larkspur’s commonest actions.

One actionWork it causesGrows with
Saving a work order1 HTTP write; 1 record-updated event delivered to every subscribing queue (about eight); its own search text; title-index update; refresh of every aggregate and proxy that uses work orders; every matching reaction’s run (each run’s actions are further writes)The number of consumers, read models and reactions defined on the entity
Renaming a supplierAll of the above for the supplier, plus proxy refreshes in two modules, plus reindex jobs over every record that references it through a searchable fieldHow many records point at it (80,000 purchase orders)
Opening Operations CommandOne aggregation per widget, each through the list-read or statistic pipelineWidgets × people × openings
The nightly planOne scheduled job; it raises N work orders, each a save as aboveN, and what each save fans out to

The arithmetic is simple and powerful: cost = frequency × fan-out × cost per unit. You can lower any of the three. Design changes usually lower the fan-out (fewer widgets on the landing page, a reaction with criteria that match one work order in a hundred instead of all) or the cost per unit (group by a reference instead of through it, M3-S3). Capacity changes lower nothing; they buy room.

The slow screen. Read-side work, paid per opening. Evidence: the per-entity aggregation timing for that entity, and the time of day. Usual designs: relation filters and joins on large entities, unanchored text conditions, counters and charts on a landing page everyone opens at once, a sort on a computed field (M3-S2), statistics without a date window (M3-S3). Capacity helps only when the work is legitimate and spread out.

The growing queue. A consumer cannot keep up. Evidence: one queue’s depth rising while others stay flat (ACDE taught you to read it), then the handler metrics for that consumer. Usual designs: a bulk change whose fan-out is large (a bulk update of 20,000 records reindexes and refreshes everything that uses them), a mapped field or aggregate on a popular record, a slow handler doing many database calls per message. Ask first whether the backlog is a burst that will drain (wait, and schedule bulk changes at night) or a steady rate above capacity (fix the design, then scale the consumer).

The reaction storm. Automation causing automation. Evidence: osos_tenant_reactions_total rate jumping; one reaction’s run count in Administration › Monitoring › Reaction Logs far above its usual; the reaction service’s queue deep. Usual designs: a reaction on “record updated” with no criteria that itself updates the record (the loop guard you configured in ACE stops it, but only after the threshold you set), two reactions that update each other’s records, a scheduled job that touches every record and so triggers every reaction on them. The decision is always a design fix; capacity only makes a storm larger. Remember from M4-S2 that runs are durable sagas: a storm already queued runs to completion unless you disable the reaction.

A capacity plan answers: with the people and the design we expect next year, which engine reaches its limit first, and what will we do? Build it from the fan-out table, not from a guess at “users”:

  1. List the program’s top actions with their daily frequency, from today’s metrics (writes per entity, page openings, scheduled runs) and from the program’s plans (Field Service adds 200 visits a day).
  2. Multiply by the fan-out of each action, per engine: HTTP writes, aggregations, messages per queue, reaction runs, reindex work.
  3. Find each engine’s busiest hour, not its daily average: 08:00 for aggregations, the month-end close for procurement writes, 06:00 for the daily maintenance plan run.
  4. Compare with what the engine handles today at acceptable latency (measured, from the metrics), and name the first one to run out.
  5. For that engine, choose: a design change that lowers the fan-out, or the capacity change ACDE taught (replicas, a pod of its own, the backing store’s capacity), and the date by which it is needed.

In a multi-tenant deployment the operator also sets a capacity ceiling for the cell and an entity limit; those are the operator’s decisions, and your plan is the evidence they need.

▶ Guided demo (10 min) — From a metric to a handler

Section titled “▶ Guided demo (10 min) — From a metric to a handler”

In Larkspur Lab. The demo starts the queue symptom and follows it from the queue to the handler.

  1. Start the bulk-update symptom from the course pack: it sets the Description of 5,000 work orders through the API, as a badly scheduled integration would. node larkspur-pack/symptoms/run.mjs --base-url $BASE --symptom bulk-update

  2. Watch the queues every few seconds: kubectl -n datastores exec deploy/rabbitmq -- rabbitmqctl list_queues -p lk name messages consumers | sort -k2 -n | tail -5. The data service’s and the indexing service’s queues grow; the others stay near zero.

  3. Read the data pod’s handler metrics (port-forward as in ACDE M5-S1, then): curl -s localhost:9900/metrics | grep osos_bus_handler_duration_seconds_sum | sort -t' ' -k2 -g | tail -5. The handler with the largest total time names itself: the refresh of the Site Workload aggregate on data-entry-updated. Note its handler name.

  4. Read its database calls per run: curl -s localhost:9900/metrics | grep 'osos_bus_handler_db_calls_bucket' | grep <handler>.

  5. Find that aggregate’s definition in the portal (Asset Maintenance › Site Workload) and its mapping: an Expression mapping with a resolveValue across two relations, for every work order.

  6. Decide aloud: the queue will drain (it is a burst), but every future bulk update will do the same; the design fix is to map the site as a copied field, not an expression with two look-ups.

    Screenshot pending Terminal output listing the RabbitMQ queues of the lk virtual host, with the data service's and indexing service's queues holding thousands of messages and the others near zero What to notice: only two queues grow. The bus is fine; two consumers are slow, and the metrics say which handler in each.

PracticeChoose one answer.

Operations Command is slow between 08:00 and 08:15 only, for everyone, while the queues stay flat. Which engine do you investigate first?

  1. Explanation for A

    ✗ Incorrect

    Not this one: flat queues and a time-of-day pattern on one page point at reads, not automation. See Three classic patterns.

  2. Explanation for B

    ✓ Correct

    Correct: a landing page’s cost is widgets × people × openings, concentrated at arrival time. See What each engine costs.

  3. Explanation for C

    ✗ Incorrect

    Not this one: a scheduled job would show as queue or job activity, not as slow page reads. See Three classic patterns.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

Which observation tells you which part of the data service makes data-entry-updated slow?

  1. Explanation for A

    ✗ Incorrect

    Not this one: depth says the consumer is behind, not which handler is slow. See Reading the engines from their metrics.

  2. Explanation for B

    ✗ Incorrect

    Not this one: it times the whole message, across every handler it runs. See Reading the engines from their metrics.

  3. Explanation for C

    ✓ Correct

    Correct: the handler-level series name the slow handler and its database calls per run. See Reading the engines from their metrics.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

PracticeChoose one answer.

A reaction storm is under way: one reaction’s runs went from 2 to 400 a minute. A colleague proposes doubling the reaction service’s replicas. What do you say?

  1. Explanation for A

    ✓ Correct

    Correct: a storm is automation causing automation; the fix is the trigger and its criteria. See Three classic patterns.

  2. Explanation for B

    ✗ Incorrect

    Not this one: draining faster lets each run cause the next sooner; the storm grows. See Three classic patterns.

  3. Explanation for C

    ✗ Incorrect

    Not this one: even temporarily, more capacity feeds the loop rather than ending it. See Three classic patterns.

Check your answer

The correct answer is A. Open the explanation under each option to see why.

⛏ Lab (30 min) — Three seeded symptoms

Section titled “⛏ Lab (30 min) — Three seeded symptoms”

Goal. Three symptoms diagnosed on Larkspur Lab with the four-step method, each with the engine, the design that causes it, the evidence, and a decision; then a one-page capacity note.

Before you start. Larkspur Lab; the workbench; the metrics port-forwards for the data pod and the indexing service (ACDE M5-S1); the course pack’s symptom script. A file m9-s1-diagnosis.md with the four steps as headings for each symptom. Reset the seed afterwards.

Symptom 1: the slow screen

  1. Start it: node larkspur-pack/symptoms/run.mjs --base-url $BASE --symptom slow-screen. It opens the view Open Work by Site as forty simulated planners over two minutes.
  2. While it runs, read the per-entity aggregation timings from the data pod’s metrics, and the tenant’s aggregation rate.
  3. Open the view’s definition in the portal and its filter. Switch the profiler on for one opening and read the pipeline (M3-S2).
  4. Write the four steps for this symptom.

Symptom 2: the growing queue

  1. Start it: --symptom bulk-update (as in the demo, if you have not already).
  2. Find the two growing queues and, from the handler metrics, the slowest handler in each.
  3. Say whether this is a burst or a steady rate, from the job and message rates over five minutes.
  4. Write the four steps.

Symptom 3: the reaction storm

  1. Start it: --symptom storm. It enables a reaction a careless builder left disabled.
  2. Watch the reaction rate (osos_tenant_reactions_total) and the reaction service’s queue.
  3. Open Administration › Monitoring › Reaction Logs, find the reaction whose runs explode, and open its trigger and actions.
  4. Stop the storm: disable that reaction. Note how long the queued runs take to finish (M4-S2).
  5. Write the four steps.

Capacity note

  1. From the fan-out table, estimate the daily aggregations, reaction runs and data-service messages for Larkspur after the capstone adds Field Service (200 visits a day, each saved four times; 30 dispatchers and technicians opening a page with six widgets five times a day).
  2. Name the engine that reaches its limit first, its busiest hour, and your decision.

Check.

  • Each symptom names the engine, the design, the evidence (a metric or a profiled pipeline) and a decision.
  • Symptom 2 names the slowest handler in each growing queue and calls the backlog a burst or a steady rate, with the rates as evidence.
  • Symptom 3 names the reaction, its trigger and why it triggers itself or another, and the time its queued runs took after you disabled it.
  • No decision is “add capacity” without a design reason.
  • The capacity note shows its arithmetic and names one engine and one hour.

Pass condition. All five checks hold.

If something goes wrong

What you seeWhat to do
The symptom script is refused with 401Set TOKEN to the workbench token; the script uses it, and LK_ADMIN_* for symptom 3’s change.
/metrics shows no osos_bus_handler_… seriesYou may be reading the wrong port: the data service’s handler metrics are on the combined pod’s admin port; the indexing service’s on 9100.
The storm does not startThe loop guard you configured in ACE may stop it at once in your lab; the script prints the reaction’s name, so read its run count instead.
The lab becomes slow for everythingThat is the symptom; if it persists after you stop the scripts, reset the seed and restart the data pod with kubectl -n larkspur rollout restart deploy/lk-osos-core-data.
Disabling the reaction does not stop the runs at onceExpected: runs already queued are durable and finish (M4-S2). Watch the queue drain.
Model answer

Symptom 1. Symptom: Open Work by Site takes seconds per opening under forty planners. Engine: the read side, list-read pipeline. Design: the view filters on value.asset.:relation.value.site with no narrowing condition, so every work order is joined to its asset, and it sorts on a computed field, which defers the sort until after the join. Evidence: the per-entity aggregation timing for work_orders rising with the load; the profiled pipeline with a $lookup before the main match and a late $sort. Decision: design fix: copy the site onto work orders as a mapped field (From Parent Only) and filter and sort on it; capacity would only add room for the same waste.

Symptom 2. Two queues grow: the data service’s and the indexing service’s. Slowest handlers: the aggregate refresh for Site Workload (an expression mapping with two look-ups, many database calls per run) in the data service, and the search-text recompute in indexing. Burst: the message rate falls to normal when the 5,000 updates end, and both queues drain in minutes. Decision: schedule bulk updates at night (governance), and change the aggregate’s mapping to a copied field (design); no scaling.

Symptom 3. The reaction Recalculate work order priority triggers on On Entry Updated of work orders with no criteria and updates the same work order’s Priority, so each run causes the next, until the loop guard’s threshold. Evidence: the reaction rate jumped to hundreds a minute; Reaction Logs shows that reaction’s runs exploding. After disabling it, queued runs finished over a minute or two. Decision: add criteria (only when Asset or Planned Date changed) and watch only those fields, so its own write does not trigger it; never scale for a storm.

Capacity note (illustrative arithmetic). Field Service writes: 200 × 4 = 800 saves a day, each about eight deliveries: 6,400 data-service-side messages, plus reactions on visits (say two per save: 1,600 runs). Pages: 30 × 6 widgets × 5 = 900 aggregations a day, but 180 of them between 08:00 and 08:15. The first limit is the read side at 08:00 (it already peaks with Operations Command); decision: a lean landing page for Field Service (two counters, one list), detail on drill-down pages; review the data pod’s replicas only if the 08:00 peak still exceeds today’s measured comfortable rate.

◇ Worked scenario (3 min) — Month-end close

Section titled “◇ Worked scenario (3 min) — Month-end close”

On the last working day of each month, Procurement closes the month: buyers approve a backlog of about 1,500 purchase requests in two hours, and finance runs Spend by Supplier repeatedly. Last month the portal was slow all afternoon and approval notifications arrived an hour late. Leila Amari asks whether Larkspur “needs a bigger server”. Follow the method.

Symptom. Slow pages for everyone between 14:00 and 17:00 on close day; notifications an hour late; normal the next morning.

Engine. Two engines at once. The late notifications point at the bus: approvals are workflow moves (M4-S3), each publishing several events that reactions, notifications, the timeline and the request mirror consume. Slow pages point at reads. The metrics confirm both: the workflow and reaction queues deep from 14:00, and the purchase-order aggregation timings ten times their usual.

Design. The approvals are legitimate work: 1,500 approvals × about six messages each, plus a reaction per approval that recalculates the supplier’s open commitments by reading all that supplier’s purchase orders. That reaction is the expensive part: a read of hundreds of orders per approval, 1,500 times. And Spend by Supplier without a date window (M3-S3) was being refreshed by finance every few minutes over five years of orders.

Decision. Two design fixes and no new hardware: the commitments reaction becomes a nightly scheduled recalculation per supplier (M4-S1), which close day does not need in real time; Spend by Supplier gets the twelve-month window it should always have had. Then you measure the next close. Only if the approvals themselves still back up the queues do you plan more consumers for the workflow and reaction applications, the capacity ACDE taught you to add, now justified by a measured legitimate peak.

What you tell Leila. “Not a bigger server yet. Two of our own designs made close day five times more expensive than it needs to be. We fix them this month and measure the next close; if it is still slow, we will know exactly which part needs capacity and how much.”

✓ Practice (5 min) — Decide like a master

Section titled “✓ Practice (5 min) — Decide like a master”
PracticeChoose one answer.

After a bulk import of 20,000 work orders, the indexing queue holds 18,000 messages, falls steadily, and nothing else is affected. Indexing CPU is high. What do you do?

  1. Explanation for A

    ✗ Incorrect

    Not this one: sizing for a one-off burst buys capacity that idles the rest of the time. See From diagnosis to a capacity plan.

  2. Explanation for B

    ✓ Correct

    Correct: a falling backlog after a one-off bulk change is legitimate work catching up. See Three classic patterns.

  3. Explanation for C

    ✗ Incorrect

    Not this one: purging loses the work and leaves search stale; it is on the never-do list. See Three classic patterns.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

PracticeChoose one answer.

Which design change lowers the fan-out of saving a work order, rather than its cost per unit?

  1. Explanation for A

    ✗ Incorrect

    Not this one: that lowers the cost of a read, not the work a save causes. See What each engine costs.

  2. Explanation for B

    ✗ Incorrect

    Not this one: capacity changes neither fan-out nor unit cost; it buys room. See What each engine costs.

  3. Explanation for C

    ✓ Correct

    Correct: fewer matching runs per save means less work fanned out from each save. See What each engine costs.

Check your answer

The correct answer is C. Open the explanation under each option to see why.

PracticeChoose one answer.

A capacity plan uses “average requests per second over the month”. Why is that the wrong number?

  1. Explanation for A

    ✓ Correct

    Correct: plan per engine, from the fan-out, at its busiest hour. See From diagnosis to a capacity plan.

  2. Explanation for B

    ✗ Incorrect

    Not this one: request metrics exist; the problem is the average. See From diagnosis to a capacity plan.

  3. Explanation for C

    ✗ Incorrect

    Not this one: excluding weekends still leaves an average per request, not per engine and peak. See From diagnosis to a capacity plan.

Check your answer

The correct answer is A. Open the explanation under each option to see why.

PracticeChoose one answer.

Your strand’s capability adds a Function call to a reaction on every meter reading, 50 readings a minute per pump. The Function takes 300 ms. Where do you look first when readings start arriving late?

  1. Explanation for A

    ✗ Incorrect

    Not this one: lateness after arrival is about processing, not admission. See The method.

  2. Explanation for B

    ✓ Correct

    Correct: frequency × fan-out × unit cost, here per pump, decides whether the consumer keeps up. See What each engine costs.

  3. Explanation for C

    ✗ Incorrect

    Not this one: reindexing is cheap per reading; the Function call dominates. See What each engine costs.

Check your answer

The correct answer is B. Open the explanation under each option to see why.

↺ Recap (1 min) — Diagnosis before capacity

Section titled “↺ Recap (1 min) — Diagnosis before capacity”

You can now go from a symptom to the engine and the design behind it, read the engine-level metrics that name the slow handler, job or aggregation, count a program’s fan-out per engine, and turn it into a capacity plan that chooses design fixes before capacity.

Next. M9-S2 plans the change that touches every engine at once: upgrading the platform under a program that carries packages, Functions and your extension.