Repository navigation
Recommend a memory-backed directory for multiprocess mode - #1269
Open
kevinmingtarja wants to merge 1 commit into
Open
kevinmingtarja wants to merge 1 commit into
kevinmingtarja wants to merge 1 commit into
Conversation
Every metric update in multiprocess mode writes into a memory-mapped file under PROMETHEUS_MULTIPROC_DIR. On a disk-backed filesystem that write can wait in a page fault while the disk is busy, and the thread holds the GIL while it waits, so every thread of the process stops. Say so on the multiprocess page and recommend tmpfs, /dev/shm or a memory-backed emptyDir volume. Signed-off-by: Kevin Mingtarja <kevin.mingtarja@gmail.com>
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.
Add a paragraph to the multiprocess mode page that recommends a memory-backed filesystem for
PROMETHEUS_MULTIPROC_DIR, and says why.Why
In multiprocess mode every metric update is a write into a memory-mapped file. The first write to a page after the kernel has written it back takes a page fault. On ext4 that fault updates the file's modification time, which needs a journal handle. If the journal is full, for example while another process deletes a large directory on the same filesystem, the fault waits.
Python cannot see the wait. The write is a slice assignment into the
mmapobject, and CPython copies the bytes with the GIL held. So one blocked metric update stops every thread of the process, an asyncio event loop included.We hit this in a multi-threaded asyncio server on Kubernetes. Its
/tmpis on the node's disk, as it is for containers by default. Each time a pod holding several hundred thousand small files was removed from the same node, the server's event loop stalled for more than a second insideHistogram.observe().Reproduction
promtest.py(below) starts 16 single-threaded processes. Each one updates a counter, a histogram and a gauge every 5 ms and times the three updates together. Eight of them havePROMETHEUS_MULTIPROC_DIRon the node's disk and eight on a memory-backed volume. While they run, a directory holding 600,000 empty files and 20,000 files of 350 KiB is deleted from the same disk.Linux 6.12, ext4 on a 95 GB cloud disk, Python 3.13, prometheus_client 0.26.0:
Outside the delete, neither group had an update of 20 ms or more.
In the server we traced the same wait with bpftrace. A write fault on one of the
.dbfiles normally takes about 10 microseconds. During the delete the faults took up to 1.8 s, with this kernel stack:Prior art
hsperfdatastatistics file: The Four Month Bug: JVM statistics cause garbage collection pauses and JDK-8076103. The workarounds there are to disable the file or to put it on tmpfs.promtest.py
In our run
/prom-diskand/prom-memwere two volumes of one Kubernetes pod, anemptyDirand anemptyDirwithmedium: Memory. The deleted directory was theemptyDirof a second pod on the same node, removed when that pod was deleted.AI disclosure: I used an AI coding assistant (Claude Code) to help reproduce the stall, trace it, and draft this change and description. I reviewed it.