From a53e4fb3d650158b2c2a7b561eac66ad54b36701 Mon Sep 17 00:00:00 2001 From: Mark Wolters Date: Tue, 2 Jun 2026 13:17:39 -0400 Subject: [PATCH] corrected offheap calculation and add to reported statistics --- .../example/benchmarks/QueryTester.java | 18 ++++++++++++------ .../diagnostics/BenchmarkDiagnostics.java | 7 +++++++ jvector-examples/yaml-configs/run-config.yml | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/QueryTester.java b/jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/QueryTester.java index 0c0686578..7eb2d28a5 100644 --- a/jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/QueryTester.java +++ b/jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/QueryTester.java @@ -98,17 +98,23 @@ public List run( diagnostics.capturePostPhaseSnapshot("Query"); // Add memory and disk metrics to results - var systemSnapshot = diagnostics.getLatestSystemSnapshot(); + // Get both pre and post snapshots to calculate maximum memory usage + var preSnapshot = diagnostics.getPrePhaseSystemSnapshot(); + var postSnapshot = diagnostics.getLatestSystemSnapshot(); var diskSnapshot = diagnostics.getLatestDiskSnapshot(); - if (systemSnapshot != null) { - // Max heap usage in MB + if (preSnapshot != null && postSnapshot != null) { + // Calculate max heap usage across pre and post snapshots + long maxHeapUsed = Math.max(preSnapshot.memoryStats.heapUsed, + postSnapshot.memoryStats.heapUsed); results.add(Metric.of("search.system.max_heap_mb", "Max heap usage (MB)", ".1f", - systemSnapshot.memoryStats.heapUsed / (1024.0 * 1024.0))); + maxHeapUsed / (1024.0 * 1024.0))); - // Max off-heap usage (direct + mapped) in MB + // Calculate max off-heap usage (direct + mapped) across pre and post snapshots + long maxOffHeapUsed = Math.max(preSnapshot.memoryStats.getTotalOffHeapMemory(), + postSnapshot.memoryStats.getTotalOffHeapMemory()); results.add(Metric.of("search.system.max_offheap_mb", "Max offheap usage (MB)", ".1f", - systemSnapshot.memoryStats.getTotalOffHeapMemory() / (1024.0 * 1024.0))); + maxOffHeapUsed / (1024.0 * 1024.0))); } if (diskSnapshot != null) { diff --git a/jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/diagnostics/BenchmarkDiagnostics.java b/jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/diagnostics/BenchmarkDiagnostics.java index 587bd2b02..816cd2903 100644 --- a/jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/diagnostics/BenchmarkDiagnostics.java +++ b/jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/diagnostics/BenchmarkDiagnostics.java @@ -233,6 +233,13 @@ public SystemMonitor.SystemSnapshot getLatestSystemSnapshot() { return snapshots.isEmpty() ? null : snapshots.get(snapshots.size() - 1); } + /** + * Gets the pre-phase system snapshot (second to last), or null if not available + */ + public SystemMonitor.SystemSnapshot getPrePhaseSystemSnapshot() { + return snapshots.size() < 2 ? null : snapshots.get(snapshots.size() - 2); + } + /** * Gets the latest disk usage snapshot, or null if none captured */ diff --git a/jvector-examples/yaml-configs/run-config.yml b/jvector-examples/yaml-configs/run-config.yml index 8f9eccf96..ba5ee1077 100644 --- a/jvector-examples/yaml-configs/run-config.yml +++ b/jvector-examples/yaml-configs/run-config.yml @@ -17,7 +17,7 @@ console: count: [ visited ] # [visited, expanded, expanded base layer] accuracy: [ recall ] # [recall, MAP] metrics: - system: [ max_heap_mb ] # [ max_heap_mb, max_offheap_mb ] + system: [ max_heap_mb, max_offheap_mb ] # [ max_heap_mb, max_offheap_mb ] # disk: total_file_size_mb # [ total_file_size_mb, file_count ] # construction: index_build_time_s # [ index_build_time_s, index_quant_time_s, search_quant_time_s ]