Skip to content

[TASK-6241] Cache ES ingestion when ingesting usage - #6276

Merged
TeddyCr merged 7 commits into
open-metadata:mainfrom
Beetelbrox:task-6241/cache-es-searches-when-ingesting-usage
Jul 22, 2022
Merged

TeddyCr merged 7 commits into
open-metadata:mainfrom
Beetelbrox:task-6241/cache-es-searches-when-ingesting-usage

Conversation

@Beetelbrox

@Beetelbrox Beetelbrox commented Jul 22, 2022 •

Copy link
Copy Markdown
Contributor

Describe your changes :

As explained on #6241, we've identified that the database usage ingestion does a very large amount of repeated requests to elastisearch and the backend tables for every query/table processed. This PR is a first effort to improve usage ingestion performance by implementing caches/checks in three stages of the process:

  • metadata_usage & table_mixin: For each table, avoid ingesting the same query more than once as it will add no new information and most of the repetaed queries are created by previous stages in the process.
  • sql_usage cache the result of search_table_entities that does one query to ES and potentially many to backend and was one of the main sources of the slowdown. I wasn't able to find a nice place to put the cache due to the way the code is structured so I ended up creating it as a module-level variable. This is far from ideal but for a nicer setup we'll need to do some restructuring.

We did some experiments to evaluate the impact in performance and obtained the results below. Note that to reduce variability we extracted an entire day's worth of queries (~52.5k queries, 57 MB) from RS into a csv file and loaded them from there. All runs below include the sql parsing step which was not optimized:

Not optimized

  • 1000 records, no optimization -> 88.63s user 5.92s system 32% cpu 4:53.97 total
  • 5000 records, no optimization -> 676.88s user 12.21s system 59% cpu 19:25.03 total
  • 10000 records, no optimization -> 1276.32s user 21.37s system 60% cpu 35:47.41 total
    Optimized
  • 1000 records, optimized -> 33.79s user 1.01s system 54% cpu 1:03.41 total
  • 5000 records, optimized -> 357.55s user 2.50s system 79% cpu 7:32.33 total
  • 10000 record, optimized -> 566.22s user 4.54s system 75% cpu 12:34.00 total

image

The chart above suggests that the imroved version has a lower complexity, although due to the many parts involved in the execution of each iteration of the ingestion this might be difficult to measure.

There's still plenty of room for improvement as the ones propoed are quite hamfisted and we could greatly reduce the amount of records we generate ourselves but it's a good indicator of how things can improve.

Type of change :

  • [] Bug fix
  • Improvement
  • [] New feature
  • [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] Documentation

Frontend Preview (Screenshots) :

N/A

Checklist:

  • I have read the CONTRIBUTING document.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • All new and existing tests passed.

Reviewers

@open-metadata/ingestion

@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 12:50 Inactive
@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 12:50 Inactive
@github-actions

Copy link
Copy Markdown
Contributor

The Python checkstyle failed.

Please run make py_format in the root of your repository and commit the changes to this PR.
You can also use pre-commit to automate the Python code formatting.

You can install the pre-commit hooks with make install_test precommit_install.

@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 13:32 Inactive
@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 13:32 Inactive
@cypress

cypress Bot commented Jul 22, 2022 •

Copy link
Copy Markdown



Test summary

47 • 0 • 3 • 0


Run details

Project openmetadata
Status Passed
Commit 87a96f5
Started Jul 22, 2022 8:43 PM
Ended Jul 22, 2022 8:54 PM
Duration 11:45 💡
OS Linux Ubuntu - 20.04
Browser Chrome 103

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@pmbrull pmbrull linked an issue Jul 22, 2022 that may be closed by this pull request
@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 17:41 Inactive
@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 17:41 Inactive
@pmbrull

pmbrull commented Jul 22, 2022

Copy link
Copy Markdown
Member

Many thanks for this @Beetelbrox, really enjoying our conversations around this and we truly appreciate the time and effort you're investing ❤️

The PR looks great, let's merge it in after adding the LRU cache as discussed 🚀

@harshach

Copy link
Copy Markdown
Collaborator

Thanks a lot @Beetelbrox this is great!!

@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 19:31 Inactive
@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 19:31 Inactive
@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 19:32 Inactive
@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 19:32 Inactive
@TeddyCr

TeddyCr commented Jul 22, 2022

Copy link
Copy Markdown
Collaborator

@Beetelbrox thank you for the awesome PR 🙏. Would you be able to fix the code smell. After that we can merge it. 🚀

@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 20:20 Inactive
@Beetelbrox
Beetelbrox temporarily deployed to cypress July 22, 2022 20:20 Inactive
@sonarqubecloud

Copy link
Copy Markdown

[open-metadata-ingestion] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

96.1% 96.1% Coverage
0.0% 0.0% Duplication

@TeddyCr TeddyCr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 🚀

@TeddyCr
TeddyCr merged commit 756dae5 into open-metadata:main Jul 22, 2022
pmbrull pushed a commit to pmbrull/OpenMetadata that referenced this pull request Jul 27, 2022
* Cache ingestion

* Uncomment secrets manager

* Fix experiment stuff

* Fix style

* Add LRU cache

* Add tests

* Fix code smell
pmbrull pushed a commit to pmbrull/OpenMetadata that referenced this pull request Jul 27, 2022
* Cache ingestion

* Uncomment secrets manager

* Fix experiment stuff

* Fix style

* Add LRU cache

* Add tests

* Fix code smell
pmbrull added a commit that referenced this pull request Jul 27, 2022
* Fix #5890 - Add health endpoint (#6030)

* Add health endpoint

* Replace rest_status for health

* Update message

* [ISSUE-6162] Upgrade RS SQL statement query (#6188)

* Upgrade RS SQL statement query

* Fix query, remove dupes

* [ISSUE-6162] Escape wildcards on revised RS query (#6200)

[ISSUE-6162] Escape wildcards on revised RS query (#6200)

* Remove retry in ES query (#6191)

Remove retry in ES query (#6191)

* min/max

* Fix  #6161 - kill endpoint for Airflow REST (#6244)

Fix  #6161 - kill endpoint for Airflow REST (#6244)

* Fixes #6031 & #6236 -- Handle binary field & UUID when ingesting sample data (#6233)

Fixes #6031 & #6236 -- Handle binary field & UUID when ingesting sample data (#6233)

* overwrite default sum function to add super for BQ overflow (#6252)

* [TASK-6241] Cache ES ingestion when ingesting usage (#6276)

* Cache ingestion

* Uncomment secrets manager

* Fix experiment stuff

* Fix style

* Add LRU cache

* Add tests

* Fix code smell

* [TASK-6140] Add OMeta header to SQLAlchemy-based queries (#6293)

[TASK-6140] Add OMeta header to SQLAlchemy-based queries (#6293)

* Fix #6248: Use PUT API instead of POST for tag & tagCategory (#6344)

* Fix #6248: Use PUT API instead of POST for tag & tagCategory

* Restructure yield_tag topology

* Renamed method to create_or_update

* compressed logs

* Update packages

* feat(ui): sync OMD theme with AntD components (#6148)

* feat(ui): sync omd theme with antd components

* update package.json

* fixed failing cypress

* fix layout break issue

Co-authored-by: Shailesh Parmar <[email protected]>
(cherry picked from commit 574dbce)

* Fix sql queries formatting

Co-authored-by: Francisco J. Jurado Moreno <[email protected]>
Co-authored-by: Teddy <[email protected]>
Co-authored-by: Mayur Singal <[email protected]>
Co-authored-by: Chirag Madlani <[email protected]>

This branch was previously deployed

1 inactive deployment
cypress — 87a96f5f Deployed Jul 22, 2022 by Beetelbrox
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.

Cache tables when ingesting database usage

4 participants