Configuring Storage for MaxScale's Cache Filter

Overview

MaxScale's Cache Filter (cache) caches the result-sets of SELECTSELECT statements to improve query performance.

This page explains how to configure the filter to use various types of storage.

Storage Types

The storage used by the Cache Filter (cache) is configured by the storage parameter.

There are two different types of storage: local storage and shared storage.

Local Storage

The Cache Filter currently supports one type of local storage:

Value

Description

storage_inmemory

  • When the storage parameter is set to this value, the cached data is stored in local memory.

  • The storage is not persistent and is destroyed when MaxScale terminates.

  • Since the storage exists in the MaxScale process, it is very fast and provides almost always a performance benefit.

  • This is the default value.

Shared Storage

The Cache Filter currently supports two types of shared storage:

Value

Description

storage_memcached

  • When the storage parameter is set to this value, the cached data is stored in a memcached instance.

storage_redis

  • When the storage parameter is set to this value, the cached data is stored in a Redis instance.

The shared storage types are most useful when multiple MaxScale instances are being used in a highly available (HA) configuration. The shared storage allows all MaxScale instances to use the same cache.

When the Cache Filter uses one of the shared storage types, any access to the cache requires network access. Therefore, it is not guaranteed that it will improve performance. It should be tested very carefully. Shared storage tends to help in the following cases:

  • If the network between MaxScale and the storage server (memcached or Redis) is faster than the network between MaxScale and the database server.

  • If the used SELECT statements are heavy (that is, take a significant amount of time) to process for the database server.

  • If the presence of the cache reduces the overall load of an otherwise overloaded database server.

If you are not using multiple MaxScale instances, and if your workload does not fall into one of the above categories, then it may be best to use local storage, which is the default behavior.

Configuring the Cache Filter to use Memcached

  1. Configure the Cache Filter to use memcached by setting the storage parameter to storage_memcached in maxscale.cnf.

    You will also need to set specific memcached-related options using the storage_options parameter. Options should be supplied as a comma-separated string.

    Option

    Description

    server

    • This option defines the address of the memcached instance, in the format: host[:port].

    • If the port is not specified, then 11211 is used by default.

    • This option is mandatory.

    max_value_size

    • This option defines the maximum size of a cached value.

    • The unit is bytes, but EIC binary prefixes (Ki, Mi, Gi, and Ti) and SI prefixes (k, M, G, and T) can also be specified.

    • If the value of this option is lower than the value of the max_result_size parameter for the Cache Filter, then the value of this option will be the effective maximum result size.

    • The default value is 1 MB.

    • This option is optional.

    For example:

    [split-router-cache]
    type                     = filter
    module                   = cache
    hard_ttl                 = 30s
    soft_ttl                 = 20s
    ...
    storage                  = storage_memcached
    storage_options          = server=192.0.2.100:11211, max_value_size=10M
    
    [cached-split-router]
    type                     = service
    router                   = readwritesplit
    ...
    filters                  = split-router-cache
    
  2. Restart the MaxScale instance.

    $ sudo systemctl restart maxscale
    

Configuring the Cache Filter to use Redis

  1. Configure the Cache Filter to use Redis by setting the storage parameter to storage_redis in maxscale.cnf.

    You will also need to set specific Redis-related options using the storage_options parameter. Options should be supplied as a comma-separated string.

    Option

    Description

    server

    • This option defines the address of the Redis instance, in the format: host[:port].

    • If the port is not specified, then 6379 is used by default.

    • This option is mandatory.

    For example:

    [split-router-cache]
    type                     = filter
    module                   = cache
    hard_ttl                 = 30s
    soft_ttl                 = 20s
    ...
    storage                  = storage_redis
    storage_options          = server=192.0.2.100:6379
    
    [cached-split-router]
    type                     = service
    router                   = readwritesplit
    ...
    filters                  = split-router-cache
    
  2. Restart the MaxScale instance.

    $ sudo systemctl restart maxscale