Skip to content

Speed up server bootstrap and startup - #8371

Merged
labkey-jeckels merged 11 commits into
developfrom
fb_faster_startup
Nov 25, 2026
Merged

labkey-jeckels merged 11 commits into
developfrom
fb_faster_startup

Conversation

@labkey-jeckels

@labkey-jeckels labkey-jeckels commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Rationale

This PR shortens server bootstrap and routine startup, part of getting TeamCity BVT suites to their first test sooner. Measured speedups for each change are in the PR comments.

Related Pull Requests

Changes

  • Load PostgreSQL foreign-key metadata with a lighter per-table catalog query instead of the JDBC driver's
  • Check for missing database views by name rather than by loading full table metadata
  • Skip the view check and the encryption cipher migration on a new install
  • Initialize audit providers in parallel

Testing

New JdbcMetaDataTest FK equivalence test passed on a local server; new TableXmlUtils.TestCase has not run yet. New ModuleArchiveTestCase re-extraction test, which covers the extraction change in LabKey/server#1562, passed in a standalone JUnit run. Fresh-database bootstraps and routine restarts ran locally without errors.

Tasks

  • Claude Code Review
  • Manual Testing @labkey-adam
  • Test Automation

@labkey-jeckels

Copy link
Copy Markdown
Contributor Author

Speedup: PostgreSQL foreign-key lookup

Fresh-database bootstrap on a local dev server (macOS, 131 modules), same tree with and without the change; JFR socket time on the Module Upgrade thread:

Before After
getImportedKeys socket time 4.01 s (880 calls) 0.05–0.10 s
Column and FK metadata loading 5.02 s 1.02–1.28 s

Per call, the JDBC driver's query costs about 4.2 ms, mostly planning a nine-relation join, against about 0.3 ms for the new query, timed across all 1,837 tables of a populated database. The two queries returned identical rows for every FK in that database. Whole-bootstrap time (49.3 s before, 48.4 s after) was dominated by run-to-run noise in script and getPrimaryKeys time, so the ~3.9 s saving shows most clearly in the socket numbers.

@labkey-jeckels

Copy link
Copy Markdown
Contributor Author

Speedup: startup view check

Routine restarts (no deploy) on a local dev server:

Before After
Core module startup step 2.52–3.14 s (6 runs) 0.71 s (1 run)
DB socket time in checkForMissingDbViews 607 ms 30 ms

About 1.9 s saved per restart. The new check answers the same question (is a view declared in schema.xml missing from the database?) from one list of table names per schema instead of full per-table metadata.

@labkey-jeckels

Copy link
Copy Markdown
Contributor Author

Speedup: parallel audit provider initialization

Local dev server (macOS, 131 modules, 57 audit tables). Times are for the Audit Log startup listener and come from the server log:

Before (serial) After (8 threads)
Audit Log listener, fresh bootstrap 7.55–8.56 s (4 runs, avg 8.0 s) 2.55 s (1 run)
Module Upgrade thread, fresh bootstrap 48.5 s (1 run) 40.5 s (1 run)
Audit Log listener, routine restart 2.83 s (1 run, earlier build) 0.62–0.70 s (11 runs)

About 5.5 s is saved per fresh bootstrap. The rest of the Module Upgrade difference is run-to-run noise in other phases. JFR shows the workers mostly waiting on Postgres, with under 1 s of Java-side contention (per-transaction cache creation and connection checkout), which caps the speedup near 3x rather than 8x. On TeamCity BVT-A the serial listener took 12.5 s (~350 ms per table), so the same ratio would save about 8 s per suite.

@labkey-jeckels
labkey-jeckels marked this pull request as ready for review November 22, 2026 20:29
@labkey-jeckels labkey-jeckels self-assigned this Nov 22, 2026
private static final Logger _log = LogManager.getLogger(TableXmlUtils.class);

// schema.xml-only tableDbType for objects whose type differs between databases; no DatabaseTableType counterpart
private static final String UNKNOWN_TABLE_TYPE = "UNKNOWN";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Now that we only support one database, I think we can get rid of UNKNOWN_TABLE_TYPE. Maybe for a different branch.

@labkey-adam

Copy link
Copy Markdown
Contributor

Manual testing looks good. I started up multiple times on my standard dev database as well as a new bootstrapped database. I compared timings from the very first log line ("Executing...main()") to "Module startup complete". My baseline was two minutes. First startup after building the change showed no improvement (two minutes). All subsequent startups were just under a minute, so twice as fast. Except for a bootstrap startup, which was still fast, at 1:21. No idea why that first startup was slower.

labkey-jeckels added a commit to LabKey/server that referenced this pull request Nov 25, 2026
## Rationale
This PR shortens server startup by cutting time spent in class loading
and module extraction, part of getting TeamCity BVT suites to their
first test sooner. Measured speedups for each change are in the PR
comments. Deploys still rewrite every module archive, so the first
restart after a deploy still checks every module; that build-side cause
is LabKey/internal-issues#1936.

## Related Pull Requests
- LabKey/platform#8371

## Changes
- When the webapp supplies no classes of its own, answer Tomcat's
class-loader lookups without touching the disk
- When a module archive changes, rewrite only the files whose content
changed instead of deleting and re-extracting the whole module
- Extract the largest module archives first so a big one can't start
last and stretch the extraction phase
@labkey-jeckels
labkey-jeckels merged commit 36b9601 into develop Nov 25, 2026
9 checks passed
@labkey-jeckels
labkey-jeckels deleted the fb_faster_startup branch November 25, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants