Skip to content

Commit

Permalink
Make memory info provider a singleton because we dont want multiple i…
Browse files Browse the repository at this point in the history
…nstances of it
  • Loading branch information
sfc-gh-psaha committed Jun 25, 2024
1 parent fe863eb commit 5d199c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public class MemoryInfoProviderFromRuntime implements MemoryInfoProvider {
private final long maxMemory;
private volatile long totalFreeMemory;
private final ScheduledExecutorService executorService;
private static final long FREE_MEMORY_UPDATE_INTERVAL_MS = 1000;
private static final MemoryInfoProviderFromRuntime INSTANCE = new MemoryInfoProviderFromRuntime(FREE_MEMORY_UPDATE_INTERVAL_MS);

public MemoryInfoProviderFromRuntime(long freeMemoryUpdateIntervalMs) {
private MemoryInfoProviderFromRuntime(long freeMemoryUpdateIntervalMs) {
maxMemory = Runtime.getRuntime().maxMemory();
totalFreeMemory =
Runtime.getRuntime().freeMemory() + (maxMemory - Runtime.getRuntime().totalMemory());
Expand All @@ -35,6 +37,10 @@ private void updateFreeMemory() {
Runtime.getRuntime().freeMemory() + (maxMemory - Runtime.getRuntime().totalMemory());
}

public static MemoryInfoProviderFromRuntime getInstance() {
return INSTANCE;
}

@Override
public long getMaxMemory() {
return maxMemory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class SnowflakeStreamingIngestChannelInternal<T> implements SnowflakeStreamingIn
this.maxMemoryLimitInBytes =
this.owningClient.getParameterProvider().getMaxMemoryLimitInBytes();

this.memoryInfoProvider = new MemoryInfoProviderFromRuntime(insertThrottleIntervalInMs);
this.memoryInfoProvider = MemoryInfoProviderFromRuntime.getInstance();
this.channelFlushContext =
new ChannelFlushContext(
name, dbName, schemaName, tableName, channelSequencer, encryptionKey, encryptionKeyId);
Expand Down

0 comments on commit 5d199c9

Please sign in to comment.