Tier Internet companies use Redis essence, you have to master the four points!

Redis first look at these questions you'll face a few?

1. What is the Redis? It outlined the advantages and disadvantages?
2, Redis and memcached Compared What are the advantages?
3, Redis to support what kinds of data types?
4, Redis major consuming what physical resources?
5, Redis data out of what kinds of strategies?
6, Redis official Why not offer Windows version?
7, a value of type string can store the maximum capacity is how much?
8. Why Redis need to put all the data into memory?
9, Redis cluster program should be how to do? What are the solutions?
10, Redis clustering scheme under what circumstances would cause the entire cluster is unavailable?
11, MySQL, there 2000w data, only the data stored in redis 20w, how to ensure that the data is hot data in redis?
12, Redis which the appropriate scene there?
13, Redis supports Java client has what? Official recommended to use which?
14, Redis and Redisson What is the relationship?
15, Jedis and Redisson contrast what advantages and disadvantages?
16, talk about the concept of Redis hash slot?
17, the main Redis cluster replication model from what?
18, Redis cluster will write to lose it? why?
19, how to select a database Redis cluster?
20, Redis how to do memory optimization?
Tier Internet companies use Redis essence, you have to master the four points!

Learn Redis

NoSQL Redis is a database based on a key (Key-Value) of, Redis may be made of Value String, hash, list, set, zset, Bitmaps, HyperLogLog data structures and algorithms, and other components. Redis also provides key expired, publish-subscribe, transaction, Lua script, Sentinel, Cluster and other functions. Redis command execution speed is very fast, according to the official performance can be achieved 10w + qps. In this paper, in the end so fast Redis where the following main points:

Development language

Now we have high-level programming language, such as Java, python and so on. You may find the C language is very old, but it is really useful, after all unix system is implemented in C, so C language is very close to the operating system language. Redis is using C language development, so the implementation will be faster.
Also say one more thing, college students a good learning C, will make you a better understanding of computer operating systems. Do not think learning a high-level language you can not focus on the bottom, always owe a debt to repay. Here recommend a book more difficult nut to "in-depth understanding of computing systems."

Pure memory access

Redis all data in memory, non-data synchronization to work in, is not required to read data from the disk, 0 times IO. Memory response time of about 100 nanoseconds, which is an important foundation of Redis fast speed. Take a look at CPU speed:
Tier Internet companies use Redis essence, you have to master the four points!

Take my computers, clocked at 3.1G, which means you can perform 3.1 * 10 ^ 9 instructions per second. So the CPU to see the world is very, very slow, a hundred times slower than its memory, disk million times slower than him, you say fast unhappy?
Borrowed an "in-depth understanding of computer systems," the diagram shows a typical memory hierarchy, in the L0 layer, CPU can be accessed in a single clock cycle, based on the renewal of spring SRAM cache, you can in a few CPU clock cycle access to, and are based on DRAM main memory, you can have access to them in tens to hundreds of clock cycles.
Tier Internet companies use Redis essence, you have to master the four points!

Single-threaded

第一,单线程简化算法的实现,并发的数据结构实现不但困难且测试也麻烦。第二,单线程避免了线程切换以及加锁释放锁带来的消耗,对于服务端开发来说,锁和线程切换通常是性能杀手。当然了,单线程也会有它的缺点,也是Redis的噩梦:阻塞。如果执行一个命令过长,那么会造成其他命令的阻塞,对于Redis是十分致命的,所以Redis是面向快速执行场景的数据库。
除了Redis之外,Node.js也是单线程,Nginx也是单线程,但他们都是服务器高性能的典范。

非阻塞多路I/O复用机制

在这之前先要说一下传统的阻塞I/O是如何工作的:当使用read或者write对某一文件描述符(File Descriptor FD)进行读写的时候,如果数据没有收到,那么该线程会被挂起,直到收到数据。阻塞模型虽然易于理解,但是在需要处理多个客户端任务的时候,不会使用阻塞模型。
Tier Internet companies use Redis essence, you have to master the four points!

I/O多路复用实际上是指多个连接的管理可以在同一进程。多路是指网络连接,复用只是同一个线程。在网络服务中,I/O多路复用起的作用是一次性把多个连接的事件通知业务代码处理,处理的方式由业务代码来决定。在I/O多路复用模型中,最重要的函数调用就是I/O 多路复用函数,该方法能同时监控多个文件描述符(fd)的读写情况,当其中的某些fd可读/写时,该方法就会返回可读/写的fd个数。
Tier Internet companies use Redis essence, you have to master the four points!

Redis as I achieved using epoll / O multiplexing technique, plus its own event model Redis to convert the epoll so read, write, close to the events, not the network I / waste too much time on O. FD implement monitoring of multiple read and write, to improve performance.
Tier Internet companies use Redis essence, you have to master the four points!
For example the image of it. For example, a tcp server handles 20 clients socket. A Program: sequential processing, if the first read data because the card socket slow processing, the eggs are playing back to a blocking. Plan B: Each socket requests to create a sub-body process to handle, do not say each process consumes a lot of system resources, just enough operating system, the process of switching the tired. Scheme C ** (I / O multiplexing model, epoll): fd user registration into the corresponding socket epoll (actually transferred between servers and operating systems, but not the socket fd fd_set data structure), then only epoll tell what needs to read / write the socket, only need to deal with those active, there is a change of socket fd just fine. In this way, the whole process will be blocked only when the epoll calls, send and receive customer messages are not blocked.

At last

Welcome to share with everyone, like the point of a praise yo remember the article, thanks for the support!

Guess you like

Origin blog.51cto.com/14442094/2429773