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

Historical queries cache size soft limit #6282

Merged
2 changes: 1 addition & 1 deletion .daily_canary
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
( V ) / . \ | +---=---'
/--x-m- /--n-n---xXx--/--yY------>>>----<<<>>]]{{}}---||-/\---..
2024__
!..!!
!..!
2 changes: 1 addition & 1 deletion doc/build_apps/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Historical Queries

.. doxygenclass:: ccf::historical::AbstractStateCache
:project: CCF
:members: set_default_expiry_duration, get_state_at, get_store_at, get_store_range, drop_cached_states
:members: set_default_expiry_duration, set_soft_cache_limit, get_state_at, get_store_at, get_store_range, drop_cached_states

.. doxygenstruct:: ccf::historical::State
:project: CCF
Expand Down
9 changes: 9 additions & 0 deletions include/ccf/historical_queries_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace ccf::historical

using ExpiryDuration = std::chrono::seconds;

using CacheSize = size_t;

/** Stores the progress of historical query requests.
*
* A request will generally need to be made multiple times (with the same
Expand Down Expand Up @@ -79,6 +81,13 @@ namespace ccf::historical
virtual void set_default_expiry_duration(
ExpiryDuration seconds_until_expiry) = 0;

/** Set the cache limit (in bytes) to evict least recently used requests
* from the cache after its size grows beyond this limit. The limit is not
* strict. It is estimated based on serialized states' sizes approximation
* and is checked once per tick, and so it can overflow for a short time.
*/
virtual void set_soft_cache_limit(CacheSize cache_limit) = 0;

/** EXPERIMENTAL: Set the tracking of deletes on missing keys for historical
* queries.
*
Expand Down
6 changes: 6 additions & 0 deletions samples/apps/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ namespace loggingapp
PUBLIC_RECORDS, context, 10000, 20);
context.get_indexing_strategies().install_strategy(index_per_public_key);

// According to manual obvervation it's enough to start evicting old
// requests on historical perf test, but not too small to get stuck
// because of a single request being larget than the cache.
constexpr size_t cache_limit = 1024 * 1024 * 10; // MB
context.get_historical_state().set_soft_cache_limit(cache_limit);

const ccf::AuthnPolicies auth_policies = {
ccf::jwt_auth_policy,
ccf::user_cert_auth_policy,
Expand Down
Loading
Loading