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

perf: Memoize the common_bootstrap_payload and include user param (#21018) #21439

Merged
merged 2 commits into from
Sep 13, 2022

Conversation

bkyryliuk
Copy link
Member

@bkyryliuk bkyryliuk commented Sep 12, 2022

Try 2 on: #21018
Includes small refactoring of the common_bootstrap_payload that passes user object to the function.

SUMMARY
Memoize the common_bootstrap_payload. The function includes the config settings and the feature flags, those tend to be changed in frequently, this PR adds caching layer with 1 minute TTL. In our staging deployment it yields 10x speedup e.g. 22 ms down from ~250 ms

BEFORE
Screen Shot 2022-08-05 at 10 17 57 AM

AFTER
image

TESTING INSTRUCTIONS
[x] CI

Try patch

Co-authored-by: Bogdan Kyryliuk <bogdankyryliuk@dropbox.com>
@codecov
Copy link

codecov bot commented Sep 12, 2022

Codecov Report

Merging #21439 (4159724) into master (9c285da) will decrease coverage by 11.27%.
The diff coverage is 100.00%.

❗ Current head 4159724 differs from pull request most recent head 608ba48. Consider uploading reports for the commit 608ba48 to get more accurate results

@@             Coverage Diff             @@
##           master   #21439       +/-   ##
===========================================
- Coverage   66.53%   55.26%   -11.28%     
===========================================
  Files        1791     1791               
  Lines       68599    68602        +3     
  Branches     7320     7320               
===========================================
- Hits        45645    37911     -7734     
- Misses      21064    28801     +7737     
  Partials     1890     1890               
Flag Coverage Δ
hive 52.94% <100.00%> (+<0.01%) ⬆️
mysql ?
postgres ?
presto 52.84% <100.00%> (+<0.01%) ⬆️
python 57.94% <100.00%> (-23.32%) ⬇️
unit 50.96% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/views/core.py 34.41% <ø> (-40.65%) ⬇️
superset/views/dashboard/views.py 58.13% <ø> (-8.14%) ⬇️
superset/views/base.py 60.56% <100.00%> (-14.89%) ⬇️
superset/utils/dashboard_import_export.py 0.00% <0.00%> (-100.00%) ⬇️
superset/key_value/commands/update.py 0.00% <0.00%> (-88.89%) ⬇️
superset/key_value/commands/delete.py 0.00% <0.00%> (-85.30%) ⬇️
superset/key_value/commands/delete_expired.py 0.00% <0.00%> (-80.77%) ⬇️
superset/dashboards/commands/importers/v0.py 15.62% <0.00%> (-76.25%) ⬇️
superset/datasets/commands/update.py 25.00% <0.00%> (-69.05%) ⬇️
superset/datasets/commands/create.py 31.25% <0.00%> (-68.75%) ⬇️
... and 282 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@bkyryliuk bkyryliuk changed the title perf: Memoize the common_bootstrap_payload (#21018) [WIP] perf: Memoize the common_bootstrap_payload and include user param (#21018) Sep 12, 2022
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM and tested to work as expected. I'd love to see all instances of @superset.utils.memoized.memoized replaced with @cache_manager.cache.memoize(timeout=x) (we could have constants for slow, medium and long lived timouts) to ensure we don't leak memory on memoized methods that get called with very diverse parameters.

def common_bootstrap_payload() -> Dict[str, Any]:
"""Common data always sent to the client"""
@cache_manager.cache.memoize(timeout=60)
def common_bootstrap_payload(user: User) -> Dict[str, Any]:
Copy link
Member

Choose a reason for hiding this comment

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

I checked the docs, and while they appear to recommend not using mutable objects as the key, it should work in this case as __repr__() will always return the same value for a single user.

Memoization docs: https://flask-caching.readthedocs.io/en/latest/#memoization

@bkyryliuk bkyryliuk merged commit 44654e5 into apache:master Sep 13, 2022
@bkyryliuk bkyryliuk deleted the bogdan/cache_bootstrap_try2 branch September 13, 2022 15:52
michael-s-molina pushed a commit that referenced this pull request Sep 14, 2022
…1018) (#21439)

Co-authored-by: Bogdan Kyryliuk <bogdankyryliuk@dropbox.com>
zhaorui2022 pushed a commit to zhaorui2022/superset that referenced this pull request Sep 22, 2022
…ache#21018) (apache#21439)

Co-authored-by: Bogdan Kyryliuk <bogdankyryliuk@dropbox.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants