MXS-2109: Change semantics of query_classifier_cache_size

The cache size now refers to the total memory used by the cache instead of
the per thread limit. This makes it easier to use as well as more
predictable by removing the dependency on the number of worker threads.
This commit is contained in:
Markus Mäkelä
2018-10-29 12:01:30 +02:00
parent 06d1189e94
commit 8d1b26060a
3 changed files with 21 additions and 25 deletions

View File

@ -572,9 +572,10 @@ the cache. The size of the cache can be specifed as explained [here](#sizes).
query_classifier_cache_size=1MB query_classifier_cache_size=1MB
``` ```
Note that MaxScale uses a separate cache for each worker thread. So, the total Note that MaxScale uses a separate cache for each worker thread. To obtain the
amount of memory used at most by the cache is obtained by multiplying the size amount of memory available for each thread, divide the cache size with the value
specified here, with the value of `threads`. of `threads`. If statements are evicted from the cache (visible in the
diagnostic output), consider increasing the cache size.
##### `log_unrecognized_statements` ##### `log_unrecognized_statements`

View File

@ -1209,27 +1209,17 @@ bool config_load_global(const char* filename)
{ {
log_config_error(filename, rval); log_config_error(filename, rval);
} }
else else if (gateway.qc_cache_properties.max_size == -1)
{ {
// Do some post-processing for auto-sized default variables gateway.qc_cache_properties.max_size = 0;
if (gateway.qc_cache_properties.max_size == -1) MXS_WARNING("Failed to automatically detect available system memory: disabling the query classifier "
{ "cache. To enable it, add '%s' to the configuration file.",
int64_t mem_per_thr = get_total_memory() * 0.4 / gateway.n_threads;
mxb_assert(mem_per_thr >= 0);
gateway.qc_cache_properties.max_size = mem_per_thr;
if (mem_per_thr == 0)
{
MXS_WARNING("Could not auto-detect total system memory for the query classifier "
"cache. Manually define `%s` to enable it.",
CN_QUERY_CLASSIFIER_CACHE_SIZE); CN_QUERY_CLASSIFIER_CACHE_SIZE);
} }
else else
{ {
MXS_NOTICE("Using up to %s of memory for query classifier cache", MXS_NOTICE("Using up to %s of memory for query classifier cache",
mxb::to_binary_size(mem_per_thr * gateway.n_threads).c_str()); mxb::to_binary_size(gateway.qc_cache_properties.max_size).c_str());
}
}
} }
return rval == 0; return rval == 0;
@ -2801,8 +2791,13 @@ void config_set_global_defaults()
gateway.peer_password[0] = '\0'; gateway.peer_password[0] = '\0';
gateway.log_target = MXB_LOG_TARGET_DEFAULT; gateway.log_target = MXB_LOG_TARGET_DEFAULT;
// Note: This is not a valid cache value: it is used to detect that the default value is used gateway.qc_cache_properties.max_size = get_total_memory() * 0.4;
if (gateway.qc_cache_properties.max_size == 0)
{
// Set to -1 so that we know the auto-sizing failed.
gateway.qc_cache_properties.max_size = -1; gateway.qc_cache_properties.max_size = -1;
}
gateway.thread_stack_size = 0; gateway.thread_stack_size = 0;
gateway.writeq_high_water = 0; gateway.writeq_high_water = 0;

View File

@ -174,7 +174,7 @@ public:
mxb_assert(peek(canonical_stmt) == nullptr); mxb_assert(peek(canonical_stmt) == nullptr);
mxb_assert(this_unit.classifier); mxb_assert(this_unit.classifier);
int64_t cache_max_size = this_unit.cache_max_size(); int64_t cache_max_size = this_unit.cache_max_size() / config_get_global_options()->n_threads;
int64_t size = canonical_stmt.size(); int64_t size = canonical_stmt.size();
if (size <= cache_max_size) if (size <= cache_max_size)