When to defer an import: CPU, memory and time budgets alongside a live website
An independent weather-import admission table covering memory, CPU, time and site response. Why a favourable observation does not reserve resources.
A new forecast release is available, but the same server also runs a website. An import can be correct in its data and unsuitable in its timing: readers are waiting for responses, memory is occupied, and too little time remains before the next heavy task. An explained decision to defer the work, while keeping the previous forecast available, can then be the useful outcome.
We will examine a small independent admission mechanism. It compares prepared observations with explicit limits and returns reasons for refusal. The Python example uses invented data and has no server access. An experiment with a real import alongside a website still needs to be performed: a local decision table helps test the policy, but does not measure a safe workload.
A launch must compete for a defined budget
The question “is there free memory?” is too narrow. We need to know how much this particular import will add, how much capacity we leave for the site, where temporary files reside, and when we stop accepting new work. A small-region profile does not justify running a large area with the same estimate. A change in fields, grid or decoder can also invalidate an earlier profile.
In a real system, the profile should come from repeatable runs in a comparable environment. For the example, we will specify it manually: an additional memory peak of 600 MiB, possible site growth of 300 MiB, and 100 MiB of allowance for observation uncertainty. Admission requires at least 1000 MiB of available headroom. This is teaching arithmetic, not a measured recommendation for a server.
Headroom cannot come solely from the host’s overall figure. It must account for the actual limits of the process and shared ancestors, as well as already accounted needs of neighbouring tasks. The cgroup v2 documentation describes hierarchical limits, CPU bandwidth, memory.high and memory.max. The first memory boundary introduces pressure and slowing; the second can lead to OOM inside the group when usage cannot be reduced. They are not two names for “free RAM”.
In our input, memory_headroom_mib already contains the prepared result of that external assessment. Current usage is accounted for in this headroom, but the specified 600, 300 and 100 MiB have not yet been deducted: we check them exactly once. The code does not calculate headroom from /proc or prove the collector correct. This is a significant boundary of the example: a good comparison function cannot repair an observation collected for the wrong process group.
CPU, waiting and the site’s response are different signals
A low CPU percentage does not mean that the import will receive the resource it needs. A process may be waiting for disk or constrained by a quota. The prepared cpu_budget_cores value in the exercise represents a budget after effective limits and neighbouring tasks have been accounted for; it is not the result of subtracting host utilisation from one hundred percent.
CPUQuota= in systemd sets an upper bound relative to the time of one CPU: 100% does not mean the whole multicore server. MemoryHigh= and MemoryMax= control the corresponding cgroup boundaries. Before using them, check the installed version’s capabilities and the process’s actual placement; configuration text alone does not prove a limit is in effect.
PSI describes time lost to resource shortages. The some metric represents time during which at least some tasks were waiting for a resource; avg10 gives a short averaged trend. It supplements utilisation measurements, but does not establish a universal safe-import threshold.
The reader’s outcome also needs its own measurement: page latency and error rate. In our table, even ample available memory does not admit work when p95 exceeds its defined limit. An empty or very small request sample also does not become evidence of a healthy site. A real experiment must define the routes, measurement window, quantile calculation and adequate sample size in advance.
A small table makes the policy visible
The teaching profile is named teaching-small-v1. Its contents are not intended to change under the same name. All numbers below were chosen for clear boundary checks; they do not describe a real site’s load.
| Observation | Admission condition in the exercise |
|---|---|
| Age of the oldest component | At most 5 s |
| Memory headroom | At least 600 + 300 + 100 = 1000 MiB |
| Disk headroom | At least 1000 + 500 = 1500 MiB |
| Prepared CPU budget | At least 0.75 CPU |
| Time window | At least 900 + 120 = 1020 s |
CPU some avg10 |
At most 10% |
I/O some avg10 |
At most 5% |
| Site sample | At least 50 requests |
| Site p95 | At most 250 ms |
| Site error rate | At most 1% |
The limits must also be verified, another writer must not be active, and there must be no memory alarm. Positive flags are inputs to a trusted call, not evidence on their own. A collector must derive them from specific observations.
The time window includes 900 seconds of planned execution and 120 seconds for controlled shutdown. Having that window does not guarantee that the work will finish in time. An execution deadline and a safe way to stop the import are still required. Temporary space also covers the candidate and the necessary allowance; a retained previous snapshot cannot be silently deleted merely to pass the capacity check.
Three answers without a hidden launch
The evaluate function returns invalid, defer or eligible. The first answer means that the observation does not meet the contract: a field is missing, a quantity is represented as a string instead of a number, the profile is unknown, or a value has an unsupported form. defer means a readable document with unfavourable conditions. eligible means only that no obstacle was found in this observation.
Numeric zero is allowed where meaningful: zero errors or zero PSI stalls is not a missing value. Boolean False in place of a number, NaN, infinity and a negative age are rejected. A missing metric is not replaced with zero. Upper bounds are checked before large integers are converted to floating-point representation.
The memory and time decisions read literally in code:
memory_short = observation["memory_headroom_mib"] < 600 + 300 + 100
window_short = observation["window_remaining_s"] < 900 + 120
The function does not modify its input, start a process or write scheduler state. The returned reasons have stable names. If CPU is insufficient and I/O pressure is too high at the same time, the answer includes both reasons; fixing the first does not hide the second.
Which boundaries could be checked locally
Independent function tests and eight scenarios written in advance were executed. The baseline observation passes, but always returns capacity_reserved: false. Reducing memory to 999 MiB gives defer; exactly 1000 MiB is admitted if the other conditions are favourable. The equivalent time-window boundary is 1019 versus 1020 seconds.
| Change from the baseline observation | Observed answer |
|---|---|
| No change | eligible, no reservation |
| Memory of 999 MiB | defer: memory |
| Window of 1019 s | defer: window |
| Oldest observation is 6 s old | defer: stale |
| p95 is 251 ms | defer: site_latency |
| Another writer is already running | defer: writer_busy |
| Only 49 site requests are available | defer: site_sample |
| CPU of 0.74 and I/O pressure of 6% | Two reasons: cpu_budget, io_pressure |
These results confirm the pure function’s behaviour on synthetic input. They measure nothing about a decoder’s actual memory consumption or the import’s effect on readers. Two calls can receive the same favourable document and both return eligible. This simple case demonstrates why a check is not a reservation.
Work remains between admission and completion
The launcher must coordinate its own writers, collect fresh observations immediately before work, and monitor execution. A lock coordinates only participants that respect it. It does not stop another service or an operator from consuming memory between two measurements.
If the site slows down during an import, the next heavy step should be deferred, and the current step completed or cancelled according to a defined protocol. Child processes must be joined and resources closed. A cancellation signal without verified completion can leave work still consuming the budget. The old weather snapshot remains available; a partially prepared candidate is not activated just to record success.
A real experiment needs the same import profile and comparable site load before, during and after the run. It should examine insufficient resources before starting, deterioration after starting, a time limit being exceeded, and an observer failure. Acceptance criteria and stopping conditions come first; only then can the resulting numbers be compared. The absence of a failure in one short run does not establish a server’s capacity.
Deferred work must leave a visible intent, a reason and a bounded retry policy. When deferral continues for a long time, the age of the available forecast must be monitored separately: cautious resource use does not make old data fresh. Decisions about a larger server, a smaller area or a different schedule depend on both debts — unfinished work and an ageing result. An admission mechanism is useful when it explains both and does not turn an observation into a promise of resources.