Note redis -1

Pre-course knowledge

1. affect disk performance factors:

Addressing: ms
Bandwidth: G / M

2. Memory

Addressing: ns
Bandwidth: large
disk memory than on addressing the full 10W times

3 I / O buffer: cost

Disk and bayonets sector, a sector 512 Byte, bringing the cost of a larger ---> Index
4K operating system, no matter how much i read, all disks that lobbied for a minimum of 4K data

4 asked:

4.1, with larger files, slow down. Why?

It should be well known: hard disk IO is the biggest bottleneck in
4.2, the larger the database tables, performance degradation?
Subject to the availability of the index, additions and deletions to change the slow
one or a small number of queries is still fast. (Index structure related)
form of concurrent time will be hard-bandwidth affected.

redis Past and Present

1, redis appears inevitable in order to achieve a scenario arise.
2, compared with the memcached

memcached: simply kv, focus, value is no concept of types; need to return all of the data value to the client, experienced server NIC IO, require client to realize his acquisition logic data;
Redis of value provides a wealth of data types , to handle different data structures, improving efficiency of the process.

Knock focus: computing to mobile data (currently not well understood)

redis installation

reference. .

redis principle

JVM thread a cost of about 1M, memory consumption,
thread more, increase the cost of scheduling, cpu waste
redis is a single instance of single-threaded process

Evolution of IO

IO evolution in the linux
Involving the operating system, it is still not well absorbed understanding.
Simply put, it is a request from the synchronous blocking BIO - Improved History> epoll (virtual memory mapping shared memory section) of -> Sync non-blocking NIO -> IO multiplexing (select).
Each change is based on the shortcomings of the current improvement made.

redis threading model

Reference Chinese Huperzine teacher painting a picture, to compare the image description
redis threading model

File event handlers

采用 IO多路复用机制  同时监听多个 socket,根据 socket上的事件 来选择对应的 事件处理器 来处理这个事件。

Configuration file event processor contains four portions: a plurality of socket, IO multiplexing program, file event dispatcher, the event processor (processor command request, reply command processor, the processor connection response, etc.).
A plurality of socket may have different simultaneous operations, each corresponding to a different event file, but the program will monitor the plurality of IO multiplexing socket, but the socket will be placed in a queue in the queue, the queue is removed from each event dispatcher to a socket, the socket event dispatcher processor corresponding to the event.

A process to communicate with client redis

在redis启动初始化的时候,redis会将连接应答处理器跟AE_READABLE事件关联起来,接着如果一个客户端跟redis发起连接,此时会产生一个AE_READABLE事件,然后由连接应答处理器来处理跟客户端建立连接,创建客户端对应的socket,同时将这个socket的AE_READABLE事件跟命令请求处理器关联起来。
当客户端向redis发起请求的时候(不管是读请求还是写请求,都一样),首先就会在socket产生一个AE_READABLE事件,然后由对应的命令请求处理器来处理。这个命令请求处理器就会从socket中读取请求相关数据,然后进行执行和处理。
接着redis这边准备好了给客户端的响应数据之后,就会将socket的AE_WRITABLE事件跟命令回复处理器关联起来,当客户端这边准备好读取响应数据时,就会在socket上产生一个AE_WRITABLE事件,会由对应的命令回复处理器来处理,就是将准备好的响应数据写入socket,供客户端来读取。
命令回复处理器写完之后,就会删除这个socket的AE_WRITABLE事件和命令回复处理器的关联关系。

Because there are elements of the network, redis only guarantee with a client in the request is in order.

redis binary safe

需要对所有客户端进行 编码的约定,防止出现乱码

redis type

string type

Type can be stored

  • string

    • Scenes:
  • Numerical

    • Common commands: incr
    • Scenes:

      Buy, spike, thumbs up. Counting limiting.

  • bitmap

    • Common commands: setbit, bitcount, bitops, bitop
    • Scenes:
      • Statistics users log on for several days, and random window
        setbit sean 1 1 setbit sean 7 1 setbit sean 364 1 STRLEN sean BITCOUNT sean -2 -1
        • Effective active user statistics

            setbit 20190101   1  1
            setbit 20190102   1  1
            setbit 20190102   7  1
            bitop  or   destkey 20190101  20190102
            BITCOUNT  destkey  0 -1
          
          

List

Ordered
scene:
+ stack
+ queue
+ Lindex acquisition: array
+ obstruction, unicast FIFO queue

hash

HashMap Similarly, the attributes of the object for convenient operation
scenario:
thumbs, collection

set

Chaotic
scene:
a common concern, raffle (prizes fewer people, fewer people and more prizes)

sorted set

Scene:
Sort
realization: skiplist (jump table)

Guess you like

Origin www.cnblogs.com/idea-persistence/p/12581922.html