From 14deb110acac35e96afa72316f6cd871dfe04168 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Mon, 2 Oct 2023 11:29:00 +0200 Subject: Limit size of memory cache layer (#423) - Feature: Limit the size ZenCacheMemoryLayer may use - `--cache-memlayer-targetfootprint` option to set which size (in bytes) it should be limited to, zero to have it unbounded - `--cache-memlayer-maxage` option to set how long (in seconds) cache items should be kept in the memory cache Do more "standard" GC rather than clearing everything. Tries to purge memory on Get/Put on the fly if exceeding limit - not sure if we should have a polling thread instead of adding overhead to Get/Put (however light it may be). --- src/zenserver/config.cpp | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'src/zenserver/config.cpp') diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp index 6daf7fe1c..5e24d174b 100644 --- a/src/zenserver/config.cpp +++ b/src/zenserver/config.cpp @@ -814,9 +814,17 @@ ParseConfigFile(const std::filesystem::path& Path, LuaOptions.AddOption("trace.file"sv, ServerOptions.TraceFile, "tracefile"sv); ////// cache - LuaOptions.AddOption("cache.enable"sv, ServerOptions.StructuredCacheEnabled); - LuaOptions.AddOption("cache.writelog"sv, ServerOptions.StructuredCacheWriteLogEnabled); - LuaOptions.AddOption("cache.accesslog"sv, ServerOptions.StructuredCacheAccessLogEnabled); + LuaOptions.AddOption("cache.enable"sv, ServerOptions.StructuredCacheConfig.Enabled); + LuaOptions.AddOption("cache.writelog"sv, ServerOptions.StructuredCacheConfig.WriteLogEnabled, "cache-write-log"); + LuaOptions.AddOption("cache.accesslog"sv, ServerOptions.StructuredCacheConfig.AccessLogEnabled, "cache-access-log"); + + LuaOptions.AddOption("cache.memlayer.targetfootprint"sv, + ServerOptions.StructuredCacheConfig.MemTargetFootprintBytes, + "cache-memlayer-targetfootprint"); + LuaOptions.AddOption("cache.memlayer.triminterval"sv, + ServerOptions.StructuredCacheConfig.MemTrimIntervalSeconds, + "cache-memlayer-triminterval"); + LuaOptions.AddOption("cache.memlayer.maxage"sv, ServerOptions.StructuredCacheConfig.MemMaxAgeSeconds, "cache-memlayer-maxage"); ////// cache.upstream LuaOptions.AddOption("cache.upstream.policy"sv, ServerOptions.UpstreamCacheConfig.CachePolicy, "upstream-cache-policy"sv); @@ -1236,14 +1244,35 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) "", "cache-write-log", "Whether cache write log is enabled", - cxxopts::value(ServerOptions.StructuredCacheWriteLogEnabled)->default_value("true"), + cxxopts::value(ServerOptions.StructuredCacheConfig.WriteLogEnabled)->default_value("true"), ""); options.add_option("cache", "", "cache-access-log", "Whether cache access log is enabled", - cxxopts::value(ServerOptions.StructuredCacheAccessLogEnabled)->default_value("true"), + cxxopts::value(ServerOptions.StructuredCacheConfig.AccessLogEnabled)->default_value("true"), + ""); + + options.add_option("cache", + "", + "cache-memlayer-targetfootprint", + "Max allowed memory used by cache memory layer per namespace in bytes. Default set to 536870912 (512 Mb).", + cxxopts::value(ServerOptions.StructuredCacheConfig.MemTargetFootprintBytes)->default_value("536870912"), + ""); + + options.add_option("cache", + "", + "cache-memlayer-triminterval", + "Minimum time between each attempt to trim cache memory layers in seconds. Default set to 60 (1 min).", + cxxopts::value(ServerOptions.StructuredCacheConfig.MemTrimIntervalSeconds)->default_value("60"), + ""); + + options.add_option("cache", + "", + "cache-memlayer-maxage", + "Maximum age of payloads when trimming cache memory layers in seconds. Default set to 86400 (1 day).", + cxxopts::value(ServerOptions.StructuredCacheConfig.MemMaxAgeSeconds)->default_value("86400"), ""); options.add_option("compute", -- cgit v1.2.3