Help Center/ Distributed Cache Service/ FAQs/ Instance Types/Versions/ New Features of DCS for Redis 4.0
Updated on 2024-09-24 GMT+08:00

New Features of DCS for Redis 4.0

Compared with DCS for Redis 3.0, DCS for Redis 4.0 and later versions add support for the new features of open-source Redis and supports faster instance creation.

Instance deployment changed from the VM mode to physical server–based containerization mode. An instance can be created within 8 to 10 seconds.

Redis 4.0 provides the following new features:

  1. New commands, such as MEMORY and SWAPDB
  2. Lazyfree, delaying the deletion of large keys and reducing the impact of the deletion on system resources
  3. Memory performance optimization, that is, active defragmentation

MEMORY Command

In Redis 3.0 and earlier versions, you can execute the INFO MEMORY command to learn only the limited memory statistics. Redis 4.0 introduces the MEMORY command to help you better understand Redis memory usage.

Running the memory help command on single-node, master/standby, and read/write splitting instances:
127.0.0.1:6379[8]> memory help
1) "MEMORY DOCTOR                        - Outputs memory problems report"
2) "MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key"
3) "MEMORY STATS                         - Show memory usage details"
4) "MEMORY PURGE                         - Ask the allocator to release memory"
5) "MEMORY MALLOC-STATS                  - Show allocator internal stats"
Running the memory help command on cluster instances:
127.0.0.1:6379[8]> memory help
1) MEMORY <subcommand> arg arg ... arg. Subcommands are:
2) DOCTOR - Return memory problems reports.
3) MALLOC-STATS -- Return internal statistics report from the memory allocator.
4) PURGE -- Attempt to purge dirty pages for reclamation by the allocator.
5) STATS -- Return information about the memory usage of the server.
6) USAGE <key> [SAMPLES <count>] -- Return memory in bytes used by <key> and its value. Nested values are sampled up to <count
> times (default: 5).

usage command

Enter memory usage [key]. If the key exists, the estimated memory used by the value of the key is returned. If the key does not exist, nil is returned. For the same memory usage, results may differ in other Redis versions.

127.0.0.1:6379[8]> set dcs "DCS is an online, distributed, in-memory cache service compatible with Redis, and Memcached."
OK
127.0.0.1:6379[8]> memory usage dcs
(integer) 141
127.0.0.1:6379[8]> 
  1. usage collects statistics on the memory usage of the value and the key, excluding the Expire memory usage of the key. Results may differ in other Redis versions.
    // The following is verified based on Redis 5.0.2.
    192.168.0.66:6379> set a "Hello, world!"
    OK
    192.168.0.66:6379> memory usage a
    (integer) 58
    192.168.0.66:6379> set abc "Hello, world!"
    OK
    192.168.0.66:6379> memory usage abc
    (integer) 60   //After the key name length changes, the memory usage also changes. This indicates that the usage statistics contain the usage of the key.
    192.168.0.66:6379> expire abc 1000000
    (integer) 1
    192.168.0.66:6379> memory usage abc
    (integer) 60   // After the expiration time is added, the memory usage remains unchanged. This indicates that the usage statistics do not contain the expire memory usage.
    192.168.0.66:6379> 
  2. For hashes, lists, sets, and sorted sets, the MEMORY USAGE command samples statistics and provides the estimated memory usage.

    Usage: memory usage keyset samples 1000

    keyset indicates the key of a set, and 1000 indicates the number of samples.

stats command

Returns the detailed memory usage of the current instance.

Usage: memory stats

127.0.0.1:6379[8]> memory stats
 1) "peak.allocated"
 2) (integer) 2412408
 3) "total.allocated"
 4) (integer) 2084720
 5) "startup.allocated"
 6) (integer) 824928
 7) "replication.backlog"
 ... ...

The following table describes some return items.

Table 1 MEMORY STATS return values

Return Value

Description

peak.allocated

Peak memory allocated by the allocator during Redis instance running. It is the same as used_memory_peak of info memory.

total.allocated

The number of bytes allocated by the allocator. It is the same as used_memory of info memory

startup.allocated

Initial amount of memory consumed by Redis at startup in bytes

replication.backlog

Size in bytes of the replication backlog. It is specified in the repl-backlog-size parameter. The default value is 1 MB.

clients.slaves

The total size in bytes of all replicas overheads

clients.normal

The total size in bytes of all clients overheads

overhead.total

The sum of all overheads. overhead.total is the total memory total.allocated allocated by the allocator minus the actual memory used for storing data.

keys.count

The total number of keys stored across all databases in the server

keys.bytes-per-key

Average number of bytes occupied by each key. Note that the overhead is also allocated to each key. Therefore, this value does not indicate the average key length.

dataset.bytes

Memory bytes occupied by Redis data, that is, overhead.total subtracted from total.allocated

dataset.percentage

The percentage of dataset.bytes out of the net memory usage

peak.percentage

The percentage of peak.allocated out of total.allocated

fragmentation

Memory fragmentation rate

doctor command

Usage: memory doctor

If the value of used_memory (total.allocated) is less than 5 MB, MEMORY DOCTOR considers that the memory usage is too small and does not perform further diagnosis. If any of the following conditions is met, Redis provides diagnosis results and suggestions:
  1. The peak allocated memory is greater than 1.5 times of the current total_allocated, that is, peak.allocated/total.allocated > 1.5, indicating that the memory fragmentation rate is high, and that the RSS is much larger than used_memory.
  2. The value of high fragmentation/fragmentation is greater than 1.4, indicating that the memory fragmentation rate is high.
  3. The average memory usage of each normal client is greater than 200 KB, indicating that the pipeline may be improperly used or the Pub/Sub client does not process messages in time.
  4. The average memory usage of each slave client is greater than 10 MB, indicating that the write traffic of the master is too high.

purge command

Usage: memory purge

Executes the jemalloc internal command to release the memory. The released objects include the memory that is occupied but not used by Redis processes, that is, memory fragments.

MEMORY PURGE applies only to the Redis instance that uses jemalloc as the allocator.

Lazyfree

Problem

Redis is single-thread. When a time-consuming request is executed, all requests are queued. Before the request is completed, Redis cannot respond to other requests. As a result, performance problems may occur. One of the time-consuming requests is deleting a large key.

Principle

The Lazyfree feature of Redis 4.0 avoids the blockage caused by deleting large keys, ensuring performance and availability.

When deleting a key, Redis asynchronously releases the memory occupied by the key. The key release operation is processed in the sub-thread of the background I/O (BIO).

Usage

  1. Active deletion
    • UNLINK

      Similar to DEL, this command removes keys. If there are more than 64 elements to be deleted, the memory release operation is executed in an independent BIO thread. Therefore, the UNLINK command can delete a large key containing millions of elements in a short time.

    • FLUSHALL and FLUSHDB

      An ASYNC option was added to FLUSHALL and FLUSHDB in order to let the entire dataset or a single database to be freed asynchronously.

  2. Passive deletion: deletion of expired keys and eviction of large keys

    There are four scenarios for passive deletion and each scenario corresponds to a parameter. These parameters are disabled by default.

    lazyfree-lazy-eviction no // Whether to enable Lazyfree when the Redis memory usage reaches maxmemory and the eviction policy is set.
    lazyfree-lazy-expire no // Whether to enable Lazyfree when the key with TTL is going to expire.
    lazyfree-lazy-server-del no // An implicit DEL key is used when an existing key is processed.
    slave-lazy-flush no // Perform full data synchronization for the standby node. Before loading the RDB file of the master, the standby node executes the FLUSHALL command to clear its own data.

Other New Commands

  1. swapdb

    Swaps two Redis databases.

    swapdb dbindex1 dbindex2

  2. zlexcount

    Returns the number of elements in the sorted set.

    zlexcount key min max

Memory and Performance Optimization

  1. Compared to before, the same amount of data can be stored with less memory.
  2. Used memory can be defragmented and gradually evicted.