(loader) Optimize DomainLoaderService for faster startups

Initialization parameters in DomainLoaderService and DomainIdRegistry have been updated to improve performance. This is done by adding sane default sizes to the hash tables involved, reducing GC churn, but also by setting a sensible fetch size to the queries used, and not fetching irrelevant information such as the domain name.
This commit is contained in:
Viktor Lofgren 2023-12-18 13:15:10 +01:00
parent b7ed0ce537
commit d02bed1a55
2 changed files with 5 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import java.util.Map;
/** Maps domain names to domain ids */
public class DomainIdRegistry {
private final Map<String, Integer> domainIds = new HashMap<>();
private final Map<String, Integer> domainIds = new HashMap<>(10_000);
public int getDomainId(String domainName) {
Integer id = domainIds.get(domainName.toLowerCase());

View File

@ -42,12 +42,12 @@ public class DomainLoaderService {
public DomainIdRegistry getOrCreateDomainIds(LoaderInputData inputData)
throws IOException, SQLException
{
Set<String> domainNamesAll = new HashSet<>();
Set<String> domainNamesAll = new HashSet<>(100_000);
DomainIdRegistry ret = new DomainIdRegistry();
try (var conn = dataSource.getConnection();
var selectStmt = conn.prepareStatement("""
SELECT ID, DOMAIN_NAME FROM EC_DOMAIN WHERE DOMAIN_NAME=?
SELECT ID FROM EC_DOMAIN WHERE DOMAIN_NAME=?
""")
) {
@ -70,6 +70,7 @@ public class DomainLoaderService {
}
}
selectStmt.setFetchSize(1000);
for (var domain : domainNamesAll) {
selectStmt.setString(1, domain);
var rs = selectStmt.executeQuery();
@ -133,7 +134,7 @@ public class DomainLoaderService {
return true;
}
private class DomainInserter implements AutoCloseable {
private static class DomainInserter implements AutoCloseable {
private final PreparedStatement statement;
private final int nodeAffinity;