Skip to content

Commit

Permalink
Reduce the default min heap size and remove the default max heap size
Browse files Browse the repository at this point in the history
For historical reasons we were setting the initial heap size to the same
value as the max heap size: 4GiB.
However, based on experimentation, our memory pool usage is only around
512MB for a lightly used ingestion workload.
The cost dynamics of cloud make it more important to set an appropriate
initial heap size and memory management in the JVM has gotten better
over time.

As for the max heap size, OpenJ9 has intelligent defaults when running
within a container, and so we should use those instead of guessing at a
default of our own:
https://www.eclipse.org/openj9/docs/xxusecontainersupport

Signed-off-by: Lee Surprenant <lmsurpre@us.ibm.com>
  • Loading branch information
punktilious authored and lmsurpre committed Oct 6, 2021
2 parents dabafd3 + 08f454a commit 29a9f61
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public void createOrReplaceFunction(String schemaName, String functionName, Supp
try {
runStatement(ddl.toString());
} catch (UndefinedNameException x) {
logger.warning(ddl + "; PROCEDURE not found");
logger.warning(ddl + "; FUNCTION not found");
}
}
super.createOrReplaceFunction(schemaName, functionName, supplier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public class FhirSchemaGenerator {
private static final String ADD_PARAMETER_NAME = "ADD_PARAMETER_NAME";
private static final String ADD_RESOURCE_TYPE = "ADD_RESOURCE_TYPE";
private static final String ADD_ANY_RESOURCE = "ADD_ANY_RESOURCE";
private static final String DELETE_RESOURCE_PARAMETERS = "DELETE_RESOURCE_PARAMETERS";
private static final String ERASE_RESOURCE = "ERASE_RESOURCE";

// The tags we use to separate the schemas
Expand Down Expand Up @@ -441,19 +442,28 @@ public void buildDatabaseSpecificArtifactsDb2(PhysicalDataModel model) {
procedurePrivileges);
pd.addTag(SCHEMA_GROUP_TAG, FHIRDATA_GROUP);

pd = model.addProcedure(this.schemaName,
DELETE_RESOURCE_PARAMETERS,
FhirSchemaVersion.V0020.vid(),
() -> SchemaGeneratorUtil.readTemplate(adminSchemaName, schemaName, ROOT_DIR + DELETE_RESOURCE_PARAMETERS.toLowerCase() + ".sql", null),
Arrays.asList(fhirSequence, resourceTypesTable, allTablesComplete),
procedurePrivileges);
pd.addTag(SCHEMA_GROUP_TAG, FHIRDATA_GROUP);
final ProcedureDef deleteResourceParameters = pd;

pd = model.addProcedure(this.schemaName,
ADD_ANY_RESOURCE,
FhirSchemaVersion.V0001.vid(),
() -> SchemaGeneratorUtil.readTemplate(adminSchemaName, schemaName, ROOT_DIR + ADD_ANY_RESOURCE.toLowerCase() + ".sql", null),
Arrays.asList(fhirSequence, resourceTypesTable, allTablesComplete),
Arrays.asList(fhirSequence, resourceTypesTable, deleteResourceParameters, allTablesComplete),
procedurePrivileges);
pd.addTag(SCHEMA_GROUP_TAG, FHIRDATA_GROUP);

pd = model.addProcedure(this.schemaName,
ERASE_RESOURCE,
FhirSchemaVersion.V0013.vid(),
() -> SchemaGeneratorUtil.readTemplate(adminSchemaName, schemaName, ROOT_DIR + ERASE_RESOURCE.toLowerCase() + ".sql", null),
Arrays.asList(fhirSequence, resourceTypesTable, allTablesComplete),
Arrays.asList(fhirSequence, resourceTypesTable, deleteResourceParameters, allTablesComplete),
procedurePrivileges);
pd.addTag(SCHEMA_GROUP_TAG, FHIRDATA_GROUP);
}
Expand Down Expand Up @@ -486,19 +496,28 @@ public void buildDatabaseSpecificArtifactsPostgres(PhysicalDataModel model) {
Arrays.asList(fhirSequence, resourceTypesTable, allTablesComplete), procedurePrivileges);
fd.addTag(SCHEMA_GROUP_TAG, FHIRDATA_GROUP);

// We currently only support functions with PostgreSQL, although this is really just a procedure
FunctionDef deleteResourceParameters = model.addFunction(this.schemaName,
DELETE_RESOURCE_PARAMETERS,
FhirSchemaVersion.V0020.vid(),
() -> SchemaGeneratorUtil.readTemplate(adminSchemaName, schemaName, ROOT_DIR + DELETE_RESOURCE_PARAMETERS.toLowerCase() + ".sql", null),
Arrays.asList(fhirSequence, resourceTypesTable, allTablesComplete),
procedurePrivileges);
deleteResourceParameters.addTag(SCHEMA_GROUP_TAG, FHIRDATA_GROUP);

fd = model.addFunction(this.schemaName,
ADD_ANY_RESOURCE,
FhirSchemaVersion.V0001.vid(),
() -> SchemaGeneratorUtil.readTemplate(adminSchemaName, schemaName, ROOT_DIR + ADD_ANY_RESOURCE.toLowerCase()
+ ".sql", null),
Arrays.asList(fhirSequence, resourceTypesTable, allTablesComplete), procedurePrivileges);
Arrays.asList(fhirSequence, resourceTypesTable, deleteResourceParameters, allTablesComplete), procedurePrivileges);
fd.addTag(SCHEMA_GROUP_TAG, FHIRDATA_GROUP);

