-
Notifications
You must be signed in to change notification settings - Fork 27
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
✨ Cache list service request in catalog #2874
✨ Cache list service request in catalog #2874
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2874 +/- ##
========================================
- Coverage 79.2% 74.8% -4.4%
========================================
Files 674 674
Lines 27620 27624 +4
Branches 3220 3220
========================================
- Hits 21876 20671 -1205
- Misses 4993 6240 +1247
+ Partials 751 713 -38
Flags with carried forward coverage won't be shown. Click here to find out more.
|
08c91d3
to
95887ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll wait until you merge previous PR to finish the review. For the moment, here are some inputs
@@ -57,6 +62,11 @@ def dsn(self) -> str: | |||
) | |||
return dsn | |||
|
|||
@cached_property | |||
def dsn_with_async_sqlalchemy(self) -> str: | |||
dsn = self.dsn.replace("postgresql", "postgresql+asyncpg") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THOUGHT: Since we are going to deprecate aiopg this means that this will be the final dsn
.
For that reason, I would directly implement it properly as
@cached_property
def dsn_with_async_sqlalchemy(self) -> str:
dsn: str = PostgresDsn.build(
scheme="postgresql+asycnpg",
user=self.POSTGRES_USER,
password=self.POSTGRES_PASSWORD.get_secret_value(),
host=self.POSTGRES_HOST,
port=f"{self.POSTGRES_PORT}",
path=f"/{self.POSTGRES_DB}",
)
return dsn
You can even add a deprecation warning if using dsn
...
The replace
in addition is dangerous ... for instance, what if any of the attributes, i.e. user or password ,etc is postgresql
??
@@ -65,8 +70,19 @@ def _prepare_service_details( | |||
return validated_service | |||
|
|||
|
|||
def _build_cache_key(fct, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wild :-D ...
@router.get("", response_model=List[ServiceOut], **RESPONSE_MODEL_POLICY) | ||
@cancellable_request | ||
@cached( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's see if i got it right: this caches the handler's return and below cached_registry_services
is a completely different cache, right?
Since one wraps the other and they have the same TTL ... is really the internal making a difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they don't have the same TTL
actually the call to the director-v0 is always returning the same info unless the registry changed.
get_registry_services_task = director_client.get("/services") | ||
# caching this steps brings down the time to generate it at the expense of being sometimes a bit out of date | ||
@cached(ttl=DIRECTOR_CACHING_TTL) | ||
async def cached_registry_services() -> Deque[Tuple[str, str, Dict[str, Any]]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MINOR: the name should not incorporate cached_
since this is a decorated property (can have it or not)
Q: here you do not worry about the key-name? does this mean that different requests to this entry will reuse this cache? it so, does the access of different request might play a role here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aiocache default key uses module name, method name and so on. here there is no key to worry about. and all users use the same one
95887ea
to
cfbfb92
Compare
cfbfb92
to
e176ebc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
@@ -39,6 +39,7 @@ | |||
} | |||
|
|||
DIRECTOR_CACHING_TTL = 5 * MINUTE | |||
LIST_SERVICES_CACHING_TTL = 30 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question, why not raise this even more? Since this just returns the list of existing services? You could cache for several minutes. It's not like services get released so fast.
Also an endpoint can be added for internal platform usage to bust
the cache if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not only new services in the registry, but you can also change the access rights, the names, thumbnail and this kind of stuff. therefore I would not extend this too much.
This reverts commit b969b8d.
What do these changes do?
This PR follows #2869 and the idea is to provide caching of the request listing services from the catalog using for now a simple cache mechanism through aiocache library.
This library could allow caching through Redis if need be. for now it caches in memory for a 30 seconds time.
The requests per seconds doubles using that mechanism, during the 30seconds the cache lives.
Without cache:
With cache:
Related issue/s
How to test
Checklist