Skip to content

Commit afe30b8

Browse files
committed
better auto size for druid.server.maxSize if druid.segmentCache.virtualStorage=true
1 parent 284d048 commit afe30b8

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

server/src/main/java/org/apache/druid/client/DruidServerConfig.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.druid.java.util.common.HumanReadableBytes;
2828
import org.apache.druid.java.util.common.HumanReadableBytesRange;
2929
import org.apache.druid.segment.loading.SegmentLoaderConfig;
30+
import org.apache.druid.utils.RuntimeInfo;
3031

3132
import javax.validation.constraints.NotNull;
3233
import java.util.Set;
@@ -35,6 +36,9 @@
3536
*/
3637
public class DruidServerConfig
3738
{
39+
private static final long VIRTUAL_CAPACITY_PER_GIB_OF_HEAP = HumanReadableBytes.parse("15TiB");
40+
private static final long ONE_GIB = HumanReadableBytes.parse("1GiB");
41+
3842
@JsonProperty
3943
@HumanReadableBytesRange(min = 0)
4044
private HumanReadableBytes maxSize = HumanReadableBytes.ZERO;
@@ -51,21 +55,34 @@ public class DruidServerConfig
5155
"druid.metadata.storage.connector.password",
5256
"password", "key", "token", "pwd");
5357

58+
private final RuntimeInfo runtimeInfo;
5459
private SegmentLoaderConfig segmentLoaderConfig;
5560

5661
// Guice inject added here to properly bind this dependency into its dependents such as StatusResource
5762
@Inject
5863
@JsonCreator
5964
public DruidServerConfig(
65+
@JacksonInject RuntimeInfo runtimeInfo,
6066
@JacksonInject SegmentLoaderConfig segmentLoaderConfig
6167
)
6268
{
6369
this.segmentLoaderConfig = segmentLoaderConfig;
70+
this.runtimeInfo = runtimeInfo;
6471
}
6572

73+
/**
74+
* The maximum size in bytes a data node advertises itself as having available to serve data. If not set explicitly,
75+
* this value is computed. By default this value is computed using {@link SegmentLoaderConfig#getCombinedMaxSize()}
76+
* which is the total physical capacity of the segment storage locations. If the data node is using virtual storage
77+
* mode, the default is instead computed based on an assumption that ~1G of heap is "plenty" to be able to serve ~50k
78+
* segments, using ~300M segment size as the conversion to storage space translates to ~15T of segments per 1G of heap
79+
*/
6680
public long getMaxSize()
6781
{
6882
if (maxSize.equals(HumanReadableBytes.ZERO)) {
83+
if (segmentLoaderConfig.isVirtualStorage()) {
84+
return VIRTUAL_CAPACITY_PER_GIB_OF_HEAP * (runtimeInfo.getMaxHeapSizeBytes() / ONE_GIB);
85+
}
6986
return segmentLoaderConfig.getCombinedMaxSize();
7087
}
7188
return maxSize.getBytes();

server/src/test/java/org/apache/druid/client/DruidServerConfigTest.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
import org.apache.druid.guice.GuiceInjectors;
2929
import org.apache.druid.initialization.Initialization;
3030
import org.apache.druid.jackson.DefaultObjectMapper;
31+
import org.apache.druid.java.util.common.HumanReadableBytes;
3132
import org.apache.druid.segment.loading.SegmentLoaderConfig;
3233
import org.apache.druid.segment.loading.StorageLocationConfig;
34+
import org.apache.druid.utils.RuntimeInfo;
3335
import org.junit.Assert;
3436
import org.junit.Before;
3537
import org.junit.Rule;
@@ -83,10 +85,33 @@ public void testCombinedSize()
8385
final StorageLocationConfig locationConfig2 = new StorageLocationConfig(testSegmentCacheDir2, 20000000000L, null);
8486
locations.add(locationConfig1);
8587
locations.add(locationConfig2);
86-
DruidServerConfig druidServerConfig = new DruidServerConfig(new SegmentLoaderConfig().withLocations(locations));
88+
DruidServerConfig druidServerConfig = new DruidServerConfig(new RuntimeInfo(), new SegmentLoaderConfig().withLocations(locations));
8789
Assert.assertEquals(30000000000L, druidServerConfig.getMaxSize());
8890
}
8991

92+
@Test
93+
public void testComputedVirtualSize()
94+
{
95+
RuntimeInfo runtimeInfo = new RuntimeInfo()
96+
{
97+
@Override
98+
public long getMaxHeapSizeBytes()
99+
{
100+
return HumanReadableBytes.parse("3GiB");
101+
}
102+
};
103+
SegmentLoaderConfig segmentLoaderConfig = new SegmentLoaderConfig()
104+
{
105+
@Override
106+
public boolean isVirtualStorage()
107+
{
108+
return true;
109+
}
110+
};
111+
DruidServerConfig druidServerConfig = new DruidServerConfig(runtimeInfo, segmentLoaderConfig);
112+
Assert.assertEquals(HumanReadableBytes.parse("45TiB"), druidServerConfig.getMaxSize());
113+
}
114+
90115
@Test
91116
public void testServerMaxSizePrecedence() throws Exception
92117
{

0 commit comments

Comments
 (0)