diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/MemoryInfoProviderFromRuntime.java b/src/main/java/net/snowflake/ingest/streaming/internal/MemoryInfoProviderFromRuntime.java index 463527a34..3a09b2a0a 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/MemoryInfoProviderFromRuntime.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/MemoryInfoProviderFromRuntime.java @@ -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()); @@ -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; diff --git a/src/main/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestChannelInternal.java b/src/main/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestChannelInternal.java index 6e8f6109b..0d89b3be8 100644 --- a/src/main/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestChannelInternal.java +++ b/src/main/java/net/snowflake/ingest/streaming/internal/SnowflakeStreamingIngestChannelInternal.java @@ -138,7 +138,7 @@ class SnowflakeStreamingIngestChannelInternal 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);