Redis_淘汰策略

淘汰策略

为什么要有这个机制?

​ 当Redis的数据存储大于物理内存时,内存就会和磁盘产生频繁的交换(swap),涉及的磁盘操作、那就是慢!会导致Redis性能急剧下降;对于访问量巨大的Redis来说,一旦出现交换行为,那Redis相当于没起作用了;所以生产环境是不允许交换行为产生的!

​ 因为要限制内存的使用!maxmemory参数,可以设置内容超出期望大小;当内容超过时,Redis就要启用淘汰策略,来腾出空间保证能够继续提供读写服务;

淘汰策略有哪些?
noeviction

​ 不能继续进行写操作,只能读;这也是默认的淘汰策略;

volatile-lru

​ 淘汰设置了过期时间的key,最少使用的key优先被淘汰;没有设置过期时间的key不会被淘汰,这样保证了需要持久化的数据不会丢失;

volatile-ttl

​ 在设置了过期的key中,淘汰即将过期的key;

allkeys-lru

所有key均可能被淘汰,不只是设置了过期时间的;

allkeys-random

​ 从所有key中,随机删除;

volatile-XX和allkeys-XX的区别是使用场景
  1. volatile-XX:

    • 只会淘汰过期的key;对于有持久化需求的,使用allkeys
  2. allkeys-random:

    • 会淘汰所有key;如果只是单纯的坐缓存使用,可以使用volatile-XX;那么没有设置了过期的key就不会被LRU算法淘汰;
请根据下述 Prometheus 采集得到的 redis 监控指标,给出 redis 集群建议的监控告警指标,并附上对应的告警表达式 redis_active_defrag_running、redis_allocator_active_bytesredis_allocator_allocated_bytes redis_allocator_frag_bytes redis_allocator_frag_ratio redis_allocator_resident_bytes redis_allocator_rss_bytes redis_allocator_rss_ratio redis_aof_base_size_bytes redis_aof_buffer_length redis_aof_current_rewrite_duration_sec redis_aof_current_size_bytes redis_aof_delayed_fsync redis_aof_enabled redis_aof_last_bgrewrite_status redis_aof_last_cow_size_bytes redis_aof_last_rewrite_duration_sec redis_aof_last_write_status redis_aof_pending_bio_fsync redis_aof_pending_rewrite redis_aof_rewrite_buffer_length redis_aof_rewrite_in_progress redis_aof_rewrite_scheduled redis_blocked_clients redis_client_recent_max_input_buffer_bytes redis_client_recent_max_output_buffer_bytes redis_cluster_connections redis_cluster_current_epoch redis_cluster_enabled redis_cluster_known_nodes redis_cluster_messages_received_total redis_cluster_messages_sent_total redis_cluster_my_epoch redis_cluster_size redis_cluster_slots_assigned redis_cluster_slots_fail redis_cluster_slots_ok redis_cluster_slots_pfail redis_cluster_state redis_cluster_stats_messages_auth_ack_sent redis_cluster_stats_messages_auth_req_received redis_cluster_stats_messages_fail_received redis_cluster_stats_messages_fail_sent redis_cluster_stats_messages_ping_received redis_cluster_stats_messages_ping_sent redis_cluster_stats_messages_pong_received redis_cluster_stats_messages_pong_sent redis_cluster_stats_messages_update_received redis_cluster_stats_messages_update_sent redis_commands_duration_seconds_total redis_commands_processed_total redis_commands_total redis_config_io_threads redis_config_maxclients redis_config_maxmemory redis_connected_clients redis_connected_slave_lag_seconds redis_connected_slave_offset_bytes redis_connected_slaves redis_connections_received_total redis_cpu_sys_children_seconds_total redis_cpu_sys_seconds_total redis_cpu_user_children_seconds_
最新发布
03-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值