Skip to content

Automatic reduction as an application #151

Open

Description

@SimonHeybrock

Automatic reduction is one application: a process that reduces the rows of a batch as their files arrive, around the clock, with or without a page open.

The reduction exists (#196, #201, #236). It is Follow on a batch (ess.apps.batch.Batch) made from a row source. Intake.step is one step on the batch that follows (#261). Two processes run it on a timer: the page's server, under the lock of its pages (Pages.tick), and the command essapps-batch follow -l LABEL, with no page (#265).

done = intake.step()    # a Step, None if no batch follows
done.refused            # why a row could not be submitted, by key
done.waiting            # the keys of the rows of the source that are not filled yet
done.records            # the records of the rows reduced, by key

An application registers its row sources (Intake(manager, sources=...)): functions from the files to rows. A step adds the rows of a source that the batch has not considered and that are filled, and reduces the rows that are ready and have no result. It never changes a row that the table has. The design is in docs/developer/automatic-reduction.md and ADR 0013, the processes in docs/developer/deployments.md. This issue tracks what is missing between that and an application.

Decided

  • The first release needs no connect() over HTTP. One process holds the workspace, the loop, and the page. Users find its results through SciCat, not by connecting to its workspace (Simon, 2026-11-05).
  • One automatic reduction per instrument, with one workspace per proposal. For a first release it may run as an application that a person starts on a VISA machine (Simon, 2026-11-13).
  • A restart needs nothing on disk but the workspace's folder: the records under the batch's label, and definitions/ (the header, settings, rows, source and considered keys, the batch that follows, and the corrections of runs).
  • The page is the batch's page, not a second one. A batch that a person works on and a batch that follows differ in which rows run (Simon, 2026-11-17).
  • A change of settings applies to the rows not reduced yet. A row reduced before reads earlier, and a person reduces it again, after a question that names how many rows (Simon, 2026-11-17).
  • The page shows a part of the table (counts per status, the newest rows, filters for failed and waiting rows), not all rows at once. A person's batch needs this too (Simon, 2026-11-17). Not built (Batch page: the cost of a batch without an end, and showing only its newest rows #223).
  • The settings of a batch are a template in definitions/labels/<label>/settings.json. A hosted service will have to keep them itself, so nothing may depend on the file being the only place (Simon, 2026-11-17).
  • A batch follows from its making (intake.create(follow=True)) or later (intake.follow(label), A batch that stopped following can follow again #263), also after it stopped. It ends with intake.stop(), the removal of the batch, or another batch that starts to follow. Whether a batch follows is kept with the batch (source.json, The batch manager knows no row source; Intake brings rows into a batch #261), so a restart resumes it (ADR 0013). The page offers only "Stop following"; the command has follow and stop.

Missing

The process.

  • A process with no page exists: essapps-batch -w FOLDER -b pkg:BINDINGS -s pkg:SOURCES follow -l LABEL steps the batch until a signal, and the next follow goes on (Batch command: take rows, follow, stop and remove #265). Missing: a command that serves the page with a batch that follows from the start (python -m ess.instruments.loki.web FOLDER serves the page and the timer and starts no batch that follows; ess.instruments.loki.arrivals --follow and ess.instruments.loki.web.build(follow=True) do), and a way for an application to name its bindings and row sources other than -b/-s module:NAME.
  • A step that raises is shown on the page of the batch that follows (Pages.failure), and essapps-batch follow says it on stderr (with --json, as the key error of a line on stdout); the next step tries again. The page's server logs nothing, so with only a page server running and no page open nobody sees it.
  • essapps-batch follow handles SIGINT, SIGTERM and SIGHUP: it ends its steps, waits for the reductions that run and exits, so docker stop or systemd end it without a failed record if the reductions end within their grace period. A second signal, or a kill, fails the records that were running at the next start ("the workspace ended while it ran"), and Follow leaves those rows to a person (A transient failure makes Follow skip a row for good #68). The page's server handles no signal.
  • Proposals: which proposals the service follows, and when it opens and closes their workspaces.

The page. Remaining, in order of effect:

  1. Each poll after a change sends the whole state: 4.6 MB (0.42 MB gzipped) at 10,000 rows, and a poll that sees a finished record takes 1.3 s under the lock. Decided: no protocol of changed rows; the page is built around a range of rows (Simon, 2026-11-17).
  2. That range of rows, served by the server: the questions and measurements are in Batch page: the cost of a batch without an end, and showing only its newest rows #223.
  3. The primary button is disabled while any row runs.
  4. A step holds the lock of the pages, so the page waits while it runs: 0.98 s for an idle step with the page's refresh (step, relist, runs) at 10,000 rows, which is 20,000 files. The step could read the files outside the lock and apply the result under it.

Cost. A step is one listing of all files, one run of the source over them, and one state of the rows without a result, linear in the number of rows: 0.41 s at 10,000 rows with nothing new (automatic-reduction.md, "Cost", has 2.8 s at 100,000). The interval between steps sets the load. What would make it cost less is listed under "Open" in automatic-reduction.md: a file source that reports what is new since a position, and a source that says which files belong together.

Around it.

  • Which file is a sample run. A row source decides by metadata that no file is known to carry; this is the Open question in the requirements (data). Until then a source assumes a rule, and a person corrects a file's metadata.
  • The folder source: follow sees a run once files.csv lists it, so something must run essapps-batch files ... -o files.csv again as runs arrive; nothing does that on a timer. A step reads files.csv again whenever it changed, and a table that changes faster than a step reads it stalls the steps (seen at an arrival every 0.25 s on 3,000 rows); one snapshot of the files per step would cure it.
  • When a file is ready. A file source should list a file only when it is finished. Today the folder source lists a file as soon as files.csv has it, and a file read too early fails; Follow does not run a failed row again (A transient failure makes Follow skip a row for good #68). Read from the sources of the file writer (kafka-to-nexus) and of scicat-ingestor on 2026-11-17, to be confirmed with the people who run them: the file writer writes under the final name with HDF5 SWMR, so an unfinished file is visible and readable; it reports the end of a job with a wrdn message, which can also report a failure; the example configuration of scicat-ingestor builds the pid from /entry/entry_identifier_uuid in the file. A folder source needs a rule for "finished" (a quiet period, or the end the file records).
  • A failed row is never run again by Follow. A row that failed for a passing reason waits for a person (A transient failure makes Follow skip a row for good #68).
  • Publishing with no page open (Publish outputs to SciCat, and how an output becomes a file #152).
  • Reductions run on one thread of the process by default (Tracking: settle disk formats, deployments, and where reductions run #184, step 2). Whether one process keeps up with an instrument is to be measured on its reductions.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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