-
Notifications
You must be signed in to change notification settings - Fork 143
adding memory and disk usage stats to bench tests #591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MarkWolters
wants to merge
1
commit into
main
Choose a base branch
from
enhanceBenchTests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,13 @@ public class Grid { | |
|
|
||
| private static int diagnostic_level; | ||
|
|
||
| /** | ||
| * Get the index build time for a dataset | ||
| */ | ||
| public static Double getIndexBuildTime(String datasetName) { | ||
| return indexBuildTimes.get(datasetName); | ||
| } | ||
|
|
||
| static void runAll(DataSet ds, | ||
| List<Integer> mGrid, | ||
| List<Integer> efConstructionGrid, | ||
|
|
@@ -158,13 +165,21 @@ static void runOneGraph(List<? extends Set<FeatureId>> featureSets, | |
| DataSet ds, | ||
| Path testDirectory) throws IOException | ||
| { | ||
| // Capture initial memory and disk state | ||
| var diagnostics = new io.github.jbellis.jvector.example.benchmarks.diagnostics.BenchmarkDiagnostics(getDiagnosticLevel()); | ||
| diagnostics.setMonitoredDirectory(testDirectory); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does import not work for this symbol?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not recall why this is fully qualified but I will clean it up |
||
| diagnostics.capturePrePhaseSnapshot("Graph Build"); | ||
|
|
||
| Map<Set<FeatureId>, ImmutableGraphIndex> indexes; | ||
| if (buildCompressor == null) { | ||
| indexes = buildInMemory(featureSets, M, efConstruction, neighborOverflow, addHierarchy, refineFinalGraph, ds, testDirectory); | ||
| } else { | ||
| indexes = buildOnDisk(featureSets, M, efConstruction, neighborOverflow, addHierarchy, refineFinalGraph, ds, testDirectory, buildCompressor); | ||
| } | ||
|
|
||
| // Capture post-build memory and disk state | ||
| diagnostics.capturePostPhaseSnapshot("Graph Build"); | ||
|
|
||
| try { | ||
| for (var cpSupplier : compressionGrid) { | ||
| indexes.forEach((features, index) -> { | ||
|
|
@@ -188,7 +203,7 @@ static void runOneGraph(List<? extends Set<FeatureId>> featureSets, | |
| } | ||
|
|
||
| try (var cs = new ConfiguredSystem(ds, index, cv, featureSetForIndex)) { | ||
| testConfiguration(cs, topKGrid, usePruningGrid, M, efConstruction, neighborOverflow, addHierarchy, benchmarks); | ||
| testConfiguration(cs, topKGrid, usePruningGrid, M, efConstruction, neighborOverflow, addHierarchy, benchmarks, testDirectory); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
@@ -197,6 +212,11 @@ static void runOneGraph(List<? extends Set<FeatureId>> featureSets, | |
| for (var index : indexes.values()) { | ||
| index.close(); | ||
| } | ||
|
|
||
| // Log final diagnostics summary | ||
| if (diagnostic_level > 0) { | ||
| diagnostics.logSummary(); | ||
| } | ||
| } finally { | ||
| for (int n = 0; n < featureSets.size(); n++) { | ||
| Files.deleteIfExists(testDirectory.resolve("graph" + n)); | ||
|
|
@@ -432,13 +452,14 @@ private static void testConfiguration(ConfiguredSystem cs, | |
| int efConstruction, | ||
| float neighborOverflow, | ||
| boolean addHierarchy, | ||
| Map<String, List<String>> benchmarkSpec) { | ||
| Map<String, List<String>> benchmarkSpec, | ||
| Path testDirectory) { | ||
| int queryRuns = 2; | ||
| System.out.format("Using %s:%n", cs.index); | ||
| // 1) Select benchmarks to run. Use .createDefault or .createEmpty (for other options) | ||
|
|
||
| var benchmarks = setupBenchmarks(benchmarkSpec); | ||
| QueryTester tester = new QueryTester(benchmarks); | ||
| QueryTester tester = new QueryTester(benchmarks, testDirectory, cs.ds.name); | ||
|
|
||
| // 2) Setup benchmark table for printing | ||
| for (var topK : topKGrid.keySet()) { | ||
|
|
@@ -563,11 +584,22 @@ public static List<BenchResult> runAllAndCollectResults( | |
| for (Function<DataSet, CompressorParameters> searchCompressor : compressionGrid) { | ||
| Path testDirectory = Files.createTempDirectory("bench"); | ||
| try { | ||
| // Capture initial state | ||
| var diagnostics = new io.github.jbellis.jvector.example.benchmarks.diagnostics.BenchmarkDiagnostics(getDiagnosticLevel()); | ||
| diagnostics.setMonitoredDirectory(testDirectory); | ||
| diagnostics.capturePrePhaseSnapshot("Build"); | ||
|
|
||
| var compressor = getCompressor(buildCompressor, ds); | ||
| var searchCompressorObj = getCompressor(searchCompressor, ds); | ||
| CompressedVectors cvArg = (searchCompressorObj instanceof CompressedVectors) ? (CompressedVectors) searchCompressorObj : null; | ||
| var indexes = buildOnDisk(List.of(features), m, ef, neighborOverflow, addHierarchy, false, ds, testDirectory, compressor); | ||
| ImmutableGraphIndex index = indexes.get(features); | ||
|
|
||
| // Capture post-build state | ||
| diagnostics.capturePostPhaseSnapshot("Build"); | ||
| var buildSnapshot = diagnostics.getLatestSystemSnapshot(); | ||
| var buildDiskSnapshot = diagnostics.getLatestDiskSnapshot(); | ||
|
|
||
| try (ConfiguredSystem cs = new ConfiguredSystem(ds, index, cvArg, features)) { | ||
| int queryRuns = 2; | ||
| List<QueryBenchmark> benchmarks = List.of( | ||
|
|
@@ -578,7 +610,7 @@ public static List<BenchResult> runAllAndCollectResults( | |
| CountBenchmark.createDefault(), | ||
| AccuracyBenchmark.createDefault() | ||
| ); | ||
| QueryTester tester = new QueryTester(benchmarks); | ||
| QueryTester tester = new QueryTester(benchmarks, testDirectory, ds.name); | ||
| for (int topK : topKGrid.keySet()) { | ||
| for (boolean usePruning : usePruningGrid) { | ||
| for (double overquery : topKGrid.get(topK)) { | ||
|
|
@@ -596,11 +628,33 @@ public static List<BenchResult> runAllAndCollectResults( | |
| "overquery", overquery, | ||
| "usePruning", usePruning | ||
| ); | ||
| // Collect all metrics including memory and disk usage | ||
| Map<String, Object> allMetrics = new HashMap<>(); | ||
| for (Metric metric : metricsList) { | ||
| Map<String, Object> metrics = java.util.Map.of(metric.getHeader(), metric.getValue()); | ||
| results.add(new BenchResult(ds.name, params, metrics)); | ||
| allMetrics.put(metric.getHeader(), metric.getValue()); | ||
| } | ||
|
|
||
| // Add build time if available | ||
| if (indexBuildTimes.containsKey(ds.name)) { | ||
| allMetrics.put("Index Build Time", indexBuildTimes.get(ds.name)); | ||
| } | ||
|
|
||
| // Add memory metrics if available | ||
| if (buildSnapshot != null) { | ||
| allMetrics.put("Heap Memory Used (MB)", buildSnapshot.memoryStats.heapUsed / 1024.0 / 1024.0); | ||
| allMetrics.put("Heap Memory Max (MB)", buildSnapshot.memoryStats.heapMax / 1024.0 / 1024.0); | ||
| allMetrics.put("Off-Heap Direct (MB)", buildSnapshot.memoryStats.directBufferMemory / 1024.0 / 1024.0); | ||
| allMetrics.put("Off-Heap Mapped (MB)", buildSnapshot.memoryStats.mappedBufferMemory / 1024.0 / 1024.0); | ||
| allMetrics.put("Total Off-Heap (MB)", buildSnapshot.memoryStats.getTotalOffHeapMemory() / 1024.0 / 1024.0); | ||
| } | ||
|
|
||
| // Add disk metrics if available | ||
| if (buildDiskSnapshot != null) { | ||
| allMetrics.put("Disk Usage (MB)", buildDiskSnapshot.totalBytes / 1024.0 / 1024.0); | ||
| allMetrics.put("File Count", buildDiskSnapshot.fileCount); | ||
| } | ||
| results.add(new BenchResult(ds.name, params, Map.of("Index Build Time", indexBuildTimes.get(ds.name)))); | ||
|
|
||
| results.add(new BenchResult(ds.name, params, allMetrics)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps clarify the unit here, such as getIndexBuildTimeMillis or getIndexBuildTimeSeconds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, I will add that.