Skip to content

Add a short (ttl-based) cache to AccountAPI.get_quotas() #24

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

Merged
merged 1 commit into from
Sep 9, 2019

Conversation

frivoire
Copy link
Contributor

@frivoire frivoire commented Sep 9, 2019

The goal is to optimize usecases like this :

api = AccountAPI(...)
api.has_quota(organization=organization, resource='servers', used=10)
api.has_quota(organization=organization, resource='volumes', used=10)
api.has_quota(organization=organization, resource='ips', used=10)

=> we check several quotas of the same organization in a very short period of time, typically within less than 1sec

In that usecase, the current AccountAPI does 3 calls to API-account, which is sub-optimal.
But we can easily cache "in-ram" the response to get_quotas(), because it's getting all quotas of a given organization, and re-use it for the 2nd and 3rd call.

NB: currently, each call to api-account to get quotas takes ~60 ms, so each call avoided is a lot :)

@codecov-io
Copy link

codecov-io commented Sep 9, 2019

Codecov Report

Merging #24 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           develop    #24   +/-   ##
======================================
  Coverage      100%   100%           
======================================
  Files            4      4           
  Lines           99    101    +2     
  Branches        21     21           
======================================
+ Hits            99    101    +2
Impacted Files Coverage Δ
scaleway/apis/api_account.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30d3eb8...bc6fb14. Read the comment docs.

Copy link
Contributor

@jerome-quere jerome-quere left a comment

Choose a reason for hiding this comment

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

LGTM

@lodow lodow self-requested a review September 9, 2019 15:28
Copy link
Contributor

@lodow lodow left a comment

Choose a reason for hiding this comment

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

LGTM

@jerome-quere jerome-quere merged commit c73988d into develop Sep 9, 2019
@frivoire frivoire deleted the add-cache-quotas branch September 10, 2019 14:05
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.

4 participants