Repository navigation
CMR-11641: Reduce heap per granule umm_json search response #2554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daniel-zamora
wants to merge
8
commits into
master
Choose a base branch
from
CMR-11641
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+272
−77
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2913ec3
CMR-11641: digest response bodies in chunks
daniel-zamora fe692a2
CMR-11641: copy umm json into search responses without decoding
daniel-zamora 1be81ff
CMR-11641: read concepts by bind list instead of the temp table
daniel-zamora 768653e
CMR-11641: cap concurrent chunk reads per concept fetch
daniel-zamora c95ecf1
CMR-11641: make oracle pool size and wait timeout configurable
daniel-zamora 693cdf4
CMR-11641: fix racy generic association test after updates
daniel-zamora e8a130d
CMR-11641: accept pool sizes below 5 and fail startup on non-positive…
daniel-zamora 0b283dd
CMR-11641: name hash chunk length and reword IN list docstring
daniel-zamora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,37 +179,49 @@ | |
| ;; we want the temp table to persist for the main select | ||
| (concat concept-id-revision-id-tuples [:transaction? false]))) | ||
|
|
||
| (def ^:private max-in-list-size | ||
| "Most items in one IN list." | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A nit, but it is a little awkward as written. Maybe |
||
| 64) | ||
|
|
||
| (defn- in-list-batches | ||
| "Splits items into batches of at most max-in-list-size, padding each with its last item to | ||
| either 8 or max-in-list-size items." | ||
| [items] | ||
| (for [batch (partition-all max-in-list-size items) | ||
| :let [size (count batch) | ||
| padded-size (if (<= size 8) 8 max-in-list-size)]] | ||
| ;; Each list length is a separate cursor whose shared pool memory grows ~3 KB per item, so keep two short lengths. | ||
| (concat batch (repeat (- padded-size size) (last batch))))) | ||
|
|
||
| (defn- in-list-placeholders | ||
| "Returns n comma separated copies of placeholder." | ||
| [n placeholder] | ||
| (string/join "," (repeat n placeholder))) | ||
|
|
||
| (defn get-latest-concept-id-revision-id-tuples | ||
| "Finds the latest pairs of concept id and revision ids for the given concept ids. If no revisions | ||
| exist for a given concept id it will not be returned." | ||
| [db concept-type provider concept-ids] | ||
| (let [start (System/currentTimeMillis)] | ||
| (j/with-db-transaction | ||
| [conn db] | ||
| ;; use a temporary table to insert our values so we can use a join to | ||
| ;; pull everything in one select | ||
| (apply j/insert! conn | ||
| "get_concepts_work_area" | ||
| ["concept_id"] | ||
| ;; set :transaction? false since we are already inside a transaction, and | ||
| ;; we want the temp table to persist for the main select | ||
| (concat (map vector concept-ids) [:transaction? false])) | ||
| ;; pull back all revisions of each concept-id and then take the latest | ||
| ;; instead of using group-by in SQL | ||
| (let [table (tables/get-table-name provider concept-type) | ||
| stmt (su/build (select [:c.concept-id :c.revision-id] | ||
| (from (as (keyword table) :c) | ||
| (as :get-concepts-work-area :t)) | ||
| (where `(and (= :c.concept-id :t.concept-id))))) | ||
| cid-rid-maps (su/query conn stmt) | ||
| concept-id-to-rev-id-maps (map #(hash-map (:concept_id %) (long (:revision_id %))) | ||
| cid-rid-maps) | ||
| latest (apply merge-with safe-max {} | ||
| concept-id-to-rev-id-maps) | ||
| concept-id-revision-id-tuples (seq latest) | ||
| latest-time (- (System/currentTimeMillis) start)] | ||
| (debug (format "Retrieving latest revision-ids took [%d] ms" latest-time)) | ||
| concept-id-revision-id-tuples)))) | ||
| (let [start (System/currentTimeMillis) | ||
| table (tables/get-table-name provider concept-type) | ||
| cid-rid-maps (j/with-db-connection | ||
| [conn db] | ||
| (doall | ||
| (mapcat (fn [batch] | ||
| (su/query conn (into [(format "SELECT concept_id, revision_id FROM %s WHERE concept_id IN (%s)" | ||
| table (in-list-placeholders (count batch) "?"))] | ||
| batch))) | ||
| (in-list-batches concept-ids)))) | ||
| ;; pull back all revisions of each concept-id and then take the latest | ||
| ;; instead of using group-by in SQL | ||
| concept-id-to-rev-id-maps (map #(hash-map (:concept_id %) (long (:revision_id %))) | ||
| cid-rid-maps) | ||
| latest (apply merge-with safe-max {} | ||
| concept-id-to-rev-id-maps) | ||
| concept-id-revision-id-tuples (seq latest) | ||
| latest-time (- (System/currentTimeMillis) start)] | ||
| (debug (format "Retrieving latest revision-ids took [%d] ms" latest-time)) | ||
| concept-id-revision-id-tuples)) | ||
|
|
||
| (defn validate-concept-id-native-id-not-changing | ||
| "Validates that the concept-id native-id pair for a concept being saved is not changing. This | ||
|
|
@@ -370,23 +382,21 @@ | |
| (defn get-concepts | ||
| [db concept-type provider concept-id-revision-id-tuples] | ||
| (if (pos? (count concept-id-revision-id-tuples)) | ||
| (let [start (System/currentTimeMillis)] | ||
| (j/with-db-transaction | ||
| (let [start (System/currentTimeMillis) | ||
| provider-id (:provider-id provider) | ||
| table (tables/get-table-name provider concept-type)] | ||
| ;; No temp table insert or transaction, so reads generate no undo or redo and need no commit. | ||
| (j/with-db-connection | ||
| [conn db] | ||
| ;; use a temporary table to insert our values so we can use a join to | ||
| ;; pull everything in one select | ||
| (save-concepts-to-tmp-table conn concept-id-revision-id-tuples) | ||
|
|
||
| (let [provider-id (:provider-id provider) | ||
| table (tables/get-table-name provider concept-type) | ||
| stmt (su/build (select [:c.*] | ||
| (from (as (keyword table) :c) | ||
| (as :get-concepts-work-area :t)) | ||
| (where `(and (= :c.concept-id :t.concept-id) | ||
| (= :c.revision-id :t.revision-id))))) | ||
|
|
||
| result (doall (map (partial db-result->concept-map concept-type conn provider-id) | ||
| (su/query conn stmt))) | ||
| (let [concepts-by-tuple (into {} | ||
| (for [batch (in-list-batches concept-id-revision-id-tuples) | ||
| row (su/query conn (into [(format "SELECT * FROM %s WHERE (concept_id, revision_id) IN (%s)" | ||
| table (in-list-placeholders (count batch) "(?,?)"))] | ||
| (apply concat batch))) | ||
| :let [concept (db-result->concept-map concept-type conn provider-id row)]] | ||
| [[(:concept-id concept) (:revision-id concept)] concept])) | ||
| ;; One result per requested tuple, duplicates included, for get-concepts' count check. | ||
| result (doall (keep concepts-by-tuple concept-id-revision-id-tuples)) | ||
| millis (- (System/currentTimeMillis) start)] | ||
| (debug (format "Getting [%d] concepts took [%d] ms" (count result) millis)) | ||
| result))) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.