From 7913dc2595322df9fc652194cad4e98e558ebdb3 Mon Sep 17 00:00:00 2001 From: Ewa Szyszka Date: Tue, 20 Oct 2026 18:03:44 +0200 Subject: [PATCH] Measure the qdrant process, not the container entrypoint shell The image entrypoint forks qdrant, so the container's main PID is a bash wrapper with one thread. vm-env.sh and the runner's refresh now pick the process named qdrant from the container cgroup, and the telemetry check refuses a PID whose comm is not qdrant. Co-Authored-By: Claude Fable 5.1 --- docs/vm.md | 4 ++- scripts/vm-env.sh | 12 +++++++ .../telemetry.py | 21 ++++++++++++ tests/test_telemetry.py | 32 +++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/docs/vm.md b/docs/vm.md index 16d56c4..acabaa3 100644 --- a/docs/vm.md +++ b/docs/vm.md @@ -47,7 +47,9 @@ through a comparison. source scripts/vm-env.sh # from the repository root, container running ``` -The script resolves the container ID, its process ID, its cgroup v2 path, and +The script resolves the container ID, the `qdrant` process ID inside it (the +image entrypoint is a shell wrapper, which is not the process to measure), its +cgroup v2 path, and the storage bind mount, exports `QDRANT_CONTAINER_ID`, `QDRANT_PID`, `QDRANT_CGROUP_PATH`, and `QDRANT_STORAGE_PATH`, and checks that this account can read `/proc//status`, `/proc//io`, `/proc//stat`, the cgroup diff --git a/scripts/vm-env.sh b/scripts/vm-env.sh index 8aa78a5..6583ce6 100755 --- a/scripts/vm-env.sh +++ b/scripts/vm-env.sh @@ -36,6 +36,18 @@ qbench_env() { fi local cgroup cgroup="/sys/fs/cgroup$(awk -F: '$1 == "0" {print $3}' "/proc/$pid/cgroup")" + # The image entrypoint is a shell that forks qdrant; measure the qdrant + # process itself, not the wrapper. + local candidate + for candidate in $(cat "$cgroup/cgroup.procs"); do + if [ "$(cat "/proc/$candidate/comm" 2>/dev/null)" = "qdrant" ]; then + pid="$candidate" + fi + done + if [ "$(cat "/proc/$pid/comm" 2>/dev/null)" != "qdrant" ]; then + echo "Could not find a qdrant process in $cgroup" >&2 + return 1 + fi export QDRANT_URL="${QDRANT_URL:-http://127.0.0.1:6333}" export QDRANT_CONTAINER_ID="$container" export QDRANT_PID="$pid" diff --git a/src/quantization_comparison_bench/telemetry.py b/src/quantization_comparison_bench/telemetry.py index 9ea6acc..c4406b4 100644 --- a/src/quantization_comparison_bench/telemetry.py +++ b/src/quantization_comparison_bench/telemetry.py @@ -82,11 +82,23 @@ def refresh_targets() -> dict[str, str]: cgroup = f"/sys/fs/cgroup{path}" if not cgroup: raise RuntimeError("Could not resolve a cgroup v2 path for the container") + pid = qdrant_process(Path(cgroup)) os.environ["QDRANT_PID"] = pid os.environ["QDRANT_CGROUP_PATH"] = cgroup return {"QDRANT_PID": pid, "QDRANT_CGROUP_PATH": cgroup} +def qdrant_process(cgroup: Path) -> str: + """The qdrant process inside the container cgroup, not its entrypoint shell.""" + for candidate in (cgroup / "cgroup.procs").read_text().split(): + try: + if (Path("/proc") / candidate / "comm").read_text().strip() == "qdrant": + return candidate + except OSError: + continue + raise RuntimeError(f"No qdrant process found in {cgroup}") + + def check_telemetry(memory_limit_bytes: int | None) -> dict[str, Any]: """Require readable VM telemetry sources and the expected cgroup limit.""" missing = [name for name in TELEMETRY_VARIABLES if not os.environ.get(name)] @@ -115,6 +127,15 @@ def check_telemetry(memory_limit_bytes: int | None) -> dict[str, Any]: problems.append(f"{path}: {type(error).__name__}: {error}") if not (storage / "collections").is_dir(): problems.append(f"{storage}/collections is not a readable directory") + try: + comm = (Path("/proc") / pid / "comm").read_text().strip() + if comm != "qdrant": + problems.append( + f"QDRANT_PID={pid} is {comm!r}, not the qdrant process; " + "re-source scripts/vm-env.sh" + ) + except OSError as error: + problems.append(f"/proc/{pid}/comm: {type(error).__name__}: {error}") if problems: raise RuntimeError( "Telemetry sources are not readable by this account:\n " diff --git a/tests/test_telemetry.py b/tests/test_telemetry.py index 89c3907..e5d78db 100644 --- a/tests/test_telemetry.py +++ b/tests/test_telemetry.py @@ -46,3 +46,35 @@ def test_summary_reports_hardware_means_or_none() -> None: assert group["mean_cpu_per_query"] == 20.0 assert group["mean_vector_io_read_per_query"] == 200.0 assert group["mean_payload_io_read_per_query"] is None + + +def test_qdrant_process_skips_the_entrypoint_shell(tmp_path, monkeypatch) -> None: + from pathlib import Path + + from quantization_comparison_bench import telemetry + + proc = tmp_path / "proc" + for pid, comm in (("10", "bash"), ("11", "qdrant")): + (proc / pid).mkdir(parents=True) + (proc / pid / "comm").write_text(comm + "\n") + cgroup = tmp_path / "cgroup" + cgroup.mkdir() + (cgroup / "cgroup.procs").write_text("10\n11\n") + real_path = telemetry.Path + + def fake_path(*parts): + path = real_path(*parts) + return ( + proc / path.relative_to("/proc") if str(path).startswith("/proc") else path + ) + + monkeypatch.setattr(telemetry, "Path", fake_path) + assert telemetry.qdrant_process(cgroup) == "11" + (cgroup / "cgroup.procs").write_text("10\n") + try: + telemetry.qdrant_process(cgroup) + except RuntimeError: + pass + else: + raise AssertionError("expected RuntimeError without a qdrant process") + assert Path # keep import used