Skip to content

Commit 8445b08

Browse files
jt2594838MyXOF
authored andcommitted
Write memory control (#196)
1 parent 56a7976 commit 8445b08

32 files changed

+1781
-40
lines changed

iotdb/conf/iotdb-engine.properties

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ period_time_for_merge_in_second=7200
5656
# default value is +08:00
5757
# eg. +08:00, -01:00
5858
time_zone=+08:00
59+
60+
# if memory used by write reaches this threshold, auto flush will be triggered, percentile of Java heap memory
61+
mem_threshold_warning=0.8
5962

60-
# if memory used by write reaches this threshold, auto flush will be triggered, in byte, 8GB by default
61-
mem_threshold_warning=23622320128
62-
63-
# if memory used by write reaches this threshold, write will be blocked, in byte, 16GB by default
64-
mem_threshold_dangerous=25769803776
63+
# if memory used by write reaches this threshold, write will be blocked, percentile of Java heap memory
64+
mem_threshold_dangerous=0.9
6565

6666
# every such interval, a thread will check if memory exceeds mem_threshold_warning
6767
# if do exceed, auto flush will be triggered, in ms, 1s by default
@@ -72,8 +72,25 @@ mem_monitor_interval=1000
7272
# 1 is JVMMemController, which use JVM heap memory as threshold.
7373
mem_controller_type=1
7474

75+
# When a bufferwrite's metadata size (in byte) exceed this, the bufferwrite is forced closed.
76+
bufferwrite_meta_size_threshold=209715200
77+
78+
# When a bufferwrite's file size (in byte) exceed this, the bufferwrite is forced closed.
79+
bufferwrite_file_size_threshold=2147483648
80+
81+
# When a overflow's metadata size (in byte) exceed this, the bufferwrite is forced closed.
82+
overflow_meta_size_threshold=209715200
83+
84+
# When a overflow's file size (in byte) exceed this, the bufferwrite is forced closed.
85+
overflow_file_size_threshold=2147483648
86+
87+
# How many thread can concurrently flush. When <= 0, use CPU core number.
88+
concurrent_flush_thread=0
89+
90+
7591
# Statistics Monitor configuration
7692
# default monitor is enabled, and write statistics info to IoTDB every 5 seconds
7793
# Choose to change the back_loop_period >= 1 seconds
7894
enable_stat_monitor = true
79-
back_loop_period = 5
95+
back_loop_period = 5
96+

iotdb/conf/iotdb-env.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@ fi
110110
IOTDB_DERBY_OPTS="-Dderby.stream.error.field=cn.edu.tsinghua.iotdb.auth.dao.DerbyUtil.DEV_NULL"
111111

112112
IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Xloggc:${IOTDB_HOME}/gc.log -XX:+PrintGCDateStamps -XX:+PrintGCDetails"
113+
113114
IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Xms${HEAP_NEWSIZE}"
114115
IOTDB_JMX_OPTS="$IOTDB_JMX_OPTS -Xmx${MAX_HEAP_SIZE}"

iotdb/conf/logback.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
<logger name="cn.edu.tsinghua.iotdb.service" level="info" />
9898
<logger name="cn.edu.tsinghua.iotdb.conf" level="info" />
99-
<root level="ERROR">
99+
<root level="info">
100100
<appender-ref ref="FILEDEBUG" />
101101
<appender-ref ref="FILEINFO" />
102102
<appender-ref ref="FILEWARN" />

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>cn.edu.tsinghua</groupId>
66
<artifactId>IoTDB</artifactId>
7-
<version>0.3.1</version>
7+
<version>0.4.0</version>
88
<packaging>jar</packaging>
99

1010
<name>IoTDB</name>
@@ -23,7 +23,7 @@
2323
<dependency>
2424
<groupId>cn.edu.tsinghua</groupId>
2525
<artifactId>iotdb-jdbc</artifactId>
26-
<version>0.3.1</version>
26+
<version>0.4.0</version>
2727
</dependency>
2828
<dependency>
2929
<groupId>cn.edu.fudan.dsm</groupId>

src/main/java/cn/edu/tsinghua/iotdb/conf/TsFileDBConstant.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ public class TsFileDBConstant {
44
public static final String ENV_FILE_NAME = "iotdb-env";
55
public static final String IOTDB_CONF = "IOTDB_CONF";
66
public static final String GLOBAL_DB_NAME = "IoTDB";
7-
public static final String VERSION = "0.3.1";
7+
public static final String VERSION = "0.4.0";
88
public static final String REMOTE_JMX_PORT_NAME = "com.sun.management.jmxremote.port";
99
public static final String TSFILEDB_LOCAL_JMX_PORT_NAME = "iotdb.jmx.local.port";
1010
public static final String TSFILEDB_REMOTE_JMX_PORT_NAME = "iotdb.jmx.remote.port";
1111
public static final String SERVER_RMI_ID = "java.rmi.server.randomIDs";
1212
public static final String RMI_SERVER_HOST_NAME = "java.rmi.server.hostname";
1313
public static final String JMX_REMOTE_RMI_PORT = "com.sun.management.jmxremote.rmi.port";
14+
15+
public static final long GB = 1024 * 1024 * 1024L;
16+
public static final long MB = 1024 * 1024L;
17+
public static final long KB = 1024L;
18+
19+
public static final long MEM_THRESHOLD_WARNING_DEFAULT = 8 * GB;
20+
public static final long MEM_THRESHOLD_DANGEROUS_DEFAULT = 16 * GB;
21+
1422
public static final String IOTDB_HOME = "IOTDB_HOME";
23+
1524
}

src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBConfig.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,50 @@ public class TsfileDBConfig {
117117
public DateTimeZone timeZone = DateTimeZone.getDefault();
118118

119119
/**
120+
* BufferWriteProcessor and OverflowProcessor will immediately flush if this threshold is reached.
121+
*/
122+
public long memThresholdWarning = (long) (0.8 * Runtime.getRuntime().maxMemory());
123+
124+
/**
125+
* No more insert is allowed if this threshold is reached.
126+
*/
127+
public long memThresholdDangerous = (long) (0.9 * Runtime.getRuntime().maxMemory());
128+
129+
/**
130+
* MemMonitorThread will check every such interval. If memThresholdWarning is reached, MemMonitorThread
131+
* will inform FileNodeManager to flush.
132+
*/
133+
public long memMonitorInterval = 1000; // in ms
134+
135+
/**
136+
* Decide how to control memory used by inserting data.
137+
* 0 is RecordMemController, which count the size of every record (tuple).
138+
* 1 is JVMMemController, which use JVM heap memory as threshold.
139+
*/
140+
public int memControllerType = 1;
141+
142+
/**
143+
* When a bufferwrite's metadata size (in byte) exceed this, the bufferwrite is forced closed.
144+
*/
145+
public long bufferwriteMetaSizeThreshold = 200 * 1024 * 1024L;
146+
147+
/**
148+
* When a bufferwrite's file size (in byte) exceed this, the bufferwrite is forced closed.
149+
*/
150+
public long bufferwriteFileSizeThreshold = 2 * 1024 * 1024 * 1024L;
151+
152+
/**
153+
* When a overflow's metadata size (in byte) exceed this, the overflow is forced closed.
154+
*/
155+
public long overflowMetaSizeThreshold = 200 * 1024 * 1024L;
156+
157+
/**
158+
* When a overflow's file size (in byte) exceed this, the overflow is forced closed.
159+
*/
160+
public long overflowFileSizeThreshold = 2 * 1024 * 1024 * 1024L;
161+
162+
163+
/*
120164
* The statMonitor's BackLoop period, 5s is enough
121165
*/
122166
public int backLoopPeriod = 5;
@@ -129,6 +173,7 @@ public class TsfileDBConfig {
129173
* the maximum number of writing instances existing in same time.
130174
*/
131175

176+
132177
public TsfileDBConfig() {}
133178

134179
public void updateDataPath() {

src/main/java/cn/edu/tsinghua/iotdb/conf/TsfileDBDescriptor.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.InputStream;
88
import java.util.Properties;
99

10+
import cn.edu.tsinghua.iotdb.engine.memcontrol.BasicMemController;
1011
import org.joda.time.DateTimeZone;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
@@ -87,6 +88,25 @@ private void loadProps() {
8788
conf.periodTimeForFlush = Long.parseLong(properties.getProperty("period_time_for_flush_in_second", conf.periodTimeForFlush+"").trim());
8889
conf.periodTimeForMerge = Long.parseLong(properties.getProperty("period_time_for_merge_in_second", conf.periodTimeForMerge+"").trim());
8990

91+
conf.memThresholdWarning = (long) (Runtime.getRuntime().maxMemory() * Double.parseDouble(properties.getProperty("mem_threshold_warning", conf.memThresholdWarning+"").trim()) );
92+
conf.memThresholdDangerous = (long) (Runtime.getRuntime().maxMemory() * Double.parseDouble(properties.getProperty("mem_threshold_dangerous", conf.memThresholdDangerous+"").trim()));
93+
94+
conf.memMonitorInterval = Long.parseLong(properties.getProperty("mem_monitor_interval", conf.memMonitorInterval+"").trim());
95+
96+
conf.memControllerType = Integer.parseInt(properties.getProperty("mem_controller_type", conf.memControllerType+"").trim());
97+
conf.memControllerType = conf.memControllerType >= BasicMemController.CONTROLLER_TYPE.values().length ? 0 : conf.memControllerType;
98+
99+
conf.bufferwriteMetaSizeThreshold = Long.parseLong(properties.getProperty("bufferwrite_meta_size_threshold", conf.bufferwriteMetaSizeThreshold + "").trim());
100+
conf.bufferwriteFileSizeThreshold = Long.parseLong(properties.getProperty("bufferwrite_file_size_threshold", conf.bufferwriteFileSizeThreshold + "").trim());
101+
102+
conf.overflowMetaSizeThreshold = Long.parseLong(properties.getProperty("overflow_meta_size_threshold", conf.overflowMetaSizeThreshold + "").trim());
103+
conf.overflowFileSizeThreshold = Long.parseLong(properties.getProperty("overflow_file_size_threshold", conf.overflowFileSizeThreshold + "").trim());
104+
105+
if(conf.memThresholdWarning <= 0)
106+
conf.memThresholdWarning = TsFileDBConstant.MEM_THRESHOLD_WARNING_DEFAULT;
107+
if(conf.memThresholdDangerous < conf.memThresholdWarning)
108+
conf.memThresholdDangerous = Math.max(conf.memThresholdWarning, TsFileDBConstant.MEM_THRESHOLD_DANGEROUS_DEFAULT);
109+
90110
conf.concurrentFlushThread = Integer.parseInt(properties.getProperty("concurrent_flush_thread", conf.concurrentFlushThread + ""));
91111
if(conf.concurrentFlushThread <= 0)
92112
conf.concurrentFlushThread = Runtime.getRuntime().availableProcessors();

src/main/java/cn/edu/tsinghua/iotdb/engine/Processor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ public boolean equals(Object obj) {
155155
*/
156156
public abstract boolean canBeClosed();
157157

158+
public abstract void flush() throws IOException;
159+
158160
/**
159161
* Close the processor.<br>
160162
* Notice: Thread is not safe
@@ -163,4 +165,6 @@ public boolean equals(Object obj) {
163165
* @throws ProcessorException
164166
*/
165167
public abstract void close() throws ProcessorException;
168+
169+
public abstract long memoryUsage();
166170
}

0 commit comments

Comments
 (0)