Danceiny / WikiNotes

My notes.
6 stars 2 forks source link

Redis开发与运维 #19

Open Danceiny opened 5 years ago

Danceiny commented 5 years ago

《Redis开发与运维 》Google Drive

Danceiny commented 5 years ago

查看内部数据结构实现

> object encoding KEY

image

Danceiny commented 5 years ago

字符串

image

Danceiny commented 5 years ago

哈希

image

Danceiny commented 5 years ago

列表

image

Danceiny commented 5 years ago

集合

image

Danceiny commented 5 years ago

有序集合

image

Danceiny commented 5 years ago

GEO

获取指定位置范围内的地理位置信息集合

获取geohash

Danceiny commented 5 years ago

RESP协议

发送命令

*<参数数量> CRLF
$<参数1的字节数> CRLF
<参数1> CRLF
...
$<参数N的字节数> CRLF
<参数N> CRLF

image

Danceiny commented 5 years ago

输入缓冲区 qbuf qbuf-free

每个客户端的输入缓冲区硬编码为1GB,一旦超过该值,客户端会被关闭。 输入缓冲区不受maxmemory限制,如果一个redis实例设置maxmemory为4G,已经存储2G数据库,此时输入缓冲区使用了3G,可能会导致数据丢失、键值淘汰、OOM等。 输入缓冲区过大的原因:

输出缓冲区 obl oll omem

image

输出缓冲区由两部分组成:固定缓冲区(16KB)和动态缓冲区。

typedef struct redisClient {
    // 动态缓冲区列表
    list *reply;
    // 动态缓冲区列表长度(对象个数)
    unsigned long reply_bytes;
    // 固定缓冲区已经使用的字节数
    int bufpos;
    // 字节数组作为固定缓冲区
    char buf[REDIS_REPLY_CHUNK_BYTES];
} redisClient;

如何预防输出缓冲区出现异常?(比输入缓冲区异常概率更大)

Danceiny commented 5 years ago

客户端类型

image image

客户端配置

image

Danceiny commented 5 years ago

AOF

image image image

Danceiny commented 5 years ago

image image image

Redis阻塞 https://redis.io/topics/latency

Danceiny commented 5 years ago

阻塞的外在原因

  1. CPU竞争
  2. 内存交换
  3. 网络问题 image
Danceiny commented 5 years ago

image image

  1. 对象内存 key对象和value对象。

  2. 缓冲内存

    • 客户端缓冲

      输入缓冲无法控制,最大1G;输出通过client-output-buffer-limit控制。

    • 复制积压缓冲
    • AOF缓冲

内存碎片

默认使用的内存分配器采用jemelloc,可选的还有glibctcmalloc

Danceiny commented 5 years ago

redisObject对象

image

Danceiny commented 5 years ago

JSON string OR HASH ?

image

Danceiny commented 5 years ago

image image

Danceiny commented 5 years ago

ziplist

image