#A long-running service: elucid8 serve
Status: in elucid8 0.3.0 and later: requests, shared caches, time budgets and cancellation (since 0.2.0), and a memory budget for the caches, new data arriving (advance), reload and frames (whole grids as one block, §4) (release notes). From 0.5.0: last in queries (§3) and subscriptions, standing queries answered again when data arrives (§7). From 0.9.0: rows appended to an input by advance, and windows of recent rows (rows, keepFrom, §3). From 0.9.1: subscriptions to an output whose records go to a program (§3), and sources served by programs (command reference). From 0.10.0: programs in the language's notation v0.2, with a timestamp in every answer. From 0.11.0: v0.2 plans of version 7. From 0.12.0: service calls written as equations, with their settings in the configuration (plan version 8). From 0.13.0: aggregates over regions (plan version 9). From 0.15.0: recursive functions, text and exact sums. From 0.16.0: Parquet and Arrow files as data (advance with parquet or arrow, §3), and outputs the program names, which serve sends to a program as an output subscription. Requests over HTTP, from several clients, with a bearer token, health checks, metrics, event streams for subscriptions and answers as Arrow (§8), from 0.18.0. From 0.19.0: plan version 18 (queries written running[t = 4], as in programs), and GET /values, the values of queries the configuration names in Prometheus's format, for Grafana (§8); the eLucid8 Player at GET /player, describe (§3) and read-only player keys (§8). From 0.20.0: plan version 19, with inputs advanced by their channel ({"op": "advance", "input": "x", …}, POST /inputs/x/rows, §3), outputs whose rows grow with the rows that arrive, and outputs written as streams, followed by subscribers. From 0.23.0: an input that follows a file another program appends to ({"builtin": "follow"}, §7). Every command and option of elucid8 is in the command reference; examples of talking to the service from Python and JavaScript are in Using eLucid8 from your code.
elucid8 run evaluates a configuration's queries and exits; its caches last for one run. elucid8 serve keeps a deployment loaded and answers queries as they arrive, each one from what earlier queries computed, while new data arrives. Every answer is exactly what a fresh elucid8 run of the same query, under the same versions of the data, would give: the service changes how fast an answer comes, never what it is.
#1. Starting it
elucid8 serve plan.json --config deploy.json
elucid8 serve plan.json --config deploy.json --cache-bytes 256M
- The same deployment as
run: the plan, and a configuration that says where its inputs come from and its outputs go, and sets its options (the configuration file). The configuration's ownqueriesare read and checked, but not run: the service answers requests instead. --cache-bytessets a memory budget for the caches (§5): a number of bytes, or of KiB, MiB or GiB withK,MorG(256M). It overrides the configuration'scacheBytesoption. Without either, nothing is evicted.- One process, one deployment, one request at a time. Every request,
advanceandreloadincluded, is handled in the order it arrived (§6); onlycancelandshutdownact at once. - Requests are JSON objects, one per line, on standard input. Replies are JSON objects, one per line, on standard output, in the order the requests arrived. Logs go to standard error (§9). With
--http, the same requests also arrive over HTTP (§8). - It ends after a
shutdownrequest, on SIGTERM or SIGINT (Ctrl-C), or when standard input closes; each way it exits with code 0. A configuration or plan that cannot be read stops it at once, with the messagesrungives and exit code 3.
Without --http there is no network socket: whoever starts the process talks to it through its standard input and output (for example a supervisor, or a program in another language that starts it as a child process). With it, other programs reach it over HTTP (§8).
#2. Two sessions
With the guide's program (running.el8, a running sum and a ratio, in the notation v0.2), one line added at its end, ahead = next.t ahead + x (a definition that is not well founded: each point reads the next, without end), the whole compiled to running-plan.json, and its configuration:
elucid8 serve running-plan.json --config running.deploy.json
Requests (standard input):
{"id": 1, "op": "query", "query": "running[t = 4..5]"}
{"id": 2, "op": "query", "query": "ratio[t = 3]", "format": "csv"}
{"id": 3, "op": "check", "query": "running[t = 0..5]"}
{"id": 4, "op": "query", "query": "ahead[t = 5]", "maxDepth": 50}
{"id": 5, "op": "stats"}
{"id": 6, "op": "shutdown"}
Replies (standard output; "report": {…} shortened here):
{"id":1,"status":"done","results":[{"name":"running","context":{"t":4},"outcome":{"kind":"value","value":13,"ts":0}},{"name":"running","context":{"t":5},"outcome":{"kind":"value","value":22,"ts":0}}],"versions":{"x":"d20b5fc4a3d402cb"},"report":{…}}
{"id":2,"status":"done","csv":"name,t,ratio_value,ratio_kind,ratio_message,ratio_ts\nratio,3,,error division,division by zero,0\n","versions":{"x":"d20b5fc4a3d402cb"},"report":{…}}
{"id":3,"status":"done","name":"running","points":6,"versions":{"x":"d20b5fc4a3d402cb"}}
{"id":4,"status":"programError","programError":"demand depth limit (50) exceeded: … -> ahead[t = 52] -> ahead[t = 53] -> ahead[t = 54] -> ahead[t = 55] (a chain of demands that never ends?)","results":[],"versions":{"x":"d20b5fc4a3d402cb"},"report":{…}}
{"id":5,"status":"done","stats":{…}}
{"id":6,"status":"done","now":false}
New data arriving. Here the configuration keeps a point cache within a 1 MiB budget:
{ "format": "elucid8-deploy/2",
"inputs": { "x": { "from": "running-x.csv" } },
"options": { "pointCache": true, "cacheBytes": 1048576 } }
On Tuesday, running-x-tuesday.csv arrives: the same as running-x.csv, except that x at t = 5 is 90 instead of 9. A client can send these requests all at once, without waiting for replies: each is handled in turn (§6), so the replies are the same either way.
{"id": 1, "op": "query", "query": "running[t = 0..5]"}
{"id": 2, "op": "advance", "input": "x", "file": "running-x-tuesday.csv"}
{"id": 3, "op": "query", "query": "running[t = 4..5]"}
{"id": 4, "op": "query", "query": "running[t = 5]", "snapshot": {"x": "d20b5fc4a3d402cb"}}
{"id": 5, "op": "reload"}
{"id": 6, "op": "shutdown"}
{"id":1,"status":"done","results":[{"name":"running","context":{"t":0},"outcome":{"kind":"value","value":3,"ts":0}},{"name":"running","context":{"t":1},"outcome":{"kind":"value","value":4,"ts":0}},{"name":"running","context":{"t":2},"outcome":{"kind":"value","value":8,"ts":0}},{"name":"running","context":{"t":3},"outcome":{"kind":"value","value":8,"ts":0}},{"name":"running","context":{"t":4},"outcome":{"kind":"value","value":13,"ts":0}},{"name":"running","context":{"t":5},"outcome":{"kind":"value","value":22,"ts":0}}],"versions":{"x":"d20b5fc4a3d402cb"},"report":{…}}
{"id":2,"status":"done","input":"x","version":"7270c6cb167f44ec","added":["7270c6cb167f44ec"],"versions":{"x":"7270c6cb167f44ec"}}
{"id":3,"status":"done","results":[{"name":"running","context":{"t":4},"outcome":{"kind":"value","value":13,"ts":0}},{"name":"running","context":{"t":5},"outcome":{"kind":"value","value":103,"ts":0}}],"versions":{"x":"7270c6cb167f44ec"},"report":{…}}
{"id":4,"status":"done","results":[{"name":"running","context":{"t":5},"outcome":{"kind":"value","value":22,"ts":0}}],"versions":{"x":"d20b5fc4a3d402cb"},"report":{…}}
{"id":5,"status":"done","plan":"unchanged","changed":[],"cachesDropped":false,"versions":{"x":"7270c6cb167f44ec"}}
{"id":6,"status":"done","now":false}
- Request 2 reads the new file and makes it the newest version of
x; its id is the hash of the file's bytes. - Request 3 pins it. Only
runningatt = 5read the changed point, so only it is computed again;runningatt = 4comes from the cache (its report: one value computed, one cache hit). - Request 4 names Monday's version: it is still available, since the configuration lists it.
- Request 5 reads the configuration again. Nothing in it changed, so
xkeeps the version that arrived.
#3. Requests
Every request is an object with op, and usually an id (a number or text, echoed in the reply; without one, the reply's id is null). A field a request does not take is an error, so a misspelt option is never silently ignored.
#query
Computes a query and replies with its outcomes.
| field | meaning |
|---|---|
query | the query as text, name[dimension = coordinate, …], as on the command line (queries). A coordinate may be last, the newest data: level[time = last], level[time = last - 9 .. last] (below) |
value and points | instead of query: the value's name and a list of contexts, as in the configuration's queries |
tile | whether to demand the points as one tile: by default true for a query as text (a box), false for value and points. The outcomes are the same either way; a box as one tile computes values that go level by level a level at a time (queries) |
snapshot | versions to pin for this request, by label or version id, over the newest ones (as a configured query's snapshot) |
format | jsonl (the default, or the configuration's output.format when that is a text format), csv, or frame: the whole box as one block (§4). The binary formats of elucid8 run (npz, arrow, parquet) are files, not replies: asking for one is invalid |
budgetMs | a time budget in milliseconds (§5). By default the service's time limit (--time, an hour unless set), and never more than it |
maxDepth, maxAggregate | lower limits for this request. A request may lower the configuration's limits, never raise them: a higher value is invalid |
Versions. A request without a snapshot pins the newest version of every input as of the moment it starts (§6): since requests are handled in the order they arrive, that is the data as of every request sent before it. One request always sees one consistent set of data, however long it runs. The reply's versions names the versions it pinned.
last. In query text, a coordinate (or either end of a range) may be last, last - k or last + k:
| dimension | last is |
|---|---|
| an integer dimension | the highest coordinate on that dimension that any input with the dimension lists, in the versions the query pins |
last is turned into a number when the query starts, so its answer is that of the same query with the number written in, and the reply's results show the coordinates. A query whose last has no value (no input listing a point) is invalid. elucid8 run reads last the same way (queries).
#check
Takes the same fields as query, reads the query and checks that every point projects onto its value (a query that leaves out a dimension of its value is invalid, as in query), without computing anything. Replies with the value's name, the number of points and the versions it would pin.
#advance
Adds a version of an input and makes it the newest:
{"id": 7, "op": "advance", "input": "x", "file": "x-2026-10-06.csv"}
{"id": 10, "op": "advance", "input": "x", "rows": "6,4.5\n7,5.25\n"}
{"id": 11, "op": "advance", "input": "x", "rows": "8,6\n", "keepFrom": {"t": 3}}
| field | meaning |
|---|---|
input | what advances: an input's channel (an input answered on demand has no rows to advance, and is refused) |
file, csv, jsonl, parquet or arrow | the new data: a file, its path relative to the configuration's directory, read with the same rules as the configuration's files (data files). file takes the format from the name's ending (.csv, .jsonl, .parquet, .arrow or .arrows); the others name it |
rows or rowsFile | rows to add at the end of the newest version's file, given as text (rows) or in a file (rowsFile, its path relative to the configuration's directory). They are in that file's format, without a header: CSV rows in its header's columns, or JSON lines. A Parquet or Arrow version takes no rows: advance it with a whole file. The new version is exactly the one advance of the whole file, with the rows added, would give (below) |
keepFrom | with rows or rowsFile: a window, {"tick": 31}, a bound on the input's first dimension (an integer one). The new version keeps only the newest version's points at or above it, plus the rows, which must be at or above it too (below) |
label | optional: a label for the new version, which requests may name in a snapshot (a label moves to the new version if another had it) |
versions, pin | instead of one file: a whole new set of versions, written as a binding writes them (sources). They replace the versions kept available (§6), and the one pin names (else the last) becomes the newest |
The version's id is the hash of the file's bytes, as for the configuration's files, so the same bytes are the same version. A new file whose rows were appended to the old one's is a new version too. A point with no row reads as the input's binding says: missing data, or the value its fill gives. A file that does not fit the program (no column for one of the input's dimensions; for an input with no dimensions, other than one value) is invalid, with the message check gives for it, such as input x (bad.csv): no column t, a dimension of x; its columns are u, value (What a file lacks).
New rows arriving. With rows (or rowsFile), the new version is the newest version's file with the rows added at its end, after a line break if the file does not end with one: the same points, and the same id (the hash of the whole file's bytes), as advance with that whole file would give. The service reads only the rows: it continues the file's hash over their bytes and adds their points to the version's table, so the cost is the rows', not the file's. Rows may list points anywhere in the input (a reading that arrives late fills its gap), but not a point the version already lists, nor one twice: as reading the whole file, that is invalid (to change a point, advance the whole corrected file). Rows without a field for one of the input's dimensions are invalid too, and nothing is appended: advance x: x.jsonl (rows appended): these rows do not fit the program: line 3 has no field t, a dimension of the input; its fields are value. The newest version must have been read from a file. The reply adds rows, the number of points the rows listed. The new version takes the old version's data, which is never copied: if anything still keeps the old version (§6), it goes on reading the same data, as far as the rows it had. (With keepFrom, the old version keeps its data and the new one gets a copy, unless nothing keeps the old one.) Without keepFrom, the input keeps every row it was given, so its memory grows with the rows sent.
A file with no column for its rows (a binding with "row": "i", command reference): rows appended continue the positions, from the file's last row; a whole new file is numbered from 0 again. A value is reused after such an advance only where the new file has the same row at the same position, as for any point.
A window. With keepFrom, the input keeps only recent rows: the new version lists the newest version's points whose first coordinate is at or above the bound, and the rows; points below the bound read as points with no row do (missing data, or the input's fill), exactly as if they had never been listed. A stream that sends each tick's readings with keepFrom the oldest tick its queries read keeps a fixed number of ticks, whatever the length of the stream. A row below the bound is invalid.
The id of a windowed version is not a file's. A windowed version is named by its history, not by its contents: its id is the hash (the 64-bit hash used for files, Versions) of the text elucid8 keepFrom <old id> <dimension> <bound> and a line break, followed by the rows' bytes; rows appended to it later continue that hash, as they do a file's. So the same history always gives the same id, and the same id the same points. But a file holding exactly the same points has another id: a snapshot naming one does not name the other, and the cache treats them as two versions. The answers are identical, point for point; the only cost is reuse, since a value cached under one is checked point by point against the other (§6) rather than reused at once. (No file can have a windowed version's id: its first line is neither a CSV header naming value (or <input>_value) nor JSON.)
The reply gives the input, the newest version, the ids added (empty if the data was already held), and the newest versions of everything: {"id":7,"status":"done","input":"x","version":"…","added":["…"],"versions":{…}}. If the file cannot be read, or is malformed, the reply is invalid with the message run would give, and nothing changes.
#reload
Reads the configuration again, and the plan:
{"id": 8, "op": "reload"}
{"id": 9, "op": "reload", "plan": "plan-2.json"}
planandconfig(optional) name other files, relative to the directory the service was started in, as on the command line. They are kept for later reloads.- A changed plan (different bytes) is a new deployment: the caches are emptied (the values' definitions may have changed), and every input takes its versions from the configuration. The data clients sent stay: data belong to the inputs, not to the program, so each advance taken is sent again, in order, while the program still reads its input and the input's entry in the configuration and its files are unchanged. The answers are those of a fresh service of the new program sent the same advances, and those a service stopped and started again with
--stategives. - Otherwise, each input whose binding changed (any field of its entry, its files, their contents, its labels or its
pin) takes the binding's versions, and the one it pins becomes the newest; its advances from before are left out, as at a start. A binding that did not change keeps its newest version, even one that arrived byadvance. - Said in the events: when advances were sent again or left out, a line on standard error,
{"event":"state","restored":4,"leftOut":[{"input":"g","advances":2,"why":"its entry in the configuration, or its file, changed"}]}(with--state,"setAside"names the copy of the file before). The reasons are those of a start:"the program no longer reads this input","its entry in the configuration, or its file, changed", an advance refused, or a file it names that changed. - A changed provider of an input answered on demand is started again (a program is stopped and started anew when next asked), and the caches are emptied: answers from the old program must not be reused for the new one.
- Changed options apply to later requests; turning a cache on or off empties the caches. A changed
missingfor an input empties them too. - The reply says whether the
planchanged, which entrieschanged(inputs.x,outputs,options), whether the caches were dropped (cachesDropped), and the newestversions. - If a file cannot be read, the reply is
invalidwith every problem found, and nothing changes. So too when the deployment does not fit the program: for example a changed program whose value gained a dimension that an output'soverleaves out (an output names every dimension of its value, as a query does): the reply isinvalidwith the refusalelucid8 checkgives, and the deployment before it goes on. A service whose deployment has such an output does not start:elucid8 serveprints the refusal and exits with code 3.
#stats
Replies with stats:
| field | meaning |
|---|---|
uptimeMs | time since the service started |
requests | requests answered, by status |
queryMs | query times: count, p50, p95, max over every query that ran |
caches | whether each cache is kept; pointEntries, sourceEntries; records (what the cached values were computed from, §5); bytes, the estimated size; cacheBytes, the budget (null: none); evictionPasses, evicted, and evictedDead (entries no request could use any more); compacted (entries whose record a pass compacted) and compactedStricter (of those, records that cover points the value never read, §5) |
totals | over every query that ran: evaluations, values computed, cache hits, service results replayed from the cache, input points read, source-cache hits, service calls; and advances, reloads, versionsDropped |
versions | the newest version of every input |
inputs | for each input, its available versions (each with whether it is current, whether it is bound, and its holders, §6) and how many were dropped |
subscriptions | only when there are any: each subscription's id, runs (answers so far), skipped (runs left out while its client had not read its last answer, §7) and held (whether it is waiting for its client now) |
perRequest | what each query and advance cost since the last stats (at most the last 100,000), in order: its id, op and ms; for a query, its evaluations, kernelElements, kernelRuns and levelsComputed; and after each, heldBytes: the estimated bytes the service holds between requests (regions and levels kept, and the caches). A session's turn costs its advance and its query. |
A reply to stats is also the health check.
#describe
{"id": 1, "op": "describe"} (or GET /describe) replies with the program as a page without a compiler needs it, the eLucid8 Player's (§8): every value the program writes, in its order, each with its kind (value or input), its dimensions (dims), its bounds along each ([0, 15]; [0, null] with no end; {"labels": ["north", "south"]} along a dimension of texts) and, when it is an iteration, the dimension it iterates along (iteratesAlong); the dimensions ({"type": "int"}, or {"type": "text", "labels": [...]}: the program's own list first, then the data's texts); the outputs the program names (name, values, over, and, from 0.24.0, query: how a query asks for the channel, output("report")); iterations, every dimension an iteration runs along; suggested, the value it most likely means as its result (the first value of its first output, else its last value that is not an input or a service call); last, what last stands for now on each dimension whose data has reached somewhere (§3); the versions pinned; the runtime; and the protocol, elucid8-serve/1.
{"id":1,"status":"done","values":[{"bounds":{"x":[0,15],"y":[0,15]},"dims":["x","y"],"kind":"input","name":"initial"},{"bounds":{"time":[0,9999],"x":[0,15],"y":[0,15]},"dims":["x","y","time"],"kind":"value","name":"heat","iteratesAlong":"time"}],"dimensions":{"time":{"type":"int"},"x":{"type":"int"},"y":{"type":"int"}},"outputs":[],"iterations":["time"],"suggested":"heat","last":{"x":15,"y":15},"versions":{"initial":"f51b9f32457b53a7"},"runtime":"elucid8/0.26.0","protocol":"elucid8-serve/1"}
A value's bounds are the plan's view bounds (viewBounds, plan-v2 §3), what a view of it shows; along a dimension whose end the data decide, [0, null] with last saying where the data has reached.
#cancel
{"id": 9, "op": "cancel", "target": 1} stops request 1:
- if it is running, it stops at its next check (within a few thousand evaluations, or between two levels of a group) and is answered
cancelled; - if it is waiting, it is answered
cancelledwhen its turn comes, without running; - otherwise (unknown, or already answered) nothing happens.
The cancel itself is acknowledged in turn, after the request it stopped: {"id":9,"status":"done","target":1,"found":true} (found is false if nothing was running or waiting under that id). Ids are compared as JSON, so 1 and "1" are different requests. A service call already in flight is not interrupted (§5). An advance or reload that has begun is not stopped.
A cancel whose target is a subscription (§7) stops its run in progress, if one is running; the subscription carries on. To end it, use unsubscribe.
#subscribe and unsubscribe
subscribe takes a query as query does (text, or value and points; tile, format, budgetMs, maxDepth, maxAggregate), but no snapshot: a subscription always follows the newest data. It is answered at once, then again after every advance or reload that changes what it can read (§7).
| field | meaning |
|---|---|
send | changed (the default): each answer after the first holds only the points whose outcome differs from the previous answer, and points the previous answer did not have; all: every point, every time |
every | true: one answer for every new version of the data, in turn, while the subscriber keeps up. Without it, a run still waiting when newer data arrives moves to the newest data, so a slow subscriber never falls behind; over HTTP, a subscriber that has not read its last answer gets the newest data next, with or without every (§7) |
An output whose records go to a program, whether the configuration lists it (outputs) or the program names it and the configuration sends it to a program (outputs named in the program), can be followed instead of a query: {"id": "rows", "op": "subscribe", "output": "training_rows"} sends every record to the program now, and after each change to the data its values can read, only the records whose outcomes changed (and records new to the box). Its answers say how many records the box has, how many were sent, and how many were unchanged: {"id":"rows","status":"done","run":2,"output":"training_rows","records":50,"sent":3,"unchanged":47,"versions":{…},"report":{…}}. A run whose records the program did not accept is answered invalid, with a message, and the next run sends again what changed since the last records it accepted. An output that writes a file cannot be followed (elucid8 run writes files).
A subscription needs an id, which every answer carries, and which no other active subscription has. {"id": 12, "op": "unsubscribe", "target": 7} ends subscription 7: the reply ({"id":12,"status":"done","target":7,"found":true}) is followed by the subscription's last, {"id":7,"status":"ended","runs":5,"reason":"unsubscribed"}.
#shutdown
{"id": 10, "op": "shutdown"}: nothing after this line is read; the requests received before it are answered, and the answers of subscriptions waiting to run, then each subscription's last reply ("status":"ended","reason":"shutdown"), then the shutdown ({"id":10,"status":"done","now":false}), and the process exits with code 0. Process services are stopped, as run stops them.
With "now": true, the running request is cancelled and every waiting one, subscription runs included, is answered cancelled, then the subscriptions end and the shutdown is answered.
Closing standard input is a shutdown without a reply.
Signals. SIGTERM or SIGINT (Ctrl-C; on Windows, Ctrl-C or Ctrl-Break) is a shutdown nobody waits for: as {"op": "shutdown"} from the moment it arrives, while the deployment loads too, but its reply is not written (the log has it, with "client":"SIGTERM","endpoint":"signal"), and {"event":"signal","signal":"SIGTERM","then":"shutdown"} is written on standard error. So docker stop, systemd and launchd stop the service cleanly, without losing an answer: allow them as long as the longest request takes (their default grace periods are 10 s for Docker and 90 s for systemd; Running eLucid8 as a service has the files). A second signal while it stops is a shutdown with "now": true ("then":"shutdown now"): the running request and every waiting one are answered cancelled. A service call in flight is not interrupted: the request ends when the call answers or times out. A signal while the deployment loads stops the service once it has loaded, with nothing answered (standard input is read only once it has loaded).
#4. Replies
The protocol's version: elucid8-serve/1, said in the ready line, in describe's reply and by GET /health. A reply may gain fields within a version: a client ignores the fields it does not know. A change that would break a client takes a new version, elucid8-serve/2.
Every reply has the request's id and a status:
| status | meaning |
|---|---|
done | the request completed. For a query, its outcomes may be eod or errors: those are results, not failures |
programError | the query stopped with a program error, as exit code 1 of run (for example the demand-depth limit). programError holds the message, and results the points computed before it |
invalid | the request could not be read, checked or carried out (malformed JSON, an unknown op or field, an unknown value, a coordinate of the wrong type, a limit raised, a file that cannot be read). message says why. Nothing is computed or changed, and the service carries on |
cancelled | stopped by cancel or shutdown with now. message is "cancelled" |
overBudget | stopped because its budgetMs ran out. message is, for example, "time budget of 2000 ms exceeded" |
ended | a subscription's last reply: it ended (reason: unsubscribed, shutdown, or the plan changed), after runs answers |
A query's results. With jsonl, results is a list of the objects elucid8 run writes, one per point, in the order of the query's points: {"name":…,"context":…,"outcome":…}, the outcome in the JSON form elucid8 run writes (Command reference). With csv, csv is the text of the file run --format csv writes for that query, header included. versions names the versions the query pinned.
Frames. With "format": "frame", the reply holds frame instead of results: the answer to the whole query as one block, shaped like the data, rather than one object per point. It is the object elucid8 run --format frame writes for the same query (one per line). With the guide's running sum, where x is 0 at t = 3 and the data ends at t = 5:
{"id": 1, "op": "query", "query": "ratio[t = 2..7]", "format": "frame"}
{"id":1,"status":"done","frame":{"name":"ratio","axes":[{"name":"t","range":[2,7]}],"type":"number","values":[2,null,2.6,2.4444444444444446,null,null],"kinds":[0,2,0,0,1,1],"kindNames":["value","eod","error"],"ts":{"axis":"t","values":[0,0,0,0,0,0]},"errors":{"1":{"error":"division","message":"division by zero"}}},"versions":{"x":"d20b5fc4a3d402cb"},"report":{…}}
| field | meaning |
|---|---|
name | the value queried |
axes | one per dimension, in the order the query names them: {"name": "t", "range": [lo, hi]} for integers (both ends included; one coordinate is [c, c]), or {"name": "zone", "labels": ["north"]}. The cells run through the box with the last axis varying fastest, so heat[time = 5, x = 0..15, y = 0..15] is 1 × 16 × 16 cells, y changing first. A value with no dimensions has no axes and one cell |
type | number, boolean or text when every value in the frame has that type; json when they mix or include a list; none when no cell is a value |
values | one per cell, in that order, written as in results (numbers JSON cannot carry, such as -0 or Infinity from source data, as {"special": "-0"}). A cell that is not a value is null |
kinds | one per cell: 0 a value, 1 eod, 2 an error |
ts | the timestamps: where every cell's timestamp is a function of its coordinate on one axis, as here, {"axis": …, "values": […]}, one per coordinate of that axis; otherwise a list, one per cell. In a partial frame, one per cell sent |
errors | each error cell's index (as text) and its error, exactly as results would give it |
programError | only if a program error stopped the query: then values and kinds hold the cells computed before it, in order, as results would |
A cell that is not a value (eod or an error) is never NaN or 0: null in values, with its kind, so a program that reads a frame cannot mistake a missing reading or a failure for data. Every frame equals results for the same query, cell by cell, and the same query sent with "tile": false (point by point) gives the same frame. A query given as value and points lists separate points, not a box, so it cannot be a frame: with "format": "frame" it is invalid.
A 64 × 64 grid of numbers is about 81 KB as a frame against 375 KB as results.
A subscription's answers carry its id, run (1 for the first answer, then 2, 3, …), and, with send: changed, unchanged, the number of points not sent because their outcome is the one the previous answer gave. With "format": "frame" and send: changed, an answer over the same box as the previous one is a partial frame: the frame's fields, with cells, the indices of the cells sent (in the whole box, the last axis fastest); values and kinds hold one entry per cell sent, in the same order, and errors is keyed by cell index, as in a whole frame. A cell not listed has the outcome it had in the previous answer. The first answer is a whole frame, and so is an answer whose box changed shape, or moved along a dimension not given with last:
{"id":3,"status":"done","run":4,"unchanged":15,"frame":{"name":"level","axes":[{"name":"x","range":[0,3]},{"name":"y","range":[0,3]}],"cells":[6],"type":"number","values":[2.5],"kinds":[0],"kindNames":["value","eod","error"],"errors":{}},"versions":{…},"report":{…}}
A box that moved along last. When the box kept its shape and moved only along dimensions given with last (t = last, t = last - 9 .. last), the answer is a partial frame too, with shift: how far the box moved along each dimension that moved, by name ({"t": 1}; {"t": 2, "k": 1}). Its axes are the new box's, and its cells are compared by position: cell i of the new box with cell i of the previous answer's box. So a client keeps the cells it holds, relabels them to the new axes (cell i stays cell i), and sets the cells listed. For a view of the newest turn (canvas[t = last, x = …, y = …], the Player's live mode), that sends the cells that changed since the last answer instead of the whole canvas. Where the value's levels share the tiles that did not change (a drawing's canvas: §10), only the points in tiles that changed are computed and compared, so such an answer costs about what changed; the cells sent are the same, and the report's demands counts only the points taken. A running total of three counters, followed over its two newest turns:
-- A running total of each counter's levels.
level = input("level", t : inf, k : 3)
total = level fby.t (total + next.t level)
level.csv holds turns 0 and 1 (t,k,value, then 0,0,1, 0,1,2, 0,2,3, 1,0,1, 1,1,0, 1,2,3), and the configuration reads it ({"format": "elucid8-deploy/2", "inputs": {"level": {"from": "level.csv"}}}). The client subscribes, then turn 2 arrives:
{"id": 1, "op": "subscribe", "query": "total[t = last - 1 .. last, k = 0..2]", "format": "frame"}
{"id": 2, "op": "advance", "input": "level", "rows": "2,0,0\n2,1,0\n2,2,1\n"}
{"id":1,"status":"done","run":1,"unchanged":0,"frame":{"name":"total","axes":[{"name":"t","range":[0,1]},{"name":"k","range":[0,2]}],"type":"number","values":[1,2,3,2,2,6],"kinds":[0,0,0,0,0,0],"kindNames":["value","eod","error"],"ts":{"axis":"t","values":[0,0]},"errors":{}},"versions":{"level":"489c66453d9cd85e"},"report":{…}}
{"id":2,"status":"done","input":"level","version":"c5fbce5f82d0301e","added":["c5fbce5f82d0301e"],"rows":3,"versions":{"level":"c5fbce5f82d0301e"}}
{"id":1,"status":"done","run":2,"unchanged":3,"frame":{"name":"total","axes":[{"name":"t","range":[1,2]},{"name":"k","range":[0,2]}],"shift":{"t":1},"cells":[0,2,5],"type":"number","values":[2,6,7],"kinds":[0,0,0],"kindNames":["value","eod","error"],"ts":[0,0,0],"errors":{}},"versions":{"level":"c5fbce5f82d0301e"},"report":{…}}
The box moved from turns 0–1 to turns 1–2. The client held [1,2,3, 2,2,6] (turn 0, then turn 1); relabelled to turns 1–2 and with cells 0, 2 and 5 set, it holds [2,2,6, 2,2,7], the whole frame a query of total[t = 1..2, k = 0..2] gives. A client that has no previous answer, or cannot relabel, asks for the whole frame with a query.
Warnings. Where the query's aggregates left out missing data, the reply, and each answer of a subscription, has warnings, a list with one message per input (aggregates left out 2 missing points of input reading), after programError (if any) and before results, csv or frame. A query that leaves out a dimension of its value (for example distance[x = 0..3] for a distance over x and y) is not answered: it is invalid, and the service keeps running (queries):
{"id":5,"status":"invalid","message":"query (distance): the query leaves out dimension y of distance: a query names every dimension of its value, as in distance[x = …, y = …]"}
A reply without warnings has no warnings field.
The report. report is the query's entry in run's report (--report): its name, number of points, time in milliseconds, program error, every service call, and its statistics (evaluations, values computed, cache hits, entries in each cache after the request, memory retention). A cancelled or overBudget reply has a report too, with what was done before it stopped; a request cancelled before it started has none.
#5. Caches, the memory budget, time budgets and cancellation
Shared caches. The configuration's options decide the caches ("pointCache": true, "sourceCache": true, options). In a service, they are shared by every request for the life of the process, as run shares them across a configuration's queries. An entry is reused only while what it read is unchanged, so a request under other versions of the data recomputes exactly the points whose inputs differ. Service results are reused by later requests only under reuse successes; failures never are. A query over a box of 4,096 cells or more, of a value computed in loops (boxKernels), is computed that way and its values are not cached: computing them again costs less than keeping them (the sensor field's stream, with a point cache, answers each tick as fast as without one).
What a stopped request leaves behind. Each request stores its new entries in an overlay, which joins the caches only when the query ends by itself (done, or programError, whose entries are correct outcomes, as a configuration's queries keep them). A cancelled or overBudget request's overlay is discarded: it leaves nothing in the caches, so every later answer, and every count in its report, is what it would have been if the stopped request had never been sent.
The memory budget. With a budget (--cache-bytes, or the option cacheBytes), the service estimates the caches' size and keeps it under the budget:
- The estimate counts each cached entry (its point, its outcome, its place in the cache) and each record: what a cached value was computed from, which the cache keeps so that it can tell, when the data changes, which entries are still right. A value's record links to the records of the values it read, so the records of a long computation (a training run, a long history) form a chain back to its start. Each record is counted once, however many others link to it.
- When a request ends and the estimate is above the budget, entries are evicted until it is under seven-eighths of the budget (the margin saves a pass after every request). Eviction never happens while a request runs.
- What goes first: entries no request can use any more (they read data that is no longer available, §6). Then, if the estimate is still above the budget, the pass compacts the records: each cached entry's record is replaced by what the value read, transitively (the input points, at the versions read, kept as boxes of points; whether it depends on a service result that may not be reused), with no links to other records. Entries that read the same data share one record, so the chains behind long computations are freed. Compaction keeps reuse exact: an entry is reused after it exactly when it would have been before. Then, if the estimate is still above the budget, entries are evicted least recently used first, wherever they are in a computation. Once a pass has had to compact, each entry's record is compacted as the entry is stored, so later passes have little left to do.
- Exact, or stricter, never looser. Where a value read many scattered points of one input (more than 16 boxes of points), neighbouring boxes are merged, and the record then covers points the value never read: a change to one of them makes the entry be computed again, although its answer could not have changed. Such records are counted (
compactedStricter, §7). None of the examples, training programs or tests here produces one. - Eviction never changes an answer. An evicted value is computed again when a request needs it, with the same outcome. Data is never evicted while a request may still read it (§6).
- What the budget does not cover: the memory a request uses while it runs (its own working set of values, which the service frees when it ends), and the data held for each version of an input (§6).
Choosing a budget. Compaction alone often brings the caches far under the budget: a training run of loss and test_loss at step 20 (Alps linear, per element) leaves 183 MB of entries and records, and 88 MB once compacted, with every entry kept. Over 40 requests for loss at steps spread from 1 to 60, a 256 MB budget kept every entry (one pass, 275 MB to 117 MB) and recomputed nothing, at 400 MB peak against 424 MB with no budget; a 64 MB budget kept about 23 steps of history, evicted the oldest steps first, and each request computed only the steps it lacked (60 ms a request, 300 MB at peak). A budget smaller than the history a request pattern revisits costs recomputation: each request computes again what was evicted, in its own working set, which the budget does not cover (below). So size the budget to the history your requests come back to, and expect peak memory to be the budget plus the largest request's working set. (These numbers were measured on an Apple M5 Max with elucid8 0.3.0, when the memory budget was introduced; later releases keep smaller records, so the same caches take less memory.) Where queries share smaller pieces of work (a heat plate queried at many points and times), compaction keeps all the reuse: 121 MB at peak against 153 MB, over 60 requests across three versions of the data, with nothing evicted.
Time budgets. budgetMs is measured from when the request starts running (not from when it arrived). The query checks the time every few thousand evaluations and between levels of a group; when the budget has run out, the query stops with a program error, and the reply is overBudget. A budget never changes an outcome: like the demand-depth limit, it is a limit on resources, so the same query without a budget (or with a larger one) gives the program's outcomes. From 0.26.0 a request with no budgetMs has the service's time limit as its budget (elucid8 serve --time, an hour by default; --time none for none), and a larger budgetMs is held to it.
Service calls in flight. A call to an external service that has started is not interrupted: the stop takes effect when the call returns. A process service's own timeoutMs still applies.
#6. Versions: data that arrives, and data that goes
The newest version. Each input has a newest version: at first, the one its binding pins (its pin, else the last listed); then the one each advance (or a reload that changed the binding) makes newest. A request without a snapshot pins the newest version of everything as of the moment it starts.
When an advance takes effect. In turn, like every request: advance and reload wait for the requests sent before them, and take effect before the requests sent after them. So a query sees exactly the data that was current when it arrived: a query sent before an advance is answered under the old data, even if it was still waiting when the advance arrived, and a query sent after it under the new. A client can therefore send a query, an advance and another query without waiting for replies, and the first query sees the old data and the second the new.
Which versions stay available. A version stays readable while something needs it:
- the newest version, and the versions the input's binding lists (in the configuration, or in the last
advancethat gave a whole set ofversions), always; - any other version while a running request pins it, or while values in the cache were computed from it: the cache needs it to tell whether those values are still right under newer data. These are the version's holders (
statscounts them).
When a version has no holders left, it is dropped and its data freed (a dropped event in the log). It keeps its id and label, so a request that names it in a snapshot still runs, but every read of it gives an Error (source-version-unavailable), never a value from another version.
What is computed again. After an advance, a cached value is reused when every input point it read is the same in the new version; otherwise it is computed again. Values computed from data that no available version still has go from the cache at once (they could never be reused).
#7. Subscriptions: answers pushed when data arrives
A subscription is a query the service answers again whenever the data it reads changes, so that a program following a stream (a sensor, a feed of events) does not have to ask for every new tick. Every answer is exactly the answer a query request would give under the same versions of the data.
When it runs. At once, and then after every advance (or reload) that changes an input the query can read, or that moves its last. What a query can read is worked out from the program: an advance of an input it never reads does not wake it. Its run is queued behind every request received before the advance was handled, like any request, and answered in turn.
When data arrives faster than answers. If a run is still waiting when newer data arrives, it moves to the newer data: the subscriber gets the latest answer, never a backlog. With "every": true, each new version of the data is answered in turn instead (for example, for an audit log).
A subscriber that reads slowly. Over HTTP, a subscription is not run again while its event stream still has an answer the client has not read: once that answer is written, the subscription runs once, at the newest data. So a slow subscriber (a browser drawing large frames, a client on a slow link) gets fewer answers, each at the newest data there is, never a backlog, and the service holds at most one unwritten answer for it; with send: changed, each answer is compared with the last one actually sent, so a client that applies every answer it receives has exactly the cells a fresh query gives. This holds with "every": true too: while the client is behind, the versions it has not seen become one answer at the newest. stats (subscriptions, each with skipped) and /metrics (elucid8_subscription_runs_skipped_total) count the runs left out this way. Over standard input, and for an output whose records go to a program, every answer is written before the service goes on, so a slow reader there slows the service instead.
What is computed. A subscription shares the service's caches (with a point cache in the options), so each run computes only what the new data changed: for a query at last over an input that gains a row, the values at the new row (§6). A run makes service calls only for the points it needs, and reuses a result from an earlier run only under reuse successes, as any request does.
Inputs served by programs. An input whose rows come from a program (programs as sources) is asked again before each request; when the program gives a new version, the input advances to it, as an advance of a file would, and the subscriptions that read it are woken.
Data that arrives by itself. An input whose from is a built-in clock or a replay of a file (command reference) is given its rows by the service: each tick is appended when it is due, between requests (a tick that is due goes before the next request), as an advance with rows would be, and wakes the subscriptions that read it. Ticks are not requests (no reply, no line in the log); stats and describe list such inputs under feeds, with the ticks given so far, and the log has a feed event when one ends ("status":"ended", its until or its file reached) or is stopped ("status":"stopped", rows it could not append, with the message). An advance of such an input is invalid. A shutdown stops the ticks with the service. An input whose from follows a file ({"builtin": "follow", "file": "live.csv"}) is looked at every every (250 ms unless given) in the same way: the complete lines added to the file are appended as rows, and a file rewritten (shorter, or with bytes already read changed) is read again whole, as a correction. Looks are not requests either; the log has a follow event when the file is rewritten ("status":"rewritten"), is gone or cannot be read ("gone", once, the data staying as they were), comes back ("back"), or has rows the version cannot take ("refused", once, with the message). stats and describe list it under feeds, with "kind":"follow".
Budgets. A run stopped by its budgetMs is answered overBudget, and the subscription carries on with the next data. A cancel naming the subscription stops the run in progress.
How it ends. By unsubscribe, by shutdown, or by a reload that changes the plan ("reason":"the plan changed"): each with a last reply, "status":"ended".
A sensor that gains readings. A program, in the notation v0.2, that calibrates a sensor's readings by the offset in force when each was taken; each reading and each calibration carries its time (the ts column of its file):
-- A sensor's reading, less the offset in force when it was taken.
reading = input("reading", time : 1000)
offset = input("offset", u : 100)
calibrated = reading - asof.u offset at time(reading) end
So far reading.csv holds two readings, 20 at 0 ms and 22 at 100 ms (time,value,ts, then 0,20,0 and 1,22,100), and offset.csv two calibrations, 1 at 0 ms and 2 at 250 ms (u,value,ts, then 0,1,0 and 1,2,250):
{ "format": "elucid8-deploy/2",
"inputs": { "reading": { "from": "reading.csv", "time": "ts" }, "offset": { "from": "offset.csv", "time": "ts" } },
"options": { "pointCache": true } }
The client subscribes to the two newest readings, then rows arrive; it waits for each reply before sending the next request. The last advance is a correction: reading-fixed.csv is the readings so far with the reading at 300 ms corrected from 25 to 26.
{"id": 1, "op": "subscribe", "query": "calibrated[time = last - 1 .. last]"}
{"id": 2, "op": "advance", "input": "reading", "rows": "2,21,200\n"}
{"id": 3, "op": "advance", "input": "reading", "rows": "3,25,300\n"}
{"id": 4, "op": "advance", "input": "offset", "rows": "2,4,280\n"}
{"id": 5, "op": "advance", "input": "reading", "file": "reading-fixed.csv"}
{"id": 6, "op": "unsubscribe", "target": 1}
{"id":1,"status":"done","run":1,"unchanged":0,"results":[{"name":"calibrated","context":{"time":0},"outcome":{"kind":"value","value":19,"ts":0}},{"name":"calibrated","context":{"time":1},"outcome":{"kind":"value","value":21,"ts":100}}],"versions":{"offset":"b14a7a8bef345e15","reading":"f6b53dc0aa47c155"},"report":{…}}
{"id":2,"status":"done","input":"reading","version":"48fa15587c147ac4","added":["48fa15587c147ac4"],"rows":1,"versions":{"offset":"b14a7a8bef345e15","reading":"48fa15587c147ac4"}}
{"id":1,"status":"done","run":2,"unchanged":1,"results":[{"name":"calibrated","context":{"time":2},"outcome":{"kind":"value","value":20,"ts":200}}],"versions":{"offset":"b14a7a8bef345e15","reading":"48fa15587c147ac4"},"report":{…}}
{"id":3,"status":"done","input":"reading","version":"ddf5cd6deb9fc99f","added":["ddf5cd6deb9fc99f"],"rows":1,"versions":{"offset":"b14a7a8bef345e15","reading":"ddf5cd6deb9fc99f"}}
{"id":1,"status":"done","run":3,"unchanged":1,"results":[{"name":"calibrated","context":{"time":3},"outcome":{"kind":"value","value":23,"ts":300}}],"versions":{"offset":"b14a7a8bef345e15","reading":"ddf5cd6deb9fc99f"},"report":{…}}
{"id":4,"status":"done","input":"offset","version":"51b5353fb9e83287","added":["51b5353fb9e83287"],"rows":1,"versions":{"offset":"51b5353fb9e83287","reading":"ddf5cd6deb9fc99f"}}
{"id":1,"status":"done","run":4,"unchanged":1,"results":[{"name":"calibrated","context":{"time":3},"outcome":{"kind":"value","value":21,"ts":300}}],"versions":{"offset":"51b5353fb9e83287","reading":"ddf5cd6deb9fc99f"},"report":{…}}
{"id":5,"status":"done","input":"reading","version":"4314bbcad1d5acf5","added":["4314bbcad1d5acf5"],"versions":{"offset":"51b5353fb9e83287","reading":"4314bbcad1d5acf5"}}
{"id":1,"status":"done","run":5,"unchanged":1,"results":[{"name":"calibrated","context":{"time":3},"outcome":{"kind":"value","value":22,"ts":300}}],"versions":{"offset":"51b5353fb9e83287","reading":"4314bbcad1d5acf5"},"report":{…}}
{"id":6,"status":"done","target":1,"found":true}
{"id":1,"status":"ended","runs":5,"reason":"unsubscribed"}
- Run 1 answers readings 0 and 1 at once, each with its timestamp (0, so not shown, and 100 ms).
- Requests 2 and 3 each add a reading:
lastmoves, and each answer sends only the new reading (unchanged: 1). Each run computes one value; the reading before it comes from the cache (its report: one value computed, one cache hit). - Request 4 adds a calibration at 280 ms. The reading at 300 ms is now calibrated by offset 4 instead of 2, so it is computed again, changes and is sent. The reading at 200 ms chose the calibration at 0 ms, with none between 0 and 200 ms; the new one, at 280 ms, cannot change that, so it comes from the cache.
- Request 5 is a correction, a whole new file: only the reading that changed is computed again, and sent; the one at 200 ms comes from the cache.
A live sine wave, with no script. The input clock is given a row every 50 ms by a built-in clock (here only 4 rows, until, from time 0, start, so that the answers below do not depend on when it ran); x has a value at every tick there is:
-- A sine wave with a value at every tick of the clock.
clock = input("clock", t : inf)
x = if iseod(clock) then eod else sin(2 * pi * #t / 100)
{ "format": "elucid8-deploy/2",
"inputs": { "clock": { "from": { "builtin": "clock", "every": "50ms", "until": 4, "start": 0 } } } }
{ echo '{"id": "wave", "op": "subscribe", "query": "x[t = last]", "every": true}'
until grep -q '"event":"feed"' serve.log 2> /dev/null; do sleep 0.05; done
echo '{"id": 1, "op": "query", "query": "x[t = 0..4]"}'; echo '{"id": 2, "op": "shutdown"}'; } | elucid8 serve sine.el8 --config deploy.json 2> serve.log
{"id":"wave","status":"done","run":1,"unchanged":0,"results":[{"name":"x","context":{"t":0},"outcome":{"kind":"value","value":0,"ts":0}}],"versions":{"clock":"01184dc1ddb1cee9"},"report":{…}}
{"id":"wave","status":"done","run":2,"unchanged":0,"results":[{"name":"x","context":{"t":1},"outcome":{"kind":"value","value":0.06279051952931337,"ts":50}}],"versions":{"clock":"0154f286c795b349"},"report":{…}}
{"id":"wave","status":"done","run":3,"unchanged":0,"results":[{"name":"x","context":{"t":2},"outcome":{"kind":"value","value":0.12533323356430426,"ts":100}}],"versions":{"clock":"bf088e1ee8a3fc73"},"report":{…}}
{"id":"wave","status":"done","run":4,"unchanged":0,"results":[{"name":"x","context":{"t":3},"outcome":{"kind":"value","value":0.1873813145857246,"ts":150}}],"versions":{"clock":"a9e4b8ae45a4d74c"},"report":{…}}
{"id":1,"status":"done","results":[{"name":"x","context":{"t":0},"outcome":{"kind":"value","value":0,"ts":0}},{"name":"x","context":{"t":1},"outcome":{"kind":"value","value":0.06279051952931337,"ts":50}},{"name":"x","context":{"t":2},"outcome":{"kind":"value","value":0.12533323356430426,"ts":100}},{"name":"x","context":{"t":3},"outcome":{"kind":"value","value":0.1873813145857246,"ts":150}},{"name":"x","context":{"t":4},"outcome":{"kind":"eod","ts":0}}],"versions":{"clock":"a9e4b8ae45a4d74c"},"report":{…}}
{"id":"wave","status":"ended","runs":4,"reason":"shutdown"}
{"id":2,"status":"done","now":false}
The client waits until the clock has ended before it asks for x over five ticks. The subscription was answered at once, at tick 0, then once a tick (every: each version of the data in turn), each time with the newest point; the clock then ended (serve.log has {"event":"feed","input":"clock","kind":"clock","status":"ended","ticks":4}). Without until, the clock ticks until the service stops; over HTTP, a Player link with "live": true follows the wave as it grows (§8), and elucid8 mcp's show starts all of this with one call. A replay does the same with a file's rows, one coordinate a tick ({"builtin": "replay", "file": "readings.csv", "every": "1s"}).
A file another program writes, with no script. Another program appends each sale to sales.csv as it happens; the input sale follows the file:
-- Sales as another program writes them, a row a sale.
sale = input("sale", t : inf)
total = sale fby.t (total + next.t sale)
{ "format": "elucid8-deploy/2",
"inputs": { "sale": { "from": { "builtin": "follow", "file": "sales.csv" } } } }
printf 't,value\n0,5\n' > sales.csv
runs() { until [ "$(grep -c '"id":"total"' replies.jsonl 2> /dev/null)" = "$1" ]; do sleep 0.05; done; }
{ echo '{"id": "total", "op": "subscribe", "query": "total[t = last]", "every": true}'
runs 1; printf '1,3\n2,4\n' >> sales.csv
runs 2; printf '3,' >> sales.csv; sleep 1; printf '2\n' >> sales.csv
runs 3; echo '{"id": 1, "op": "shutdown"}'; } | elucid8 serve sales.el8 --config deploy.json > replies.jsonl 2> serve.log
cat replies.jsonl
{"id":"total","status":"done","run":1,"unchanged":0,"results":[{"name":"total","context":{"t":0},"outcome":{"kind":"value","value":5,"ts":0}}],"versions":{"sale":"35c2319ad939ac27"},"report":{…}}
{"id":"total","status":"done","run":2,"unchanged":0,"results":[{"name":"total","context":{"t":2},"outcome":{"kind":"value","value":12,"ts":0}}],"versions":{"sale":"a213985ac37bd566"},"report":{…}}
{"id":"total","status":"done","run":3,"unchanged":0,"results":[{"name":"total","context":{"t":3},"outcome":{"kind":"value","value":14,"ts":0}}],"versions":{"sale":"1865961e1ee97a3f"},"report":{…}}
{"id":"total","status":"ended","runs":3,"reason":"shutdown"}
{"id":1,"status":"done","now":false}
The script waits for each answer before it writes again. The two rows written together came in one look, as one new version; the row written in two parts (3,, then a second later 2 and its line break) was read only once its line had ended, so no answer ever saw a half-written sale. Each version's id is the id of sales.csv's bytes up to its last line break, the id elucid8 run gives the file as it stands. Over HTTP, the Player with "live": true follows such a file as it grows.
#8. Over HTTP
elucid8 serve plan.json --config deploy.json --http 127.0.0.1:8080
--http HOST:PORT (or the configuration's http section, below) makes the service listen for HTTP requests too. Every endpoint is a thin mapping onto a request of §3: the same JSON in, the same reply out, byte for byte as on standard output. Standard input keeps working beside it, and requests from both go through one queue, in the order they arrive (below). When the service listens over HTTP, standard input closing does not stop it: a shutdown request does (POST /shutdown). It writes {"event":"listening","address":"127.0.0.1:8080","token":false} on standard error as soon as it listens (with port 0, the address names the port chosen), before the deployment is loaded.
A session. With the guide's program and data, as in §2 (deploy.json binds x to running-x.csv):
curl -s http://127.0.0.1:8080/health
curl -s -H "Content-Type: application/json" http://127.0.0.1:8080/query -d '{"id": 1, "query": "running[t = 4..5]"}'
curl -s -H "Content-Type: application/json" http://127.0.0.1:8080/check -d '{"id": 2, "query": "running[t = 0..5]"}'
curl -s -H "Content-Type: application/json" http://127.0.0.1:8080/advance -d '{"id": 3, "input": "x", "file": "running-x-tuesday.csv"}'
curl -s -H "Content-Type: application/json" http://127.0.0.1:8080/query -d '{"id": 4, "query": "running[t = 5]"}'
printf '6,4\n' | curl -s -H "Content-Type: text/csv" --data-binary @- 'http://127.0.0.1:8080/inputs/x/rows?id=5'
curl -s -H "Content-Type: application/json" http://127.0.0.1:8080/ -d '{"id": 6, "op": "query", "query": "running[t = 6]", "format": "csv"}'
curl -s -H "Content-Type: application/json" http://127.0.0.1:8080/shutdown -d '{"id": 7}'
{"status":"ready","protocol":"elucid8-serve/1"}
{"id":1,"status":"done","results":[{"name":"running","context":{"t":4},"outcome":{"kind":"value","value":13,"ts":0}},{"name":"running","context":{"t":5},"outcome":{"kind":"value","value":22,"ts":0}}],"versions":{"x":"d20b5fc4a3d402cb"},"report":{…}}
{"id":2,"status":"done","name":"running","points":6,"versions":{"x":"d20b5fc4a3d402cb"}}
{"id":3,"status":"done","input":"x","version":"7270c6cb167f44ec","added":["7270c6cb167f44ec"],"versions":{"x":"7270c6cb167f44ec"}}
{"id":4,"status":"done","results":[{"name":"running","context":{"t":5},"outcome":{"kind":"value","value":103,"ts":0}}],"versions":{"x":"7270c6cb167f44ec"},"report":{…}}
{"id":5,"status":"done","input":"x","version":"f56d89f167360a05","added":["f56d89f167360a05"],"rows":1,"versions":{"x":"f56d89f167360a05"}}
{"id":6,"status":"done","csv":"name,t,running_value,running_kind,running_message,running_ts\nrunning,6,107,value,,0\n","versions":{"x":"f56d89f167360a05"},"report":{…}}
{"id":7,"status":"done","now":false}
Endpoints.
| endpoint | takes | gives |
|---|---|---|
POST / | a request exactly as standard input takes it, any op | its reply |
POST /query, /check, /advance, /reload, /cancel, /shutdown, /unsubscribe | the request's JSON object, without op (or with that endpoint's own) | its reply |
GET /stats (or POST) | optional ?id=… | the stats reply |
POST /inputs/NAME/rows | rows as the body (CSV or JSON lines, as the input's file is), with Content-Type: text/csv or application/x-ndjson (or application/jsonl), and optional ?id=…&label=…&keepFrom=DIM:N | the reply of advance with those rows (§3) |
GET /subscribe?query=…&id=… (or POST /subscribe with a JSON body) | a subscription's fields (§3); in a query string, every and tile are true or false, the limits numbers, and id a number when it is a whole number | an event stream (below) |
GET /health | 200 {"status":"ready","protocol":"elucid8-serve/1"}; 503 with loading while the deployment loads, or stopping after a shutdown or a signal | |
GET /metrics | the counts, in the Prometheus text format (below) | |
GET /values | the values of the queries the configuration's http.values names, in the Prometheus text format (below); from 0.19.0 | |
GET /describe (or POST) | optional ?id=… | the describe reply (§3); from 0.19.0 |
GET /player | the eLucid8 Player, a page (below); needs no token; from 0.19.0 | |
POST /player/link | {"view": {…}}, with the service's token | {"url": "http://127.0.0.1:8080/player#k=KEY&v=…"}, a link to the Player with a read-only key (below); from 0.19.0 |
Every POST names its body's type: Content-Type: application/json (parameters such as charset=utf-8 may follow), or, for rows, the types above. A POST without it, or with another (text/plain, a form's), is refused with 415 (below).
Replies. A reply's body is the reply of §4, followed by a line break, with Content-Type: application/json. Its HTTP status is 200 for done, programError and cancelled, 400 for invalid, and 504 for overBudget; the X-Elucid8-Status header names the reply's status. X-Elucid8-Seq is the reply's place in the order the service answered, counting every reply to every client (standard output included), so a client using several connections can put its replies in that order. Requests on one connection may be pipelined (sent without waiting for the replies before them); their replies come back in order.
Subscriptions are server-sent events (Content-Type: text/event-stream), one event per answer, and ended last, after which the service closes the connection:
event: run
id: 1
data: {"id":"live","status":"done","run":1,"unchanged":0,"results":[{"name":"running","context":{"t":5},"outcome":{"kind":"value","value":22,"ts":0}}],"versions":{"x":"d20b5fc4a3d402cb"},"report":{…}}
event: run
id: 3
data: {"id":"live","status":"done","run":2,"unchanged":0,"results":[{"name":"running","context":{"t":6},"outcome":{"kind":"value","value":26,"ts":0}}],"versions":{"x":"08153f41beace4d2"},"report":{…}}
event: ended
id: 5
data: {"id":"live","status":"ended","runs":2,"reason":"unsubscribed"}
That is GET /subscribe?id=live&query=running%5Bt%20%3D%20last%5D on a fresh service, then POST /inputs/x/rows?id=2 with the row 6,4, then POST /unsubscribe with {"id": 4, "target": "live"}; each event's id is its X-Elucid8-Seq. A subscription takes its connection for itself: nothing more is read on it. When its client closes the connection, the subscription ends, as with unsubscribe (the log names the endpoint disconnect). An invalid subscription is an ordinary 400 reply, not a stream. With nothing to send for 15 seconds, the stream carries a comment (: keepalive), so proxies keep it open.
Arrow answers. A query whose Accept header names application/vnd.apache.arrow.stream is answered with the Arrow stream elucid8 run --format arrow writes for that query, byte for byte (Apache Arrow), so a client reads it with pyarrow, Polars or DuckDB instead of parsing JSON. Its query must be a box, as for frames. The reply without its results (versions, report) is in the X-Elucid8-Reply header (when it is under 8 KiB), with X-Elucid8-Status and X-Elucid8-Versions. An invalid, cancelled or over-budget query is answered with its JSON reply, as above.
import json, urllib.request, pyarrow.ipc
req = urllib.request.Request("http://127.0.0.1:8080/query",
data=json.dumps({"id": 1, "query": "running[t = 0..5]"}).encode(),
headers={"Content-Type": "application/json", "Accept": "application/vnd.apache.arrow.stream"})
with urllib.request.urlopen(req) as r:
table = pyarrow.ipc.open_stream(r.read()).read_all()
Order. Requests from every client, and from standard input, go through one queue in the order the service receives them, and are answered one at a time, as in §6: a query received after an advance (from any client) sees its data, one received before it does not. cancel and shutdown act at once, whoever sends them. Answering several queries at once is not built: it would need each request's pinned versions and overlay of the caches kept apart while they run, and the caches, records and data shared between threads, where today they belong to one.
A token. --token-file FILE (or http.tokenFile, relative to the configuration) names a file holding one token (printable characters, no spaces; a final line break is ignored). Every endpoint but /health then needs Authorization: Bearer TOKEN, compared in constant time; without it, or with another, the answer is 401 with WWW-Authenticate: Bearer. The token is never read from the command line or the configuration itself, and never written to a log. Without a token, the service listens only on a loopback address (127.0.0.1, ::1, localhost); any other address is refused at start (exit code 2).
Requests from other websites. A web page open in the browser of someone using the machine can send requests to a service on a loopback address, and, by DNS rebinding (its name made to resolve to 127.0.0.1), read the answers. So the service refuses, on every endpoint (/health included) and before anything else:
- a request whose
Originheader is present and is not the service's own:http://and the address it listens on (http://127.0.0.1:8080), orlocalhostwith its port when that is a loopback address (http://localhost:8080). With a token, an origin naming the host the request'sHostheader names (https://elucid8.example.combehind a proxy) is the service's own too.403. A request withoutOrigin(curl, Python, the MCP tool, any program that is not a browser) is not affected; - without a token, a request whose
Hostheader does not name the address listened on, orlocalhost, with its port (Host: 127.0.0.1:8080,Host: localhost:8080): a page reached by DNS rebinding sends its own name.403. With a token,Hostmay be anything (a proxy in front); - a
POSTwithout its endpoint's content type (above), so that no page can send one as a "simple" request, which a browser sends without asking the service first.415.
The service sends no CORS headers: no other website may read its answers. Each refusal has a JSON body {"error": "…"} and a line on standard error, as below; neither repeats the headers' values.
The eLucid8 Player (from 0.19.0). GET /player is a page that shows a value of the program the service has loaded, as a picture, a chart or a number, and plays it along the dimension it iterates along, every frame a query of the service with "format": "frame", and Live a subscription. It is one file built into the command, with its style and script inline and nothing loaded from elsewhere, sent with Content-Security-Policy: default-src 'none'; script-src 'sha256-…'; style-src 'sha256-…'; img-src data: blob:; connect-src 'self'; frame-ancestors 'self' http://localhost:* http://127.0.0.1:* (the hashes of its own style and script), X-Content-Type-Options: nosniff, Cache-Control: no-store and Referrer-Policy: no-referrer. It needs no token: it holds no data. It is on whenever the service listens over HTTP; --no-player (or the configuration's "http": {"player": false}) turns it off, and /player and /player/link are then 404.
At start the service writes the Player's link on standard error, after listening: {"event":"player","url":"http://127.0.0.1:8080/player#k=0f3a…"} (without a token, http://127.0.0.1:8080/player). A program or a script that holds the token asks for a link of its own with POST /player/link and a view: what to show (value, up to 4 values side by side, coordinates at by dimension, the tick shown, the range Play runs through, play, live, show (values or timestamps), each dimension's role in roles (across, down, play, fixed), speed); another field, or one of the wrong kind, is 400.
Links you can type (from 0.21.0). The Player also reads its view from the link's query string, the same fields by name: http://127.0.0.1:8080/player?value=heat&play (plays heat), ?value=heat&step=300 (heat at step 300: a coordinate is written as the dimension's name, x=8, zone=north, and the played dimension's coordinate is the tick shown), ?value=x&live (follows new data). Opened before the data has reached anywhere (from 0.23.0), a live view says "Live · waiting for the first data", asks describe every second, and follows the data once it arrives. The fields: value; values=u,v; play (or play=yes), play=no, or play=step to play along a dimension; live (or live=yes), live=no; tick=300; range=0..200; show=timestamps; speed=2; roles=x:across,y:down; any other name a coordinate (at.NAME= for a dimension named like a field; a text that reads as a whole number in double quotes, code="12"). A parameter the Player cannot read is ignored. A view in the fragment (#v=…) wins over the query string. A key is never read from the query string, which browsers send to the service: with a token, put the key in the fragment, /player?value=heat&play#k=KEY. The Player writes the view back to the link in the form it was opened with, so a reload comes back to it.
The Player as an input (from 0.23.0). A link with input=NAME (input=click; click=NAME reads the same, and "input": "NAME" in the fragment's view) sends what the pointer does over the picture to the program's input NAME, as points of the value shown, never pixels. The program declares the input over a turn and a list of fields, click = input("click", t : inf, f : {"x", "y", "shown"}): each event is one row per field the list names, at its turn (one past the input's newest, last, or 0), posted with POST /inputs/NAME/rows: the dimensions across and up under their own names, "shown" the tick shown, and "kind" (1 down, 2 a move to another cell while pressed, 3 up) when the list names it; without "kind" each click (a press and release on one cell, or Enter) is one event. Events wait while a request is in flight and go together in the next, so none is lost or reordered. The page is live while it sends. It sends only to a service without a token, on loopback: with a token it says "This link can't send clicks: the service has a token" and sends nothing, since a player key only reads. For example, a game of tic-tac-toe played by clicking (/player?value=mark&live&input=click), and freehand drawing (/player?value=canvas&live&input=pen).
Keys from the Player (from 0.23.0). When the input's list names "key", the page also sends the keys pressed while the picture has the keyboard (click the picture; the stage shows a ring), exactly as elucid8 window sends them, the same rows for the same keys: "kind" 4 and "key" the key's name as the browser names it ("c", "Enter", "ArrowLeft", " " for the space bar), the modifiers "shift", "alt", "ctrl", "meta" and "cmd" (Command on macOS, Ctrl elsewhere) as true or false when listed (with one listed, "key" is the key with no modifier applied: "z" for Shift-Cmd-Z; with "cmd", "ctrl" or "meta" listed, keys with Ctrl or Cmd held reach the program), and "repeat" for a system repeat of a held key when listed (without it repeats are not sent). A key goes with the cell under the pointer when the input lists the cell's fields and the pointer is over the picture. With chars=NAME in the link ("chars": "NAME" in the view), text typed is "kind" 5 with "length", "code" and "text" when listed, and its code points go to the input NAME, over a turn and an index, as rows turn,i,code at the same turn, posted before the events; Enter, Tab, keys that type nothing or a control character, and keys with Ctrl or Cmd are "kind" 4. An input that lists neither the across nor the down field is a keys-only input: it gets keys and text typed, and the pointer sends it nothing; one that lists one of the two but not the other is refused, as by the window. Which keys stay the Player's: while the picture has the keyboard every key goes to the program except Escape, which gives the keyboard back to the Player (and stops a frame being computed); then Space, the arrows, Home and End, T and L are the Player's again. Keys the browser keeps (Cmd-Q, Cmd-W, Cmd-T) and those the window keeps for itself (Cmd-Q, Cmd-W, and Ctrl-C without a characters input) are not sent. The browser does not say which key is pressed with no modifier: with Shift, Ctrl or Command, a letter is sent in lower case; anything else with Option or Alt, or with Shift, is what that key types with none on a US layout. Text composed with an input method is not sent. For example, the editor (/player?value=doc&live&input=keys&chars=chars, its keys input listing no cell) and the drawing with tools (/player?value=canvas&live&input=pen, its keys choosing a tool, clearing and undoing).
Player keys. A browser never holds the service's token. With a token, each link carries a player key: 128 random bits, valid until the service stops, in the link's fragment (after #), which browsers never send, so it reaches neither the service's log nor a proxy's; the page sends it as Authorization: Bearer KEY. A key only reads: it is accepted by describe, query, subscribe, cancel and unsubscribe of the requests made with it, and stats (and /health, which needs nothing), and refused with 403 by everything else: advance, reload, shutdown, check, POST /inputs/…/rows, /metrics, /values, /player/link, a subscription to an output, and POST / with any of those. Without a token the service listens only on a loopback address, and the page needs no key. Whoever has a link with a key can watch the program's values, never change anything; the key in the start event is the only key ever written to standard error.
TLS. The command does not encrypt. To reach it from another machine, put a proxy in front that gives TLS (nginx, Caddy, a cloud load balancer), and keep the service on a loopback address, with a token. For event streams the proxy must not buffer (the service sends X-Accel-Buffering: no, which nginx follows) and must allow connections that stay open; for example, with Caddy: reverse_proxy 127.0.0.1:8080 { flush_interval -1 }.
Limits. The configuration's http section:
"http": { "address": "127.0.0.1:8080", "tokenFile": "token.txt", "maxBodyBytes": 67108864,
"maxConnections": 64, "maxSubscriptions": 32, "budgetMs": 30000 }
| field | default | |
|---|---|---|
address | none | where to listen, HOST:PORT; --http overrides it |
tokenFile | none | the token's file; --token-file overrides it |
maxBodyBytes | 67108864 (64 MiB) | the largest request body; a larger one is 413 |
maxConnections | 64 | connections open at once; another is answered 503 and closed |
maxSubscriptions | 32 | subscriptions open over HTTP at once; another is 503 |
values | none | the values GET /values answers: a metric's name for each, and its query ("values": { "sensor_level": "level[t = last, s = 0..2]" }), below |
budgetMs | none | the most time a query or subscription run from HTTP may take: a request without budgetMs, or with a larger one, gets this one, and is answered overBudget (504) past it |
player | true | false turns the Player off (GET /player, POST /player/link, and the link written at start), as --no-player does |
Request lines and headers longer than 16 KiB are 431; a malformed request line or body encoding is 400; a request from another website 403, a POST without its content type 415 (above); an unknown path 404, a method an endpoint does not take 405; any request after a shutdown 503. A connection idle for 60 seconds is closed. Each of these refusals has a JSON body {"error": "…"} saying why, and a line on standard error ("event":"http", with the client's address, the endpoint and the status).
Metrics (GET /metrics, the Prometheus text format): elucid8_requests_total by status and elucid8_query_duration_seconds (a histogram), the numbers stats gives (as of the last request answered; stats counts requests before itself, the metrics after it); elucid8_cache_bytes, elucid8_cache_budget_bytes, elucid8_cache_entries by cache, elucid8_cache_records, elucid8_evictions_total; elucid8_versions_held by source and elucid8_versions_dropped_total; elucid8_subscriptions; totals (elucid8_evaluations_total, elucid8_computed_total, elucid8_cache_hits_total, elucid8_source_reads_total, elucid8_service_calls_total, elucid8_advances_total, elucid8_reloads_total); and the HTTP layer's own: elucid8_ready (1 when /health answers 200), elucid8_requests_waiting (requests taken in and not yet answered, from standard input and HTTP, the one running included), elucid8_http_connections, elucid8_http_subscriptions, and elucid8_http_responses_total by endpoint and code. /health and /metrics answer at once, while a query runs.
Values (GET /values, from 0.19.0, in the Prometheus text format): for each name m that http.values gives, with its query over a box of at most 10,000 cells, m (a sample per cell that is a number, a boolean as 1 or 0, labelled by the query's dimensions), m_timestamp_seconds (each such cell's timestamp, in seconds) and m_cells (the cells by kind: value, eod, error, other for text and lists, and stopped, 1 when a program error stopped the query). Unlike /metrics, it waits its turn: its queries go through the queue with the other requests, so a scrape after an advance sees its data, and last moves as rows arrive. Over standard input, {"op": "values"} gives the same text in the reply's values. A Prometheus scrape job names metrics_path: /values; Seeing your results goes through it with Grafana.
Logs. Each request's log line (§9) begins with the client's address and the endpoint: {"client":"127.0.0.1:53570","endpoint":"POST /query","id":1,"op":"query",…}. A subscription's later answers name the endpoint subscription. Never the token, outcomes or data.
#From a terminal: elucid8 repl
elucid8 repl URL is a prompt for asking a running service for values, in the language's notation, and for watching them change as data arrives. It is a client of the endpoints above and nothing more: it starts no service, and it only asks (data reaches the service through its inputs, as always: files, connectors, programs, POST /inputs/NAME/rows). With a token, give it the file holding it (--token-file FILE), or set ELUCID8_SERVE_TOKEN.
A program that adds up readings (app.el8), its configuration (deploy.json) and three readings (readings.csv):
reading = input("reading", t : inf)
total = reading fby.t (total + next.t reading)
alert = total > 10
{"format": "elucid8-deploy/2", "inputs": {"reading": {"from": "readings.csv", "row": "t"}}}
value
3
4
5
elucid8 serve app.el8 --config deploy.json --http 127.0.0.1:8080
elucid8 repl http://127.0.0.1:8080
elucid8/0.26.0 at http://127.0.0.1:8080/: total, alert; input reading. Type help for commands, quit to leave.
elucid8> total[t = last]
12
elucid8> alert[t = 0..3]
t = 0: false
t = 1: false
t = 2: true
t = 3: eod
elucid8> spark total[t = 0..3]
▁▄█
t from 0 to 3; min 3, max 12; 1 eod (blank)
elucid8> quit
One point's answer is its value; several points' answers name their coordinates, in the query's order. Numbers and booleans are written as CSV writes them, a text as it is, eod as eod, and an Error in words (Error: division by zero). At a terminal an answer shows its first 100 points and says how many more there are; piped, every point is written. ts on adds each answer's timestamp. An invalid query, a program error or a budget running out is said plainly, and the prompt carries on; Ctrl-C during a query cancels it, and Ctrl-C at the prompt leaves.
watch QUERYprints the answer, then, as data reaches the service, the points whose answers changed (or are new to the query, aslastmoves), each with its coordinates, until Ctrl-C, which stops watching and returns to the prompt. Withwatch total[t = last]running, a reading posted by another program (printf '2\n' | curl -s -H 'Content-Type: text/csv' --data-binary @- http://127.0.0.1:8080/inputs/reading/rows) printst = 3: 14.show QUERYasksPOST /player/linkfor a link to the eLucid8 Player showing the query, prints it, and opens it in the browser (not when standard input is piped, or with--no-open). A range of the dimension the value iterates along is the part Play runs through (show heat[time = 0..200]);lastmakes the Player follow new data.spark QUERYdraws an answer in the terminal: a row of numbers (one dimension varying) as a sparkline, a small grid (two varying, at most 60 across and 30 down) as shaded blocks; eod is blank and an Error×. A larger answer is refused, withshowas the way to see it.describelists the program's values with their dimensions, its inputs and their versions, and its dimensions with their kinds;statsthe service's counts;helpthe commands;quit(orexit, or Ctrl-D) leaves.
Piped, the repl reads one query a line and writes the answers, with no prompt and no greeting: printf 'total[t = last]\n' | elucid8 repl http://127.0.0.1:8080 writes 12. It exits with 0; with 2 for a wrong command line; with 3 when the service cannot be reached, refuses the token, or is not elucid8 serve.
Interactive programs plays games and runs a shop counter this way: each move or sale is a row posted to an input, and each answer a query.
#9. Logs
One JSON line per request on standard error, in the order answered, plus a line when the service is ready and when it stops, and one per event:
{"event":"ready","plan":"running-plan.json","runtime":"elucid8/0.8.0","protocol":"elucid8-serve/1"}
{"id":1,"op":"query","query":"running","points":6,"versions":{"x":"d20b5fc4a3d402cb"},"ms":0.014,"evaluations":6,"computed":6,"cacheHits":0,"status":"done"}
{"id":2,"op":"advance","input":"x","version":"7270c6cb167f44ec","added":1,"ms":0.09,"status":"done"}
{"event":"evict","before":1210344,"after":905212,"evicted":2210,"dead":0,"compacted":4410,"records":[6620,12],"ms":1.3}
{"event":"dropped","input":"x","version":"06b4278a9a51d047"}
{"id":5,"op":"reload","plan":"unchanged","changed":[],"cachesDropped":false,"ms":0.34,"status":"done"}
{"id":6,"op":"shutdown","status":"done"}
{"event":"stopped"}
| line | gives |
|---|---|
| a query | the value queried, its number of points, the versions pinned, its time, evaluations, values computed, cache hits and status |
| a subscription's answer | the same, with "op":"subscribe" for its first answer and "op":"subscription" for later ones, and its run |
advance | the input, the newest version, how many versions were added, for rows how many points they listed (rows), how many subscriptions it woke (woke), the time |
reload | whether the plan changed, which bindings changed, whether the caches were dropped, the time |
evict | an eviction pass: the estimate before and after, the entries evicted (and of those, how many no request could use), the entries whose records it compacted, the records alive before and after compacting, the time |
dropped | a version of an input with no holders left, now unavailable |
Logs never hold outcomes, data, the coordinates questions are asked at or environment variables.
#10. Guarantees and limits
- Every answer is a fresh run's answer. The tests send logs of requests (the guide's programs, heat across versions of its data, the linear models, and random programs) through one service, and compare every point with a fresh
elucid8 runof that query alone, under the versions the reply names. Another log mixes queries, advances, reloads and eviction under a tiny budget, including a version that was dropped and then named, and queries sent just before and just after an advance while another query ran. Others follow subscriptions, whose every answer must be a fresh run's, and whosechangedanswers exactly the difference between two fresh runs. - Two ways in. A program talks to the service on its standard input and output, and several clients at once over HTTP (§8). To reach it from another machine, put a proxy that gives TLS in front of it (§8).
- One request at a time. A long query delays the requests behind it, advances, reloads and subscriptions' runs included;
budgetMsandcancelbound that. - Bookkeeping after new data. After each advance the service looks only at the cached values that could have read what changed. When an input gains rows, a cached value found usable before stays usable without its history being checked again, unless it read a point the input did not list in the range where rows were added, or a point a window removed. With a point cache and a subscription at
last, after 10,000 advances of one row each, an advance takes about 0.02 ms and the subscription's run about 0.003 ms; the old versions the cache still reads share the input's data, so memory grows with the rows, not with the versions (measured on an Apple M5 Max, with the client waiting for each answer). A memory budget (§5) bounds what is cached. - Iterations go on from where they were. A value computed by levels along a dimension (an iteration, such as a drawing whose canvas at each turn is the one before with the turn's stroke) keeps its newest levels between requests, without a point cache. A later request computes only the levels above them, as long as every input they read is at the same version, or at one made from it by rows appended after what they read (a later turn). Rows that fill a gap among what they read, a window that drops some of it, a whole new file and a reload make it start again from the beginning. The answers are those a fresh
elucid8 rungives. The Player's drawing at 512 × 384 cells answers each new event in about 2.5 ms in the service, whatever the history (1.5 s after 1,000 events before), and holds two levels of each value of the iteration (measured on an Apple M5 Max). Where a level equals the one before outside a condition (the drawing's canvas outside the stroke), it is computed only in the 64 × 64 tiles the condition may reach and shares the rest with the level before, so a level then costs the cells that may have changed (about 0.1 ms at 1920 × 1080, against 10 ms); the newesthistoryDepthlevels (100 by default, an option) are kept, sharing their unchanged tiles, so a step among them is answered without computing again. - A subscription's changed cells are found cell by cell. With
send: changed, a new answer is compared with the previous one by position when its box is the same, and by each cell's coordinates whenlastmoved it; the cells sent are those whose outcome differs, or that the previous answer did not have. A subscription keeps its previous answer's cells (about 9 bytes a cell for numbers), not a copy of every point as text. The Player's drawing at 512 × 384, followed live at 60 events a second, answers each event in about 5 ms (measured on an Apple M5 Max, the client waiting for each answer). An answer whose box moved is still a whole frame: at 1920 × 1080, 2 million numbers; a client slower than the answers leaves them queued in the service's memory. - Memory. Without a budget, a service with a point cache keeps every entry it computes. With one, the caches stay under it between requests (§5). With a point cache, a request also keeps every value it computes while it runs (its working set, which the budget does not cover), and the service frees what it does not cache when the request ends. Without caches, memory is that of the request running, plus each available version's data.
- The service is local unless it listens over HTTP. Whoever can write to its standard input can query it, advance its data and reload it; over HTTP, whoever holds its token (or, without one, any program on the same machine, §8). The configuration holds no credentials: the token is in a file the configuration or the command line names, and process services read theirs from the variables
envnames (services). - Native only. The WebAssembly module has no
serve; an embedding program keeps the module loaded and callselucid8_runinstead.