Enable query classifier cache by default
Enabling it will give a performance improvement and it offloads work from the CPU. This leads to better and more complete utilization of system resources.
This commit is contained in:
@ -552,26 +552,29 @@ _qc_sqlite_ - supports the following arguments:
|
|||||||
|
|
||||||
#### `query_classifier_cache_size`
|
#### `query_classifier_cache_size`
|
||||||
|
|
||||||
If present, enables and specifies the maximum size of the query classifier cache.
|
Specifies the maximum size of the query classifier cache. The default limit is
|
||||||
|
40% of total system memory.
|
||||||
|
|
||||||
If the query classifier cache has been enabled, MaxScale will, after a statement
|
When the query classifier cache has been enabled, MaxScale will, after a
|
||||||
has been parsed, store the classification result using the canonicalized version
|
statement has been parsed, store the classification result using the
|
||||||
of the statement as the key.
|
canonicalized version of the statement as the key.
|
||||||
|
|
||||||
When the classification result for a statement is needed, MaxScale will first
|
If the classification result for a statement is needed, MaxScale will first
|
||||||
canonicalize the statement and check whether the result can be found in the cache.
|
canonicalize the statement and check whether the result can be found in the
|
||||||
If it can, the statement will not be parsed at all but the cached result is used.
|
cache. If it can, the statement will not be parsed at all but the cached result
|
||||||
|
is used.
|
||||||
|
|
||||||
|
The configuration parameter takes one integer that specifies the maximum size of
|
||||||
|
the cache. The size of the cache can be specifed as explained [here](#sizes).
|
||||||
|
|
||||||
The configuration parameter takes one integer that specifies the maximum size
|
|
||||||
of the cache. The size of the cache can be specifed as explained [here](#sizes).
|
|
||||||
```
|
```
|
||||||
# 1MB query classifier cache
|
# 1MB query classifier cache
|
||||||
query_classifier_cache=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. So, the total
|
||||||
amount of memory used at most by the cache is obtained by multiplying the
|
amount of memory used at most by the cache is obtained by multiplying the size
|
||||||
size specified here, with the number the worker threads used.
|
specified here, with the value of `threads`.
|
||||||
|
|
||||||
##### `log_unrecognized_statements`
|
##### `log_unrecognized_statements`
|
||||||
|
|
||||||
|
|||||||
@ -154,8 +154,20 @@ bool clean_up_pathname(char *path);
|
|||||||
|
|
||||||
bool mxs_mkdir_all(const char *path, int mask);
|
bool mxs_mkdir_all(const char *path, int mask);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of processors
|
||||||
|
*
|
||||||
|
* @return Number of processors or 1 if the information is not available
|
||||||
|
*/
|
||||||
long get_processor_count();
|
long get_processor_count();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return total system memory
|
||||||
|
*
|
||||||
|
* @return Total memory in bytes or 0 if the information is not available
|
||||||
|
*/
|
||||||
|
int64_t get_total_memory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a 4 byte integer
|
* Store a 4 byte integer
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1123,6 +1123,22 @@ bool config_load_global(const char *filename)
|
|||||||
{
|
{
|
||||||
log_config_error(filename, rval);
|
log_config_error(filename, rval);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Do some post-processing for auto-sized default variables
|
||||||
|
if (gateway.qc_cache_properties.max_size == -1)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return rval == 0;
|
return rval == 0;
|
||||||
}
|
}
|
||||||
@ -2608,6 +2624,9 @@ void config_set_global_defaults()
|
|||||||
gateway.passive = false;
|
gateway.passive = false;
|
||||||
gateway.promoted_at = 0;
|
gateway.promoted_at = 0;
|
||||||
|
|
||||||
|
// 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 = -1;
|
||||||
|
|
||||||
gateway.thread_stack_size = 0;
|
gateway.thread_stack_size = 0;
|
||||||
gateway.writeq_high_water = 0;
|
gateway.writeq_high_water = 0;
|
||||||
gateway.writeq_low_water = 0;
|
gateway.writeq_low_water = 0;
|
||||||
|
|||||||
@ -1119,11 +1119,6 @@ int open_unix_socket(enum mxs_socket_type type, struct sockaddr_un *addr, const
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the number of processors available.
|
|
||||||
* @return Number of processors or 1 if the required definition of _SC_NPROCESSORS_CONF
|
|
||||||
* is not found
|
|
||||||
*/
|
|
||||||
long get_processor_count()
|
long get_processor_count()
|
||||||
{
|
{
|
||||||
long processors = 1;
|
long processors = 1;
|
||||||
@ -1139,6 +1134,24 @@ long get_processor_count()
|
|||||||
return processors;
|
return processors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t get_total_memory()
|
||||||
|
{
|
||||||
|
int64_t pagesize = 0;
|
||||||
|
int64_t num_pages = 0;
|
||||||
|
#if defined _SC_PAGESIZE && defined _SC_PHYS_PAGES
|
||||||
|
if ((pagesize = sysconf(_SC_PAGESIZE)) <= 0 || (num_pages = sysconf(_SC_PHYS_PAGES)) <= 0)
|
||||||
|
{
|
||||||
|
MXS_WARNING("Unable to establish total system memory");
|
||||||
|
pagesize = 0;
|
||||||
|
num_pages = 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error _SC_PAGESIZE and _SC_PHYS_PAGES are not defined
|
||||||
|
#endif
|
||||||
|
mxb_assert(pagesize * num_pages > 0);
|
||||||
|
return pagesize * num_pages;
|
||||||
|
}
|
||||||
|
|
||||||
namespace maxscale
|
namespace maxscale
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user