redis一些有趣的问题(我觉得有用的)--加深redis的理解


redis官网文档传送门

1.redis占用内存大概的数据量是多少

  • 举例:

1.空实例使用 3MB 的内存。
2.100 万个小密钥 - >string的结构:会占用 85MB 的内存。
3.100 万键 - >hash结构:一个hash有 5 个字段,占用160 MB 的内存。

  • 建议

用redis-benchmark去测,然后用info memory命令去看内存的相关信息

  • 补充:

64位系统比32位存的键值对更多,占用内存更多,因为比如说一个指针占用8位。但是64位系统优点是能有更多可支配的内存空间,备选方案是分片sharding,那就能存更多键值对

2.Background saving fails with a fork() error under Linux even if I have a lot of free RAM!(在有很多内存容量的时候,后台用fork保存数据会返回错误怎么办?涉及到linux分配管理内存机制)

  • 解决方法:

Short answer: echo 1 > /proc/sys/vm/overcommit_memory

Redis background saving schema relies on the copy-on-write semantic of fork in modern operating systems: Redis forks (creates a child process) that is an exact copy of the parent. The child process dumps the DB on disk and finally exits. In theory the child should use as much memory as the parent being a copy, but actually thanks to the copy-on-write semantic implemented by most modern operating systems the parent and child process will share the common memory pages. A page will be duplicated only when it changes in the child or in the parent. Since in theory all the pages may change while the child process is saving, Linux can’t tell in advance how much memory the child will take, so if the overcommit_memory setting is set to zero fork will fail unless there is as much free RAM as required to really duplicate all the parent memory pages, with the result that if you have a Redis dataset of 3 GB and just 2 GB of free memory it will fail.

Setting overcommit_memory to 1 tells Linux to relax and perform the fork in a more optimistic allocation fashion, and this is indeed what you want for Redis.

A good source to understand how Linux Virtual Memory works and other alternatives for overcommit_memory and overcommit_ratio is this classic from Red Hat Magazine, “Understanding Virtual Memory”. You can also refer to the proc(5) man page for explanations of the available values.

3.redis用完内存会发生什么

  • 结果:

①be killed by the Linux kernel OOM killer,crash with an error
②will start to slow down

  • 解决方法:

①设置内存淘汰策略。server will start swapping (if some swap space is configured), and Redis performance will start to degrade, so you’ll probably notice there is something wrong
②设置最大内存配置选项。Redis has built-in protections allowing the user to set a max limit to memory usage, using the maxmemory option in the configuration file to put a limit to the memory Redis can use. If this limit is reached Redis will start to reply with an error to write commands (but will continue to accept read-only commands), or you can configure it to evict keys when the max memory limit is reached in the case where you are using Redis for caching.
redis官方对于内存淘汰的文档链接

command reports the amount of memory Redis is using so you can write scripts that monitor your Redis servers checking for critical conditions before they are reached.

4.redis是单线程的,如何利用多个CPU/内核?

  • 大多数情况下:

redis瓶颈大多数情况下都是内存或网络方面的限制,使用管道流水线的redis峰值可达到100W的qps,所以redis只用O(N) or O(log(N)) 命令,那就很少用到更多的cpu

  • 建议:

尽量最大化使用cpu,在同一个box(我不知道官方文档中box指的啥,可能是机器?)中使用多个实例,并将它们视为不同的服务器,而且考虑涉及分片的一些配置
redis官方文档分片的信息

5.redis一个实例最大能存多少数据量

1.Redis can handle up to 232 keys, and was tested in practice to handle at least 250 million keys per instance.Every hash, list, set, and sorted set, can hold 232 elements.
2.In other words your limit is likely the available memory in your system.

6.redis的名字寓意是啥?

REmote DIctionary Server.
远程字典服务器

7.redis怎么发音?

It’s “red” like the color, then “iss”.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值