Skip to content

Commit 3525cfd

Browse files
Correct memory estimation for MSBFS
1 parent 56986fe commit 3525cfd

File tree

6 files changed

+52
-37
lines changed

6 files changed

+52
-37
lines changed

algo/src/main/java/org/neo4j/gds/msbfs/MSBFSMemoryEstimation.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,36 @@ public final class MSBFSMemoryEstimation {
2929
private MSBFSMemoryEstimation() {}
3030

3131

32-
private static MemoryEstimations.Builder MSBFS(int sourceNodes){
33-
var runnable = MemoryEstimations.builder(MultiSourceBFSRunnable.class).build();
32+
private static MemoryEstimation MSBFSRunnable(boolean seenNext){
33+
var builder = MemoryEstimations.builder(MultiSourceBFSRunnable.class)
34+
.perNode("visits", HugeLongArray::memoryEstimation)
35+
.perNode("visitsNext", HugeLongArray::memoryEstimation)
36+
.perNode("seens", HugeLongArray::memoryEstimation);
3437

35-
var builder = MemoryEstimations.builder(MultiSourceBFSAccessMethods.class)
36-
.perThread("visits", HugeLongArray::memoryEstimation)
37-
.perThread("visitsNext", HugeLongArray::memoryEstimation)
38-
.perThread("seens", HugeLongArray::memoryEstimation)
39-
.perThread("runnable", runnable);
38+
if (seenNext) {
39+
builder.perNode("seenNext", HugeLongArray::memoryEstimation);
40+
}
41+
42+
return builder.build();
43+
44+
}
45+
private static MemoryEstimations.Builder MSBFS(int sourceNodes, boolean seenNext){
46+
47+
var builder = MemoryEstimations.builder(MultiSourceBFSAccessMethods.class);
4048

4149
if (sourceNodes > 0 ) {
4250
builder.fixed("source nodes", Estimate.sizeOfLongArray(sourceNodes));
4351
}
4452

53+
builder.perThread("runnable", MSBFSRunnable(seenNext));
54+
4555
return builder;
4656
}
4757

4858
public static MemoryEstimation MSBFSWithPredecessorStrategy(int sourceNodes){
49-
return MSBFS(sourceNodes)
50-
.perThread("seenNext", HugeLongArray::memoryEstimation)
51-
.build();
59+
return MSBFS(sourceNodes,true).build();
5260
}
5361
public static MemoryEstimation MSBFSWithANPStrategy(int sourceNodes){
54-
return MSBFS(sourceNodes)
55-
.build();
62+
return MSBFS(sourceNodes,false).build();
5663
}
5764
}

algo/src/test/java/org/neo4j/gds/allshortestpaths/AllShortestPathsMemoryEstimateDefinitionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class AllShortestPathsMemoryEstimateDefinitionTest {
2929

3030
@ParameterizedTest
3131
@CsvSource({
32-
"10_000, 1, false, 320",
33-
"10_000, 4, false, 584",
34-
"500_000, 4, false, 584",
35-
"10_000_000, 4, false, 584",
32+
"10_000, 1, false, 24_0296",
33+
"10_000, 4, false, 960_848",
34+
"500_000, 4, false, 48_000_848",
35+
"10_000_000, 4, false, 960_000_848",
3636
"10_000, 1, true, 120_280",
3737
"10_000, 4, true, 480_976",
3838
"500_000, 4, true, 24_000_976",

algo/src/test/java/org/neo4j/gds/closeness/ClosenessCentralityAlgorithmEstimateDefinitionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class ClosenessCentralityAlgorithmEstimateDefinitionTest {
2929

3030
@ParameterizedTest
3131
@CsvSource({
32-
"10_000, 1, 160_456",
33-
"10_000, 4, 160_720",
34-
"500_000, 4, 8_000_720",
35-
"10_000_000, 4, 160_000_720",
36-
"10_000, 2, 160_544",
37-
"10_000, 128, 171_632"
32+
"10_000, 1, 400_432",
33+
"10_000, 4, 1_120_984",
34+
"500_000, 4, 56_000_984",
35+
"10_000_000, 4, 1_120_000_984",
36+
"10_000, 2, 640_616",
37+
"10_000, 128, 30_903_800"
3838
})
3939
void testMemoryEstimation(long nodeCount, int concurrency, long expectedMemory) {
4040
var memoryEstimation = new ClosenessCentralityAlgorithmEstimateDefinition().memoryEstimation();

algo/src/test/java/org/neo4j/gds/harmonic/HarmonicCentralityAlgorithmEstimateDefinitionTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class HarmonicCentralityAlgorithmEstimateDefinitionTest {
2929

3030
@ParameterizedTest
3131
@CsvSource({
32-
"10_000, 1, 80_368",
33-
"10_000, 4, 80_632",
34-
"500_000, 4, 4_000_632",
35-
"10_000_000, 4, 80_000_632",
36-
"10_000, 2, 80_456",
37-
"10_000, 128, 91_544"
32+
"10_000, 1, 320_344",
33+
"10_000, 4, 1_040_896",
34+
"500_000, 4, 52_000_896",
35+
"10_000_000, 4, 1_040_000_896",
36+
"10_000, 2, 560_528",
37+
"10_000, 128, 30_823_712"
3838
})
3939
void testMemoryEstimation(long nodeCount, int concurrency, long expectedMemory) {
4040
var memoryEstimation = new HarmonicCentralityAlgorithmEstimateDefinition().memoryEstimation();

algo/src/test/java/org/neo4j/gds/msbfs/MSBFSMemoryEstimationTest.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ class MSBFSMemoryEstimationTest {
2929

3030
@ParameterizedTest
3131
@CsvSource({
32-
"100,1,0, 328",
33-
"100,1,10, 424",
34-
"100,4,0, 616",
35-
"100,4,10, 712"
32+
"100,1,0, 3496",
33+
"100,1,10, 3592",
34+
"100,4,0, 13768",
35+
"100,4,10, 13864",
36+
"200,1,0, 6696",
37+
"200,1,10, 6792",
38+
"200,4,0, 26568",
39+
"201,4,10, 26792"
3640

3741
})
3842
void shouldWorkForPredecessor(long nodeCount, int concurrency, int sourceNodesSize, long expectedMemory){
@@ -43,10 +47,14 @@ void shouldWorkForPredecessor(long nodeCount, int concurrency, int sourceNodesS
4347

4448
@ParameterizedTest
4549
@CsvSource({
46-
"100,1,0,280",
47-
"100,1,10,376",
48-
"100,4,0,544",
49-
"100,4,10,640"
50+
"100,1,0, 2656",
51+
"100,1,10, 2752",
52+
"100,4,0, 10408",
53+
"100,4,10, 10504",
54+
"200,1,0, 5056",
55+
"200,1,10, 5152",
56+
"200,4,0, 20008",
57+
"200,4,10, 20104"
5058
})
5159
void shouldWorkForANP(long nodeCount, int concurrency, int sourceNodesSize, long expectedMemory){
5260
MemoryEstimationAssert.assertThat(MSBFSMemoryEstimation.MSBFSWithANPStrategy(sourceNodesSize))

doc/modules/ROOT/pages/algorithms/harmonic-centrality.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ YIELD nodeCount, relationshipCount, bytesMin, bytesMax, requiredMemory
274274
[opts="header"]
275275
|===
276276
| nodeCount | relationshipCount | bytesMin | bytesMax | requiredMemory
277-
| 5 | 6 | 672 | 672 | "672 Bytes"
277+
| 5 | 6 | 1416 | 1416 | "1416 Bytes"
278278
|===
279279
--
280280

0 commit comments

Comments
 (0)