Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<pid>/status`, `/proc/<pid>/io`, `/proc/<pid>/stat`, the cgroup
Expand Down
12 changes: 12 additions & 0 deletions scripts/vm-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions src/quantization_comparison_bench/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 "
Expand Down
32 changes: 32 additions & 0 deletions tests/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading