Force refresh on every dnf run vs scheduled makecache: trade‑off for stale cache control in AlmaLinux?
0 reputation · 19 Sept 2022, 21:45 UTC
0 reputation · 19 Sept 2022, 21:45 UTC
The goal is to keep repository metadata current enough to prevent dependency resolution failures while avoiding unnecessary network traffic caused by frequent cache refreshes.
AlmaLinux inherits DNF’s default metadata_expire of six hours, after which cached data is considered stale. Administrators can either set metadata_expire=0 to force a refresh on every dnf invocation or rely on manual dnf makecache run on a schedule. The uncertainty lies in determining which approach offers a better balance of freshness versus bandwidth consumption under typical workloads and repository sizes.
What is the expected increase in network traffic when metadata_expire=0 is enabled?
How does the frequency of a manual makecache schedule affect the likelihood of encountering stale metadata?
Are there scenarios where a hybrid setting (e.g., a longer metadata_expire combined with occasional makecache) outperforms either extreme?
32775 reputation · 19 Sept 2022, 23:28 UTC
For AlmaLinux, enabling metadata_expire=0 (or using dnf --refresh) forces DNF to download fresh repository metadata on every invocation, guaranteeing zero‑staleness but incurring a download of the full metadata set each time. A scheduled dnf makecache timer updates the metadata at a fixed interval (e.g., every 6 h, 12 h, or daily), trading a bounded staleness window for reduced bandwidth.
metadata_expire (default 6 h).metadata_expire=0 makes every dnf command treat the cache as expired, triggering a refresh.dnf-makecache.timer unit, when enabled, runs dnf makecache on the schedule defined in its timer unit.If each metadata refresh transfers ≈ M bytes, then:
metadata_expire=0 and N DNF runs per day, daily traffic ≈ N × M.Thus the bandwidth saving factor is roughly N ÷ (24/T). For a server that runs DNF only a few times a day (e.g., N = 4) and a 6‑hour timer (T = 6, giving 4 runs/day), the traffic is comparable; for more frequent DNF use (e.g., N = 20) the timer saves about 80 % of the bandwidth.
Staleness risk grows linearly with the timer interval: the chance of encountering a missing or updated package is proportional to how long the metadata lags behind the mirror.
If the repository changes infrequently but occasional bursts of updates occur (e.g., security‑only updates released twice a week), a longer metadata_expire (e.g., 12 h) combined with a weekly dnf makecache run can keep bandwidth low while still catching the bulk of changes. The hybrid approach outperforms pure force‑refresh when:
Conversely, if the repo sees multiple changes per day (e.g., rolling‑release or internal development repos), forcing refresh per run or using a short timer (≤ 2 h) is preferable.
# Check current metadata age stat /var/cache/dnf/metadata_timestamp-* # Force a refresh and see the timestamp update dnf --refresh repolist stat /var/cache/dnf/metadata_timestamp-* # Verify timer status systemctl list-timers --all | grep dnf-makecache
To refine the recommendation, it would help to know the approximate size of the repository metadata you are syncing (M) and how many DNF invocations you expect per day (N).
Use comments to ask for clarification. Post a solution as an answer.
32,775 reputation · 20 Sept 2022, 03:10 UTC
Even when metadata_expire=0 forces DNF to treat the cache as stale on every invocation, DNF does not necessarily re‑download the entire repository metadata set each time. The process works as follows:
repomd.xml (typically a few kilobytes) from the mirror.repomd.xml indicates a change does DNF proceed to fetch the full metadata payload.Consequently, the bandwidth increase per DNF run is closer to the size of repomd.xml plus occasional full metadata pulls, rather than a full‑size download on every command. This nuance means that the traffic penalty of forcing a refresh is often lower than the simple N × M estimate, especially in environments where repository updates are infrequent.