Skip to content

Commit

Permalink
fix bug in Performance Stat
Browse files Browse the repository at this point in the history
  • Loading branch information
fanhualta committed Jul 10, 2019
1 parent dec5e9e commit e3ccc40
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 30 deletions.
6 changes: 3 additions & 3 deletions iotdb/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public class IoTDBConfig {
/**
* Memory allocated for the read process
*/
private long allocateMemoryForWrite;
private long allocateMemoryForWrite = Runtime.getRuntime().maxMemory() * 6 / 10;

/**
* Memoru allocated for the write process
* Memory allocated for the write process
*/
private long allocateMemoryForRead;
private long allocateMemoryForRead = Runtime.getRuntime().maxMemory() * 3 / 10;

/**
* Is dynamic parameter adapter enable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ private IoTDBConstant() {
public static final String USER = "User";
public static final String PRIVILEGE = "Privilege";

public static final String DEFAULT_MEMORY_ALLOCATE_PROPORTION = "6:3:1";
}
21 changes: 12 additions & 9 deletions iotdb/src/main/java/org/apache/iotdb/db/conf/IoTDBDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,19 @@ private void loadProps() {
}

private void initMemoryAllocate(Properties properties){
String memoryAllocateProportion = properties.getProperty("write_read_free_memory_proportion",
IoTDBConstant.DEFAULT_MEMORY_ALLOCATE_PROPORTION);
String[] proportions = memoryAllocateProportion.split(":");
int proportionSum = 0;
for(String proportion:proportions){
proportionSum += Integer.valueOf(proportion.trim());
String memoryAllocateProportion = properties.getProperty("write_read_free_memory_proportion");
if(memoryAllocateProportion != null) {
String[] proportions = memoryAllocateProportion.split(":");
int proportionSum = 0;
for (String proportion : proportions) {
proportionSum += Integer.valueOf(proportion.trim());
}
long maxMemoryAvailable = Runtime.getRuntime().maxMemory();
conf.setAllocateMemoryForWrite(
maxMemoryAvailable * Integer.valueOf(proportions[0].trim()) / proportionSum);
conf.setAllocateMemoryForRead(
maxMemoryAvailable * Integer.valueOf(proportions[1].trim()) / proportionSum);
}
long maxMemoryAvailable = Runtime.getRuntime().maxMemory();
conf.setAllocateMemoryForWrite(maxMemoryAvailable * Integer.valueOf(proportions[0].trim()) / proportionSum);
conf.setAllocateMemoryForRead(maxMemoryAvailable * Integer.valueOf(proportions[1].trim()) / proportionSum);
}

private static class IoTDBDescriptorHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ public class IoTDBConfigDynamicAdapter implements IDynamicAdapter {

// static parameter section

private static final double WRITE_MEMORY_RATIO = 0.8;

private static final double FLUSH_THRESHOLD = 0.2;

/**
* Maximum amount of memory that the Java virtual machine will attempt to use
* Maximum amount of memory allocated for write process.
*/
private static final long MAX_MEMORY_B = (long) (Runtime.getRuntime().maxMemory()
* WRITE_MEMORY_RATIO);
private static final long ALLOCATE_MEMORY_FOR_WRITE = CONFIG.getAllocateMemoryForWrite();

/**
* Metadata size of per timeseries, the default value is 2KB.
Expand Down Expand Up @@ -126,7 +123,7 @@ private int calcuMemTableSize() {
double ratio = CompressionRatio.getInstance().getRatio();
// when unit is byte, it's likely to cause Long type overflow. so use the unit KB.
double a = (long) (ratio * maxMemTableNum);
double b = (long) ((MAX_MEMORY_B - staticMemory) * ratio);
double b = (long) ((ALLOCATE_MEMORY_FOR_WRITE - staticMemory) * ratio);
int times = b > Integer.MAX_VALUE ? 1024 : 1;
b /= times;
double c = (double) CONFIG.getTsFileSizeThreshold() * maxMemTableNum * CHUNK_METADATA_SIZE_B * MManager
Expand All @@ -143,7 +140,7 @@ private int calcuMemTableSize() {
* @return Tsfile threshold
*/
private int calcuTsFileSize(int memTableSize) {
return (int) ((MAX_MEMORY_B - maxMemTableNum * memTableSize - staticMemory) * CompressionRatio
return (int) ((ALLOCATE_MEMORY_FOR_WRITE - maxMemTableNum * memTableSize - staticMemory) * CompressionRatio
.getInstance().getRatio()
* memTableSize / (maxMemTableNum * CHUNK_METADATA_SIZE_B * MManager.getInstance()
.getMaximalSeriesNumberAmongStorageGroups()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,6 @@ public void stop() {
}
stopStatistic();
futureList.clear();
service.shutdownNow();
try {
service.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
LOGGER.error("Performance statistic service could not be shutdown, {}", e.getMessage());
// Restore interrupted state...
Thread.currentThread().interrupt();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class CompressionRatioTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ public void run() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
continue;
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
memTables.remove(memTable);
MemTablePool.getInstance().putBack(memTable, "test case");
Expand Down

0 comments on commit e3ccc40

Please sign in to comment.