Persistence
Last updated
Was this helpful?
Last updated
Was this helpful?
Metarank supports two possible persistence modes for storing features:
: ephemeral; all state is in RAM.
: state persisted in remote Redis.
Persistence mode is configured by the optional state
section in the . By default, if the section is not defined, Metarank uses .
See also .
Memory persistence is no persistence at all: the complete Metarank state is stored only in RAM, is ephemeral, and will be entirely lost on each service restart.
Nevertheless, memory persistence can be useful:
While testing Metarank locally in a , as it has no external service dependencies.
As a staging env to validate configuration changes before going to production.
To configure memory persistence, use the type: memory
option:
Metarank can use as a persistence method. To enable it, use the following snippet:
Redis persistence is sensitive to network latencies (as it needs to perform a couple of round-trips on each event), hence Metarank leverages a couple of Redis performance optimization strategies:
A note on optional cache & pipelining related settings:
Metarank has a separate cache per underlying feature type (like scalar/counter/map/etc, 10 total), so cache.maxSize
is set per cache type, so keep in mind an implicit multiplication: default value 1024
in reality means 10240
.
pipeline.maxSize
going above 128
is usually giving no benefit on low latencies (e.g. when Redis server is located in the same datacenter/AZ)
pipeline.flushPeriod
controls the level of "eventualness" in the overall eventual consistency. With values larger than 10
seconds, a second Metarank instance may not see write buffered in a first instance.
Metarank has also an experimental option of using disk persistence instead of Redis. The main drawback of such an approach is that the deployment becomes stateful and you need to maintain a disk persistence.
Metarank supports two disk backends for file-based persistence:
MapDB: uses a mmap-based storage for data, works well for smaller datasets.
RocksDB: uses an LSM-tree storage, suits for large datasets.
The file persistence configured in the following way:
RocksDB can be configured by defining the following values in the config file:
A rule of thumb defining these parameters:
higher LRU cache size leads to better read throughput at the cost of extra memory usage. If not sure, set it to 50% of your RAM.
blockSize defines a size of page RocksDB reads from disk. In a perfect world it should match your actual disk block size: For cloud-attached disks like AWS EBS it should be 16kb, for local drives 1-2kb.
MapDB can be configured in the following way:
Metarank supports connecting to Redis using TLS for transport encryption, but there is no way to autodetect the type of connection.
To connect to a TLS-enabled Redis server with self-signed certificate, you need to specify the CA used to sign the certificate (for self-signed certs it will be the server certificate itself):
To connect to a TLS-enabled Redis server with a certificate generated with default CA (for example, AWS ElastiCache Redis), then you don't need to specify any custom CA:
In a case when you have cert trust issues connecting to a TLS-enabled redis, you can downgrade the verification level. Supported levels are:
full
- verify both certificate and hostname
ca
- verify only the certificate
off
- skip verification, trust all
An example:
auth.user
and auth.password
can control the credentials used to connect to Redis. As hardcoding the credentials into the config file is not usually considered secure, you can supply the credentials from environment variables:
METARANK_REDIS_USER
- only needed when Redis ACL is enabled.
METARANK_REDIS_PASSWORD
- the pre-shared password used to connect to the Redis instance.
Metarank Redis persistence supports json
and binary
encoding formats for data stored in Redis:
json
: focused on readability and debugging simplicity.
binary
: low-overhead binary encoding format, with better performance and smaller memory footprint.
Metarank requires Redis 6+ due to a lack of client-side caching support in 5.x
you can disable client caching altogether (for example, for managed Redis-compatible engines, like GCP Memorystore Redis) with cache.maxSize: 0
.
For GCP Memorystore Redis, you can also set state.cache.clientTracking: false
to disable the CLIENT TRACKING
cache eviction support: GCP Memstore has client-side caching disabled even on 7.x Redis cluster.
: all write operations are batched together and sent all at once
: read cache for hot keys with server-assisted invalidation.
cache.ttl
defines expiration interval after last read, so hot features may be cached almost indefinitely. The problem of stale cache values is solved with : Redis server sends a notification to Metarank when key value was changed by someone else.
Metarank's has a placeholder for the env variables passed inside the container inside Kubernetes. Usage example:
binary
format on typical datasets (like ) is ~2x faster and takes ~4x less RAM. We recommend it for larger datasets, when memory usage and associated costs are an important factor.
Redis Cluster is not yet supported; see ticket for the progress.