Skip to content

Commit

Permalink
Add memory configurable percentage #755
Browse files Browse the repository at this point in the history
  • Loading branch information
diego.salvi committed Aug 27, 2021
1 parent 35b5e87 commit 4619b01
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
26 changes: 22 additions & 4 deletions herddb-core/src/main/java/herddb/core/DBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public class DBManager implements AutoCloseable, MetadataChangeListener {
private long maxLogicalPageSize = ServerConfiguration.PROPERTY_MAX_LOGICAL_PAGE_SIZE_DEFAULT;
private long maxDataUsedMemory = ServerConfiguration.PROPERTY_MAX_DATA_MEMORY_DEFAULT;
private long maxPKUsedMemory = ServerConfiguration.PROPERTY_MAX_PK_MEMORY_DEFAULT;
private double maxDataUsedMemoryPercentage = ServerConfiguration.PROPERTY_MAX_DATA_MEMORY_PERCENTAGE_DEFAULT;
private double maxPKUsedMemoryPercentage = ServerConfiguration.PROPERTY_MAX_PK_MEMORY_PERCENTAGE_DEFAULT;

private boolean clearAtBoot = false;
private boolean haltOnTableSpaceBootError = ServerConfiguration.PROPERTY_HALT_ON_TABLESPACE_BOOT_ERROR_DEAULT;
Expand Down Expand Up @@ -261,6 +263,22 @@ public Thread newThread(final Runnable r) {
ServerConfiguration.PROPERTY_MAX_PK_MEMORY,
ServerConfiguration.PROPERTY_MAX_PK_MEMORY_DEFAULT);

this.maxDataUsedMemoryPercentage = configuration.getDouble(
ServerConfiguration.PROPERTY_MAX_DATA_MEMORY_PERCENTAGE,
ServerConfiguration.PROPERTY_MAX_DATA_MEMORY_PERCENTAGE_DEFAULT);

if (maxDataUsedMemoryPercentage <= 0) {
maxDataUsedMemoryPercentage = ServerConfiguration.PROPERTY_MAX_DATA_MEMORY_PERCENTAGE_DEFAULT;
}

this.maxPKUsedMemoryPercentage = configuration.getDouble(
ServerConfiguration.PROPERTY_MAX_PK_MEMORY_PERCENTAGE,
ServerConfiguration.PROPERTY_MAX_PK_MEMORY_PERCENTAGE_DEFAULT);

if (maxPKUsedMemoryPercentage <= 0) {
maxPKUsedMemoryPercentage = ServerConfiguration.PROPERTY_MAX_PK_MEMORY_PERCENTAGE_DEFAULT;
}

}

public boolean isHaltOnTableSpaceBootError() {
Expand Down Expand Up @@ -403,14 +421,14 @@ public void start() throws DataStorageManagerException, LogNotAvailableException
}
LOGGER.log(Level.INFO, ServerConfiguration.PROPERTY_MEMORY_LIMIT_REFERENCE + "= {0} bytes", Long.toString(maxMemoryReference));

/* If max data memory for pages isn't configured or is too high default it to 0.3 maxMemoryReference */
/* If max data memory for pages isn't configured or is too high default it to a maxMemoryReference percentage */
if (maxDataUsedMemory == 0 || maxDataUsedMemory > maxMemoryReference) {
maxDataUsedMemory = (long) (0.3F * maxMemoryReference);
maxDataUsedMemory = (long) (maxDataUsedMemoryPercentage * maxMemoryReference);
}

/* If max index memory for pages isn't configured or is too high default it to 0.2 maxMemoryReference */
/* If max index memory for pages isn't configured or is too high default it to a maxMemoryReference percentage */
if (maxPKUsedMemory == 0 || maxPKUsedMemory > maxMemoryReference) {
maxPKUsedMemory = (long) (0.2F * maxMemoryReference);
maxPKUsedMemory = (long) (maxPKUsedMemoryPercentage * maxMemoryReference);
}

/* If max used memory is too high lower index and data accordingly */
Expand Down
13 changes: 13 additions & 0 deletions herddb-core/src/main/java/herddb/server/ServerConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ public final class ServerConfiguration {
public static final String PROPERTY_MAX_PK_MEMORY = "server.memory.pk.limit";
public static final long PROPERTY_MAX_PK_MEMORY_DEFAULT = 0L;

/**
* Percentage of maximum memory used for data pages, will be used if {@link PROPERTY_MAX_PK_MEMORY} is not given
*/
public static final String PROPERTY_MAX_DATA_MEMORY_PERCENTAGE = "server.memory.data.percentage";
public static final double PROPERTY_MAX_DATA_MEMORY_PERCENTAGE_DEFAULT = 0.50D;

/**
* Percentage of maximum memory used for primary index pages, will be used if {@link PROPERTY_MAX_DATA_MEMORY} is
* not given
*/
public static final String PROPERTY_MAX_PK_MEMORY_PERCENTAGE = "server.memory.pk.percentage";
public static final double PROPERTY_MAX_PK_MEMORY_PERCENTAGE_DEFAULT = 0.20D;

public static final String PROPERTY_JMX_ENABLE = "server.jmx.enable";
public static final boolean PROPERTY_JMX_ENABLE_DEFAULT = true;

Expand Down

0 comments on commit 4619b01

Please sign in to comment.