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: add caching to service calls initiated from BFF #600

Merged
merged 8 commits into from
Nov 27, 2024

Conversation

adamstankiewicz
Copy link
Member

@adamstankiewicz adamstankiewicz commented Nov 25, 2024

Description:

  • Adds caching abstractions to all GET requests to downstream services (e.g., when fetching enrollments from LMS, learner subscription licenses from license-manager, etc.).
    • get_and_cache_subscription_licenses_for_learner
    • get_and_cache_default_enterprise_enrollment_intentions
    • get_and_cache_enterprise_course_enrollments
  • Updates settings around cache timeouts.
  • Invalidates cached data when side effects occur (e.g., license activation / auto-apply, redeeming a default enterprise enrollment intention).
    • invalidate_subscription_licenses_cache
    • invalidate_default_enterprise_enrollment_intentions_cache
    • invalidate_enterprise_course_enrollments_cache

Jira:
ENT-9634

Merge checklist:

  • ./manage.py makemigrations has been run
    • Note: This must be run if you modified any models.
      • It may or may not make a migration depending on exactly what you modified, but it should still be run.

Post merge:

  • Ensure that your changes went out to the stage instance
  • Deploy to prod instance

Comment on lines 471 to 473
LICENSE_MANAGER_CLIENT_TIMEOUT = os.environ.get('LICENSE_MANAGER_CLIENT_TIMEOUT', 45)
LMS_CLIENT_TIMEOUT = os.environ.get('LMS_CLIENT_TIMEOUT', 45)
ECOMMERCE_CLIENT_TIMEOUT = os.environ.get('ECOMMERCE_CLIENT_TIMEOUT', 45)
Copy link
Member Author

Choose a reason for hiding this comment

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

[sanity check] Are we still comfortable with 45s timeouts on service calls within our API clients? Feels a bit high, but curious how others feel about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

That does feel high, but I don't remember encountering any problems because of it.

@adamstankiewicz adamstankiewicz marked this pull request as ready for review November 25, 2024 17:21

ALL_ENTERPRISE_GROUP_MEMBERS_CACHE_TIMEOUT = 60 * 5
DEFAULT_CACHE_TIMEOUT = 60 * 5 # 5 minutes
CONTENT_METADATA_CACHE_TIMEOUT = 60 * 30 # 30 minutes
Copy link
Member Author

@adamstankiewicz adamstankiewicz Nov 25, 2024

Choose a reason for hiding this comment

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

[inform] Updating CONTENT_METADATA_CACHE_TIMEOUT from 10 minutes to 30 minutes, for parity with the content metadata cache timeout in enterprise-subsidy (source).

CONTENT_METADATA_CACHE_TIMEOUT = 60 * 30 # 30 minutes
ENTERPRISE_USER_RECORD_CACHE_TIMEOUT = 60 * 10 # 10 minutes
SUBSIDY_AGGREGATES_CACHE_TIMEOUT = 60 * 10 # 10 minutes
SUBSCRIPTION_LICENSES_LEARNER_CACHE_TIMEOUT = 60 * 2 # 2 minutes
Copy link
Member Author

@adamstankiewicz adamstankiewicz Nov 25, 2024

Choose a reason for hiding this comment

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

[inform] Opted to keep the learner-licenses cache timeout a bit smaller to reflect potentially more frequently updated data (e.g., admin-driven license assignment/revocation, etc.), as compared to enterprise customer or content metadata.

enterprise_access/apps/bffs/api.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/api.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/api.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/api.py Outdated Show resolved Hide resolved
Comment on lines 471 to 473
LICENSE_MANAGER_CLIENT_TIMEOUT = os.environ.get('LICENSE_MANAGER_CLIENT_TIMEOUT', 45)
LMS_CLIENT_TIMEOUT = os.environ.get('LMS_CLIENT_TIMEOUT', 45)
ECOMMERCE_CLIENT_TIMEOUT = os.environ.get('ECOMMERCE_CLIENT_TIMEOUT', 45)
Copy link
Contributor

Choose a reason for hiding this comment

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

That does feel high, but I don't remember encountering any problems because of it.

@adamstankiewicz adamstankiewicz merged commit efa5fc1 into main Nov 27, 2024
3 checks passed
@adamstankiewicz adamstankiewicz deleted the ags/ent-9634 branch November 27, 2024 14:12
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.

2 participants