Skip to content
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

Slow DB select concept by uri #1082

Closed
rkorytkowski opened this issue Nov 5, 2021 · 9 comments
Closed

Slow DB select concept by uri #1082

rkorytkowski opened this issue Nov 5, 2021 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@rkorytkowski
Copy link
Contributor

DB is reporting a lot of queries like this to be slow:
2021-11-05 11:00:11 UTC:10.1.11.104(36992):postgres@postgres:[3082]:LOG: duration: 628517.541 ms statement: SELECT "concepts"."id", "concepts"."public_access", "concepts"."created_at", "concepts"."updated_at", "concepts"."created_by_id", "concepts"."updated_by_id", "concepts"."is_active", "concepts"."extras", "concepts"."uri", "concepts"."version", "concepts"."released", "concepts"."retired", "concepts"."is_latest_version", "concepts"."name", "concepts"."full_name", "concepts"."default_locale", "concepts"."supported_locales", "concepts"."website", "concepts"."description", "concepts"."external_id", "concepts"."concept_class", "concepts"."datatype", "concepts"."comment", "concepts"."parent_id", "concepts"."versioned_object_id", "concepts"."mnemonic" FROM "concepts" WHERE ("concepts"."is_latest_version" AND "concepts"."uri"::text LIKE '%/orgs/Regenstrief-Institute/sources/LOINC/concepts/LP427294-6/%') ORDER BY "concepts"."id" ASC LIMIT 1

We need to fix finding by URI. I recall a similar issue was fixed in the past. Is this a regression? @snyaggarwal

@rkorytkowski rkorytkowski added the bug Something isn't working label Nov 5, 2021
@rkorytkowski
Copy link
Contributor Author

I couldn't quickly track down where in code this query gets executed, but I manually enabled full-text search modules on staging: pg_trgm and btree_gist. I've also added index using those with:
CREATE INDEX concepts_uri_id_gin ON concepts USING gist (uri gist_trgm_ops, id) WHERE is_latest_version;

It fixed the query time to be a few hundred ms instead of minutes.

I consider it to be a temporary fix. We need to put these changes in code as well as try to find the DB query and fix it not to use LIKE if not needed.

@rkorytkowski
Copy link
Contributor Author

The problematic query might be coming from process_hierarchy_for_concept_version...

@rkorytkowski
Copy link
Contributor Author

Note that I needed to clear up queues on staging. Many of process_hierarchy_for_concept_version has not been completed. They blocked pretty much all exports. We need to be more careful with deployments that might affect normal operation. Especially long running tasks should be assigned to dedicated workers.

snyaggarwal added a commit to OpenConceptLab/oclapi2 that referenced this issue Nov 8, 2021
@snyaggarwal
Copy link
Contributor

@rkorytkowski this query was used in populating hierarchy. I have changed the query to use exact match so now rather than LIKE it will use uri=.

@snyaggarwal snyaggarwal self-assigned this Nov 8, 2021
@snyaggarwal
Copy link
Contributor

@rkorytkowski Hierarchy processing async tasks are now moved to concurrent queue.

@rkorytkowski
Copy link
Contributor Author

@snyaggarwal thanks! Could you please add a few lines of description on the hierarchy processing tasks. What are they doing and when are they executed?

@rkorytkowski
Copy link
Contributor Author

Is there a way to enable DB extensions from django?

snyaggarwal added a commit to OpenConceptLab/oclapi2 that referenced this issue Nov 8, 2021
@snyaggarwal
Copy link
Contributor

@rkorytkowski Yes you can create db extensions from django, its documented here

rkorytkowski added a commit to OpenConceptLab/oclapi2 that referenced this issue Nov 9, 2021
@rkorytkowski
Copy link
Contributor Author

rkorytkowski commented Nov 9, 2021

@snyaggarwal Thanks! Added in OpenConceptLab/oclapi2@904904a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants