如何找到分配给redis实例的内存?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何找到分配给redis实例的内存?相关的知识,希望对你有一定的参考价值。
使用Redis info
命令,我可以获得redis服务器的所有统计信息。我也能够获得已用内存指标。
如何获取分配给Redis实例的总内存,以便获取使用的内存百分比?
答案
默认情况下,Redis会获得所有可用内存(尽可能多的内存以及所有可用的物理内存)。您可以使用maxmemory
文件中的redis.conf
参数限制分配给Redis的内存量。
这是文件的摘录:
# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys with an
# EXPIRE set. It will try to start freeing keys that are going to expire
# in little time and preserve keys with a longer time to live.
# Redis will also try to remove objects from free lists if possible.
#
# If all this fails, Redis will start to reply with errors to commands
# that will use more memory, like SET, LPUSH, and so on, and will continue
# to reply to most read-only commands like GET.
#
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
# 'state' server or cache, not as a real DB. When Redis is used as a real
# database the memory usage will grow over the weeks, it will be obvious if
# it is going to use too much memory in the long run, and you'll have the time
# to upgrade. With maxmemory after the limit is reached you'll start to get
# errors for write operations, and this may even lead to DB inconsistency.
#
# maxmemory <bytes>
另一答案
你可以这样做:
$ ps aux -m | grep redis-server | head -n1 | awk '{printf "VSZ: %dMB, RSS: %dMB
", $5/1024, $6/1024}'
这将以MB为单位显示redis-server进程的舍入虚拟和实际内存大小(要查看实际数字,请从两个参数中删除/1024
)。
以上是关于如何找到分配给redis实例的内存?的主要内容,如果未能解决你的问题,请参考以下文章