Skip to content

CMR-11641: Reduce heap per granule umm_json search response - #2554

Open
daniel-zamora wants to merge 8 commits into
masterfrom
CMR-11641
Open

daniel-zamora wants to merge 8 commits into
masterfrom
CMR-11641

Conversation

@daniel-zamora

@daniel-zamora daniel-zamora commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Overview

What is the objective?

A page_size=2000 umm_json granule search decoded every UMM-G document into maps, re-encoded the whole page, then copied the body twice more to hash it, holding several times the response size in heap. Its metadata-db read ran every 200-granule chunk at once, each inserting into a temp table inside its own transaction, so one page took 10 Oracle sessions and 10 commits. Concurrent requests like this exhaust search heap and Oracle connections.

What are the changes?

  • Search copies stored UMM JSON into umm_json responses token by token instead of decoding and re-encoding it.
    • JSON content is unchanged.
    • Key order inside umm now follows the stored document, so response bytes and Content-MD5/Content-SHA1 values can differ from before.
    • The body's took no longer includes decode time.
  • Content-MD5 and Content-SHA1 are digested in chunks instead of from two full copies of the body; values are unchanged.
  • metadata-db reads concept revisions with bind-list selects instead of inserting into get_concepts_work_area inside a transaction, so reads no longer generate undo, redo or commits.
    • Bind lists are padded to 8 or 64 items, so each table keeps at most two cursors per statement shape.
  • New CMR_PARALLEL_CHUNK_THREADS (default 2) caps how many chunks one fetch reads at once. A 2000-concept fetch now holds 2 connections instead of 10; a single large page can be slightly slower.
  • New CMR_DB_MAX_POOL_SIZE (default 100) and CMR_DB_CONNECTION_WAIT_TIMEOUT (default 600 s); defaults are unchanged.
    • A max below 5 lowers the minimum pool size to match.
    • A max of 0 or less fails startup.
    • Documented in oracle-lib/README.md.
  • Fixes a race in generic-association-test, which passed only when the post-update searches read stale index data.

What areas of the application does this impact?

  • search-app: umm_json results for granules, collections, variables, services, tools, subscriptions and generics
  • common-app-lib: response hash headers for every app using add-body-hashes
  • metadata-db-app: Oracle concept reads, used by metadata-db, search and bootstrap
  • oracle-lib: connection pool settings for every app
  • system-int-test

Required Checklist

  • New and existing unit and int tests pass locally and remotely
  • clj-kondo has been run locally and all errors in changed files are corrected
  • I have commented my code, particularly in hard-to-understand areas
  • I have made changes to the documentation (if necessary)
  • My changes generate no new warnings

Additional Checklist

  • I have removed unnecessary/dead code and imports in files I have changed
  • I have cleaned up integration tests by doing one or more of the following:
    • migrated any are2 tests to are3 in files I have changed
    • de-duped, consolidated, removed dead int tests
    • transformed applicable int tests into unit tests
    • reduced number of system state resets by updating fixtures. Ex) (use-fixtures :each (ingest/reset-fixture {})) to be :once instead of :each

@codecov-commenter

codecov-commenter commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 39.78495% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.62%. Comparing base (30ced1d) to head (e8a130d).

Files with missing lines Patch % Lines
...b-app/src/cmr/metadata_db/data/oracle/concepts.clj 18.42% 31 Missing ⚠️
...p/src/cmr/metadata_db/services/concept_service.clj 33.33% 10 Missing ⚠️
...-app-lib/src/cmr/common_app/api/request_logger.clj 64.70% 0 Missing and 6 partials ⚠️
metadata-db-app/src/cmr/metadata_db/config.clj 50.00% 0 Missing and 1 partial ⚠️
metadata-db-app/src/cmr/metadata_db/system.clj 0.00% 1 Missing ⚠️
...results_handlers/generics_json_results_handler.clj 0.00% 1 Missing ⚠️
...lts_handlers/granules_umm_json_results_handler.clj 0.00% 1 Missing ⚠️
...lts_handlers/services_umm_json_results_handler.clj 0.00% 1 Missing ⚠️
...andlers/subscriptions_umm_json_results_handler.clj 0.00% 1 Missing ⚠️
...esults_handlers/tools_umm_json_results_handler.clj 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2554      +/-   ##
==========================================
+ Coverage   54.60%   54.62%   +0.02%     
==========================================
  Files        1049     1049              
  Lines       73929    73971      +42     
  Branches     2451     2458       +7     
==========================================
+ Hits        40368    40406      +38     
+ Misses      31245    31239       -6     
- Partials     2316     2326      +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

(let [md5 (MessageDigest/getInstance "MD5")
sha1 (MessageDigest/getInstance "SHA-1")
length (.length text)
buffer (char-array (min length 8192))]

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.

It may be worth making the chunk length a constant instead of using a literal here.

(concat concept-id-revision-id-tuples [:transaction? false])))

(def ^:private max-in-list-size
"Most items in one IN list."

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.

A nit, but it is a little awkward as written. Maybe Maximum number of items in one IN list.?

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.

3 participants