fd = model.addFunction(this.schemaName,
ERASE_RESOURCE,
FhirSchemaVersion.V0013.vid(),
() -> SchemaGeneratorUtil.readTemplate(adminSchemaName, schemaName, ROOT_DIR + ERASE_RESOURCE.toLowerCase() + ".sql", null),
Arrays.asList(fhirSequence, resourceTypesTable, allTablesComplete), procedurePrivileges);
Arrays.asList(fhirSequence, resourceTypesTable, deleteResourceParameters, allTablesComplete), procedurePrivileges);
fd.addTag(SCHEMA_GROUP_TAG, FHIRDATA_GROUP);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,36 +143,8 @@ BEGIN
THEN
-- existing resource, so need to delete all its parameters.
-- TODO patch parameter sets instead of all delete/all insert.
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_str_values WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_number_values WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_date_values WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_latlng_values WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_resource_token_refs WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_quantity_values WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_profiles WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_tags WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_security WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || 'str_values WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || 'date_values WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || 'resource_token_refs WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || 'logical_resource_profiles WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || 'logical_resource_tags WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'DELETE FROM ' || v_schema_name || '.' || 'logical_resource_security WHERE logical_resource_id = ?';
EXECUTE stmt USING v_logical_resource_id;
PREPARE stmt FROM 'CALL ' || v_schema_name || '.delete_resource_parameters(?,?)';
EXECUTE stmt USING p_resource_type, v_logical_resource_id;
END IF; -- end if parameter hash is different
END IF; -- end if existing resource

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
-------------------------------------------------------------------------------
-- (C) Copyright IBM Corp. 2021
--
-- SPDX-License-Identifier: Apache-2.0
-------------------------------------------------------------------------------

-- ----------------------------------------------------------------------------
-- Procedure to delete all the search parameters associated with a resource
--
-- p_logical_resource_id: the id representing the resource for which to delete the parameters
-- ----------------------------------------------------------------------------
( IN p_resource_type VARCHAR( 36 OCTETS),
IN p_logical_resource_id BIGINT)
LANGUAGE SQL
MODIFIES SQL DATA
BEGIN
-- Declare the variables
DECLARE v_schema_name VARCHAR(128 OCTETS) DEFAULT '{{SCHEMA_NAME}}';
DECLARE d_stmt STATEMENT;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_str_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_number_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_date_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_latlng_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_resource_token_refs WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_quantity_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_profiles WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_tags WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_security WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'str_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'date_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'resource_token_refs WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'logical_resource_profiles WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'logical_resource_tags WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'logical_resource_security WHERE logical_resource_id = ?';
EXECUTE d_stmt USING p_logical_resource_id;
END
48 changes: 3 additions & 45 deletions fhir-persistence-schema/src/main/resources/db2/erase_resource.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,51 +61,9 @@ BEGIN
EXECUTE dr_stmt USING v_logical_resource_id;
GET DIAGNOSTICS v_total = ROW_COUNT;

-- Step 3: Delete from All Parameters Tables
PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_str_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_number_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_date_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_latlng_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_resource_token_refs WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_quantity_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_profiles WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_tags WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_security WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'str_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'date_values WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'resource_token_refs WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'logical_resource_profiles WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'logical_resource_tags WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;

PREPARE d_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || 'logical_resource_security WHERE logical_resource_id = ?';
EXECUTE d_stmt USING v_logical_resource_id;
-- Step 3: Delete from all parameters tables
PREPARE d_stmt FROM 'CALL ' || v_schema_name || '.delete_resource_parameters(?,?)';
EXECUTE d_stmt USING p_resource_type, v_logical_resource_id;

-- Step 4: Delete from Logical Resources table
PREPARE dlr_stmt FROM 'DELETE FROM {{SCHEMA_NAME}}.' || p_resource_type || '_LOGICAL_RESOURCES WHERE LOGICAL_RESOURCE_ID = ?';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,38 +122,10 @@ BEGIN

IF o_current_parameter_hash IS NULL OR p_parameter_hash_b64 != o_current_parameter_hash
THEN
-- existing resource, so need to delete all its parameters.
-- existing resource, so need to delete all its parameters (select because it's a function, not a procedure)
-- TODO patch parameter sets instead of all delete/all insert.
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_str_values WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_number_values WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_date_values WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_latlng_values WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_resource_token_refs WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_quantity_values WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_profiles WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_tags WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || p_resource_type || '_security WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || 'str_values WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || 'date_values WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || 'resource_token_refs WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || 'logical_resource_profiles WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || 'logical_resource_tags WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'DELETE FROM ' || v_schema_name || '.' || 'logical_resource_security WHERE logical_resource_id = $1'
USING v_logical_resource_id;
EXECUTE 'SELECT {{SCHEMA_NAME}}.delete_resource_parameters($1, $2)'
USING p_resource_type, v_logical_resource_id;
END IF; -- end if check parameter hash
END IF; -- end if existing resource

Expand Down
Loading

0 comments on commit 29a9f61

Please sign in to comment.