Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is consumed in the Redis process

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article is about what is consumed in the Redis process. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

Redis in-process consumption mainly includes: own memory + object memory + buffer memory + memory fragmentation.

Memory. Because the data of redis is stored in memory. The in-memory database is faster to read than the general relational database, but consumes more memory resources.

Object memory

Object memory is the largest block of Redis memory, which stores all the data of users. All Redis data is of the key-value data type, and each time a key-value pair is created, at least two type objects are created: the key object and the value object. Memory consumption can be simply understood as sizeof (keys) + sizeof (values). Key objects are strings, and it is easy to ignore the impact of keys on memory consumption when using Redis, and you should avoid using long keys. Value objects are more complex, including five basic data types: strings, lists, hashes, collections, and ordered collections. Each value object type takes up different amounts of memory depending on the scale of usage. When using it, you must reasonably estimate and monitor the occupancy of value objects to avoid memory overflow.

Buffer memory

Buffer memory mainly includes: client buffer, copy backlog buffer, AOF buffer.

Client buffering refers to all input and output buffers connected to Redis server TCP connections. Input and output buffer can not be controlled, the maximum space is 1G, if it exceeds, it will be disconnected. Input buffering is controlled by the parameter client-output-buffer-limit:

1. Ordinary client: except for copying and subscribing clients, the default configuration of Redis is: client-output-buffer-limit normal 2000 Magi Redis does not limit the output buffer of ordinary clients, and the memory consumption of ordinary clients can be ignored, but when there are a large number of slow connection clients connected, this part of memory consumption can not be ignored, you can set maxclients as a limit. Be careful not to use only a large number of data output commands and the data can not be pushed to the client in time, such as the monitor command, it is easy to cause the memory of the Redis server to soar suddenly.

Slave client: the master node establishes a separate connection for each slave node for command replication. The default configuration is: client-output-buffer-limit slave 256mb 64mb 60. When the network latency between master and slave nodes is high or a large number of slave nodes are mounted on the master node, this part of memory consumption will take up a large part. It is recommended that no more than 2 slave nodes are mounted on the master node, and the master-slave node should not be deployed in a poor network environment, such as remote cross-server room, to prevent the overflow caused by slow connection of the replication client.

Subscription client: when using the publish and subscribe feature, the connection client uses a separate output buffer, which is configured as client-output-buffer-limit pubsub 32mb 8mb 60 by default. When the message production of the subscription service is faster than the consumption speed, the output buffer will overrun due to the backlog of the output buffer.

Replication backlog buffer: Redis provides a reusable fixed size buffer for partial replication after version 2.8.According to the repl-backlog-size parameter control, the default is 1MB. For the replication backlog buffer, there is only one master node, and all slave nodes share this buffer, so you can set a large buffer space, such as 100MB.

AOF buffer: this part of the space is used to hold the most recent write commands during Redis rewrite.

3. Memory fragmentation

The default memory allocator for Redis is jemalloc, and the optional allocators are glibc and tcmalloc. In order to better manage and reuse memory, the memory allocator generally uses fixed-range memory blocks to allocate memory.

The following scenarios are prone to high memory fragmentation:

Do update operations frequently, such as append, setrange and other update operations on existing keys.

A large number of expired keys are deleted, and after the expired deletion of key objects, the free space can not be fully utilized, resulting in an increase in fragmentation rate.

Thank you for reading! About what is consumed in the Redis process is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report