Skip to content

Commit 9e8d2e9

Browse files
authored
Add offheap memory tracking to Bench YAML reports (#671)
* corrected offheap calculation and add to reported statistics
1 parent b5874e1 commit 9e8d2e9

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/QueryTester.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,23 @@ public List<Metric> run(
9898
diagnostics.capturePostPhaseSnapshot("Query");
9999

100100
// Add memory and disk metrics to results
101-
var systemSnapshot = diagnostics.getLatestSystemSnapshot();
101+
// Get both pre and post snapshots to calculate maximum memory usage
102+
var preSnapshot = diagnostics.getPrePhaseSystemSnapshot();
103+
var postSnapshot = diagnostics.getLatestSystemSnapshot();
102104
var diskSnapshot = diagnostics.getLatestDiskSnapshot();
103105

104-
if (systemSnapshot != null) {
105-
// Max heap usage in MB
106+
if (preSnapshot != null && postSnapshot != null) {
107+
// Calculate max heap usage across pre and post snapshots
108+
long maxHeapUsed = Math.max(preSnapshot.memoryStats.heapUsed,
109+
postSnapshot.memoryStats.heapUsed);
106110
results.add(Metric.of("search.system.max_heap_mb", "Max heap usage (MB)", ".1f",
107-
systemSnapshot.memoryStats.heapUsed / (1024.0 * 1024.0)));
111+
maxHeapUsed / (1024.0 * 1024.0)));
108112

109-
// Max off-heap usage (direct + mapped) in MB
113+
// Calculate max off-heap usage (direct + mapped) across pre and post snapshots
114+
long maxOffHeapUsed = Math.max(preSnapshot.memoryStats.getTotalOffHeapMemory(),
115+
postSnapshot.memoryStats.getTotalOffHeapMemory());
110116
results.add(Metric.of("search.system.max_offheap_mb", "Max offheap usage (MB)", ".1f",
111-
systemSnapshot.memoryStats.getTotalOffHeapMemory() / (1024.0 * 1024.0)));
117+
maxOffHeapUsed / (1024.0 * 1024.0)));
112118
}
113119

114120
if (diskSnapshot != null) {

jvector-examples/src/main/java/io/github/jbellis/jvector/example/benchmarks/diagnostics/BenchmarkDiagnostics.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,20 @@ public SystemMonitor.SystemSnapshot getLatestSystemSnapshot() {
233233
return snapshots.isEmpty() ? null : snapshots.get(snapshots.size() - 1);
234234
}
235235

236+
/**
237+
* Gets the pre-phase system snapshot (second to last), or null if not available
238+
*/
239+
public SystemMonitor.SystemSnapshot getPrePhaseSystemSnapshot() {
240+
// The pre-phase snapshot is the second to last entry in the snapshots list, since the last one is the post-phase snapshot
241+
var numSnapshots = snapshots.size();
242+
if (numSnapshots < 2) {
243+
return null;
244+
} else {
245+
SystemMonitor.SystemSnapshot prePhaseSnapshot = snapshots.get(numSnapshots - 2);
246+
return prePhaseSnapshot;
247+
}
248+
}
249+
236250
/**
237251
* Gets the latest disk usage snapshot, or null if none captured
238252
*/

jvector-examples/yaml-configs/run-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ console:
1717
count: [ visited ] # [visited, expanded, expanded base layer]
1818
accuracy: [ recall ] # [recall, MAP]
1919
metrics:
20-
system: [ max_heap_mb ] # [ max_heap_mb, max_offheap_mb ]
20+
system: [ max_heap_mb, max_offheap_mb ] # [ max_heap_mb, max_offheap_mb ]
2121
# disk: total_file_size_mb # [ total_file_size_mb, file_count ]
2222
# construction: index_build_time_s # [ index_build_time_s, index_quant_time_s, search_quant_time_s ]
2323

0 commit comments

Comments
 (0)