redis使用記憶體調整及最佳化

來源:互聯網
上載者:User

redis使用記憶體調整及最佳化
redis使用記憶體調整及最佳化1、查看當前記憶體使用量情況

[root@redis01 ~]# redis-cli info# Serverredis_version:2.8.19redis_git_sha1:00000000redis_git_dirty:0redis_build_id:c0359e7aa3798aa2redis_mode:standaloneos:Linux 3.10.0-123.el7.x86_64 x86_64arch_bits:64multiplexing_api:epollgcc_version:4.8.3process_id:24191run_id:36ad15148d3478f13076b6feb065536c7dca4adctcp_port:6379uptime_in_seconds:173800uptime_in_days:2hz:10lru_clock:14099001config_file:/etc/redis.conf# Clientsconnected_clients:84client_longest_output_list:0client_biggest_input_buf:0blocked_clients:0# Memoryused_memory:14187404192used_memory_human:13.21Gused_memory_rss:14567976960used_memory_peak:14189556584used_memory_peak_human:13.22Gused_memory_lua:35840mem_fragmentation_ratio:1.03mem_allocator:jemalloc-3.6.0# Persistenceloading:0rdb_changes_since_last_save:130135rdb_bgsave_in_progress:1rdb_last_save_time:1490493874rdb_last_bgsave_status:okrdb_last_bgsave_time_sec:100rdb_current_bgsave_time_sec:74aof_enabled:0aof_rewrite_in_progress:0aof_rewrite_scheduled:0aof_last_rewrite_time_sec:-1aof_current_rewrite_time_sec:-1aof_last_bgrewrite_status:okaof_last_write_status:ok# Statstotal_connections_received:280094total_commands_processed:228769139instantaneous_ops_per_sec:1111total_net_input_bytes:14293923616total_net_output_bytes:42883168734instantaneous_input_kbps:72.58instantaneous_output_kbps:77.55rejected_connections:0sync_full:1sync_partial_ok:0sync_partial_err:1expired_keys:38545evicted_keys:0keyspace_hits:33635872keyspace_misses:302049pubsub_channels:0pubsub_patterns:4latest_fork_usec:195303# Replicationrole:masterconnected_slaves:1slave0:ip=x.0.x.x,port=6379,state=online,offset=11332087470,lag=0master_repl_offset:11332106737  ##  已修改隱藏實際iprepl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:11331058162repl_backlog_histlen:1048576# CPUused_cpu_sys:6134.57used_cpu_user:2565.36used_cpu_sys_children:8045.19used_cpu_user_children:97035.76# Keyspacedb0:keys=337475,expires=180183,avg_ttl=1286629728
2、分析實際記憶體消耗已經13G
used_memory_human:13.21G
查看zabbix內redis使用記憶體的最近一個月記錄
一個月前3.5G,線性增長到到13G
平均到期時間
db0:keys=337475,expires=180183,avg_ttl=1286629728
實際記憶體設定
[root@redis01 ~]# redis-cli config get maxmemory1) "maxmemory"2) "0"
3、最佳化措施3.1、設定記憶體限制,防止達到記憶體最大限制宕機設定記憶體最大使用量為10G,先調整運行時
127.0.0.1:6379> config set maxmemory 10737418240OK(10.76s)127.0.0.1:6379> info......# Memoryused_memory:10730048552used_memory_human:9.99G
設定redis.conf,下次重啟生效
maxmemory 10737418240
3.2、調整到期時間,清理到期時間keys佔用記憶體
預設到期時間移交開發調整,avg_ttl單位為ms,換成後平均為15天,相當長的時間;未設定預設到期時間的keys,移交開發調整;
3.3、調整系統參數,保證bgsave正常運行
[root@redis01 ~]# cat /etc/sysctl.confvm.overcommit_memory = 1
運行命令後生效
sysctl -p 
3.4、分析keys,找出使用記憶體最大的keys列表交開發分析安裝redis-rdb-tools
過程略
產生redis快照
rdb -c memory dump.rdb > memory.csv   #dump.rdb為redis產生的dump檔案
尋找記憶體用量最大的20個對象
sort -t, -k4nr memory.csv |heand -n 20

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.