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

fix: Remove double pickling for cached payloads #10222

Merged
merged 1 commit into from
Jul 2, 2020

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Jul 1, 2020

SUMMARY

It seems we pickle the visualization payloads et al. prior to caching via the Flask-Caching package, however for all backends as part of the set/get logic the object to cache is pickled and the unpicked respectively, i.e., for Redis the set and get methods call dump_object and load_object respectively which in turn calls pickle.dumps and pickle.loads, hence we were actually double pickling the payloads.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

CI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@@ -260,14 +258,8 @@ def get_df_payload( # pylint: disable=too-many-locals,too-many-statements
if is_loaded and cache_key and cache and status != utils.QueryStatus.FAILED:
try:
cache_value = dict(dttm=cached_dttm, df=df, query=query)
cache_binary = pkl.dumps(cache_value, protocol=pkl.HIGHEST_PROTOCOL)

logger.info(
Copy link
Member Author

Choose a reason for hiding this comment

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

I annexed this as we no longer a priori know the size of the payload and it seems somewhat like an unnecessary comment.

stats_logger.incr("set_cache_key")
cache.set(cache_key, cache_binary, timeout=self.cache_timeout)
cache.set(cache_key, cache_value, timeout=self.cache_timeout)
Copy link
Member

Choose a reason for hiding this comment

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

random thought [out of scope for this PR], we should time this operation eventually

Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

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

Good catch! Simplifies the code, saves CPU.

dill-with-it-3jr-prints

@john-bodley john-bodley merged commit cf60f66 into apache:master Jul 2, 2020
@john-bodley john-bodley deleted the john-bodley--pickle branch July 2, 2020 23:49
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/S 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants