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

How to use Redis memory

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

Share

Shulou(Shulou.com)05/31 Report--

How to use Redis memory, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

How to use Redis memory

If the memory used by Redis exceeds the available physical memory, it is likely that the Redis system will be killed by OOM Killer. In response to this, you can monitor used_memory and used_memory_peak through the info command, set a threshold for the amount of memory used, and set the corresponding alarm mechanism. Of course, the alarm is only a means, it is important for you to plan in advance what you should do when you use too much memory, whether to erase some useless cold data, or to migrate the Redis to a more powerful machine.

Redis persistence

If Redis crashes because of a problem with your machine or Redis itself, then your only lifesaver may be the rdb file from dump, so it is also important to monitor Redis dump files. You can monitor rdb_last_save_time to know the time of your last dump data operation, and you can monitor rdb_changes_since_last_save to know how much data you will lose if there is a failure.

Redis master-slave replication

If you set the master-slave replication mode, then you'd better do some monitoring on whether the replication is normal, mainly to monitor the master_link_status in the info output. If this value is up, then the synchronization is normal. If it is down, then you should pay attention to some other diagnostic information output. Such as the following:

Role:slave

Master_host:192.168.1.128

Master_port:6379

Master_link_status:down

Master_last_io_seconds_ago:-1

Master_sync_in_progress:0

Master_link_down_since_seconds:1356900595

RedisFork performance

When Redis persists data to disk, it performs a fork operation to mirror memory cheaply through the copy on write mechanism of fork to memory. But although the memory is copy on write, the virtual memory table needs to be allocated at the moment of fork, so fork will cause the main thread to stutter for a short time (stop all read and write operations), which is related to the current memory usage of Redis. Usually, Redis of GB magnitude performs fork operations in milliseconds. You can monitor the latest_fork_usec output of info to see how long the last fork operation caused stutters.

Redis configuration is consistent

Redis supports the use of CONFIG SET operations to implement real configuration changes, which is convenient, but can also cause a problem. The configuration that is dynamically modified through this command will not be synchronized to your configuration file. So when you restart Redis for some reason, the configuration changes you made with CONFIG SET will be lost, so we'd better make sure that the configuration file is changed accordingly every time you use CONFIG SET to modify the configuration. In order to prevent human error, it is best to monitor the configuration, use the CONFIG GET command to get the current runtime configuration, and compare it with the configuration value in redis.conf. If you find that the two sides do not match, start the alarm.

Redis slow log

Redis provides SLOWLOG instruction to get the latest slow log, the slow log of Redis is directly stored in memory, so its slow log overhead is not big. In practical application, we use crontab task to execute SLOWLOG command to get slow log, then save the slow log to file, and use Kibana to generate real-time performance chart to achieve performance monitoring.

It is worth mentioning that the slow logging time of Redis only includes the execution time of a command by Redis itself, not the time of IO, such as receiving client data and sending client data. In addition, the slow log of Redis is a little different from that of other databases. It may be normal for other databases to occasionally have slow logs of 100ms, because the general database is multithreaded and concurrent execution, and the performance of a thread executing a command may not represent the overall performance, but for Redis, it is single-threaded. Once a slow log appears, it may need to be paid attention to immediately. Better find out what the reason is.

What services are monitored by Redis

-Sentinel

Sentinel is a tool that comes with Redis, which can monitor the master-slave replication of Redis and realize automatic failover after the master hangs up. During the transfer process, it can also be configured to execute a user-defined script in which we can implement functions such as alarm notification.

-Redis Live

Redis Live is a more general Redis monitoring scheme. Its principle is to execute MONITOR commands on Redis regularly to obtain the commands currently being executed by Redis, and to generate visual analysis reports of web pages through statistical analysis.

-Redis Faina

Redis Faina is a Redis monitoring service developed by the famous photo-sharing application instagram. Its principle is similar to that of Redis Live, which is done through MONITOR.

Data distribution

It is difficult to figure out the distribution of data storage in Redis, for example, you want to know which type of key value takes up the most memory. Here are some tools that can help you analyze Redis data sets.

-Redis-sampler

Redis-sampler is a tool developed by the authors of Redis, which allows you to know the general type, data and distribution of the data in the current Redis through sampling.

-Redis-audit

Redis-audit is a script through which we can know the amount of memory used by each type of key. It can provide data such as how often a certain type of key value is accessed, how many values set the expiration time, and the amount of memory used by a certain type of key value, which makes it convenient for us to find out which key is not commonly used or not used at all.

-Redis-rdb-tools

Redis-rdb-tools is similar to Redis-audit in function, except that it obtains statistics by analyzing rdb files.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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