Skip to content

Conversation

@VipulMascarenhas
Copy link
Member

@VipulMascarenhas VipulMascarenhas commented Feb 14, 2024

To cache model list API results, we can use TTL cache from cachetools. docs

We have set up TTL cache for model listing (5 hrs) and compartment listing (2 hrs) APIs. Since we need an option to clear/invalidate the cache, we need to set lock as well.

Note that caching is only enabled for models in the service compartment and not in the custom compartment.

To invalidate service model cache, user can call:

DELETE http://localhost:8888/aqua/model/cache 

To invalidate compartment listing cache, call:

DELETE http://localhost:8888/aqua/compartments/cache 

Time to list models locally:

  • Before caching ~700 ms
  • After caching ~75ms

Time to list compartments locally:

  • Before caching ~2.7 secs
  • After caching ~60ms

To do:

  • update THIRD_PARTY_LICENSES.txt if we proceed with this.
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Feb 14, 2024
@github-actions
Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.
@github-actions
Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.
@github-actions
Copy link

📌 Cov diff with main:

No success to gather report. 😿

📌 Overall coverage:

No success to gather report. 😿

@github-actions
Copy link

📌 Cov diff with main:

Coverage-3%

📌 Overall coverage:

Coverage-23.43%

]
llm = ["langchain>=0.0.295", "evaluate>=0.4.0"]
aqua = ["fire"]
aqua = ["fire", "cachetools"]
Copy link
Member

Choose a reason for hiding this comment

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

We need to check license for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

did a search on slack and seems a lot of projects are using it, still need to confirm.

"""Read the information of an Aqua model."""
return self.finish(AquaModelApp().get(model_id))

@handle_exceptions
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we need this :) User will not be able to reach out this end point. If only we add supporting refresh button in UI which might be a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

agree- depends on what we want to start with first. If we just use it for service models, then it makes sense not to have it. For custom models, we'll need it.

),
)

@cached(
Copy link
Member

Choose a reason for hiding this comment

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

I think the problem with this approach is that we want different caching for the Service models and Custom models. Maybe we can start only with the service models?

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case, the parameters values for the cache key can be set as None, that way results are cached only when the function is called without specific compartment id and project id. Would using a cached decorator still be a good idea or is it better to explicitly maintain a cache in the class?

Copy link
Member

Choose a reason for hiding this comment

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

There are pros and cons. Does it support saving cache into the file? ALso does it support updating cache explicitly? For example if we return user the cashed data but in the parallel thread update the case with the fresh data?

Copy link
Member Author

Choose a reason for hiding this comment

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

having different cache for service vs. custom models isn't supported via the decorator directly. It's doable with custom wrappers but makes it more complex. Moved the cache outside and now we're caching service models and compartments only.
Need more testing on our end but UI team can use it in the meanwhile to that they don't have to wait longer times for testing.

Copy link
Member

Choose a reason for hiding this comment

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

Let us start with the service models for now. The custom models anyway goes through RQS, which is makes it slightly faster.
Let us also add it to the compartment listing as well. I think these two will improve the overall experience.

@github-actions
Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.
@github-actions
Copy link

📌 Cov diff with main:

Coverage-4%

📌 Overall coverage:

Coverage-23.40%

@github-actions
Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.
@github-actions
Copy link

📌 Cov diff with main:

Coverage-4%

📌 Overall coverage:

Coverage-23.40%

@VipulMascarenhas VipulMascarenhas changed the title [ODSC-52993] Set up caching for listing models [ODSC-52993] Set up caching for listing models and compartments Feb 21, 2024
"""Handles DELETE request for clearing cache"""
url_parse = urlparse(self.request.path)
paths = url_parse.path.strip("/")
if paths.startswith("aqua/model/cache"):
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to move the paths into the const variable? At least all of them will be in one place.

Copy link
Member Author

Choose a reason for hiding this comment

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

agree. Added this to pending items and will update all paths in a separate PR.

)
compartments.insert(
0,
Compartment(id=TENANCY_OCID, name=" ** Root - Name N/A **"),
Copy link
Member

Choose a reason for hiding this comment

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

That what we want to show to user if they don't have permissions?

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 wasn't sure if it should be either empty or return the tenancy ocid. My thinking was that they should be able to see the root compartment at least.

@github-actions
Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.
@github-actions
Copy link

📌 Cov diff with main:

Coverage-8%

📌 Overall coverage:

Coverage-23.34%

@github-actions
Copy link

⚠️ This PR changed pyproject.toml file. ⚠️

  • PR Creator must update 📃 THIRD_PARTY_LICENSES.txt, if any 📚 library added/removed in pyproject.toml.
  • PR Approver must confirm 📃 THIRD_PARTY_LICENSES.txt updated, if any 📚 library added/removed in pyproject.toml.
@VipulMascarenhas VipulMascarenhas merged commit 221963c into feature/aqua Feb 27, 2024
@VipulMascarenhas VipulMascarenhas deleted the ODSC-52993_cache_model_list branch February 27, 2024 21:43
@github-actions
Copy link

📌 Cov diff with main:

Coverage-6%

📌 Overall coverage:

Coverage-23.04%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

3 participants