Repository navigation
Conversation
…he trial by trial An ended job whose folder's time moved while its files did not was decoded, found current, and written again in full only to store its new head. Its head is now noted in jobs/index.json beside the signature it was seen with, which load_jobs already writes once, and the next process answers the job by it without stating its trials. The cache file is left as it was. A cache write no longer deep-copies every trial with dataclasses.asdict, nor encodes through json.dump's Python encoder: each trial is encoded by the C encoder and written in turn, so one trial's text is in memory at a time. The file's shape is unchanged; caches written before are read as they are.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #311
What
An ended job is answered by its head. When only its folder's time moved (an entry added or removed beside the trials),
load_jobdecoded the cache, found the signature current and wrote the whole job again to store the new head. The head is now noted in the workspace'sjobs/index.json, beside the signature it was seen with: the entry of an ended job gainssignatureandhead.load_jobsalready reads that file once and writes it once, so a moved head costs one small write for the workspace and none for the job. The next process answers the job by the head in the index when the cache's signature is the one noted there, without stating its trials. The cache file keeps the head it was written with, and either answers.A cache write no longer goes through
dataclasses.asdict, which deep-copied every trial, nor throughjson.dump, whose encoder is pure Python. Each trial is encoded byjson.dumps(the C encoder) and written in turn, so one trial's text is in memory at a time, as before.job_to_dictreads the fields without copying them: no field of aJoborTrialholds a dataclass.The cache file's shape is unchanged (its keys are the same;
trialsnow comes last injob), soworkspace.SCHEMAstays as it is and caches written before are read as they are.Touches
backend:
app/nullius/workspace.py(job_to_dict,_write_cache,_note_in_index,_noted_head,load_job). Tests:app/tests/test_workspace.py.Verified
Backend suite: 3220 tests in 169 modules, OK. Route suite: 719 tests in 61 modules, OK. Both in a rootless
python:3.12container, on main with perf(web): count a closed workspace's runs from counts kept on disk #314.New tests:
workspace._signaturespatched to fail; the index holds the job's signature and head;job_from_dict(job_to_dict(job)), and its cache read back, written withasdictpatched to fail;asdictandjson.dump) is read by its head and equals the job;The first
/workspacesafter a start, on profiles from the generator in Workspaces: counting a workspace's runs decodes every trial of every job #309 (W workspaces of 20 ended Harbor jobs of 50 trials), main and this branch alternated on the same profile, 3 fresh server processes each in one rootlesspython:3.12container, timed with curl inside it, median and range:parse.SCHEMAchangeA moved head now takes 1.48 times the start with current caches at 20x20x50 (1.35 at 100x20x50). What it still spends beyond that is stating each job's trials once to confirm its signature, as the head alone cannot. The start with no caches is about twice as fast. The issue's 15.0 s for that start was measured before perf(runs): compute the catalogue signature once per load, not once per trial #313.
cProfile of the first request at 20x20x50 (werkzeug
ProfilerMiddleware, which slows it down), measured before perf(web): count a closed workspace's runs from counts kept on disk #314 merged, so line numbers are those of that build:Risk
The head in the index is trusted only with the signature it was noted with, and the head is taken before the signature, as the cache's own head is: a job changed after its head was taken moves its head again. It shares the head's existing limit: a file changed inside a trial folder of an ended job and nothing else is not seen; Refresh reads every job again. A lost or older index (an older version rewriting it without the new keys) costs one statement of the trials per job, never a wrong answer. The cache's format is unchanged, so an upgrade costs nothing and a downgrade reads the caches as written. The index's new keys are ignored by its other readers. Undone by a revert; the extra keys in
index.jsonare harmless and Refresh removes the file.