memcached and redis What is the difference? What redis threading model? Why single-threaded memcached redis much higher than the efficiency of multi-threaded (redis Why is single-threaded, but can also support high concurrent)?

1.redis and memcached What is the difference?

This thing right, you can compare the difference to a plurality of N, but I still take a few more authors give it redis

 

1) Redis support server-side data manipulation: Redis compared Memcached, owning more data and structure and support a richer data manipulation, usually Memcached, you need the data to get the client to carry out similar changes again set back. This greatly increases the number of network IO and data volume. In Redis, these operations are usually complex and general GET / SET as efficient. So, if a cache can support more complex structures and operations, so Redis would be a good choice.

 

2 ) Memory efficiency comparison: using a simple key-value store, then, the Memcached higher memory utilization, and if Redis using hash structures do key-value store, due to the compression of its modular, high memory utilization thereof to Memcached .

 

3 ) Performance Comparison: Redis since only a single core, and Memcached may be used a multi-core, so that on average each core Redis in storing data Memcached smaller than the higher performance. In the 100k or more data, Memcached performance than Redis , although Redis to optimize the performance of large data storage more recently on, but compared Memcached , or slightly less.

 

4) cluster mode: memcached no native cluster model, relies on the client to achieve write data to the cluster carved pieces; but redis currently is native support cluster mode, redis official is to support redis cluster cluster mode than memcached to said to be better

 

What 2.redis threading model?

1) document the event handler


redis reactor model developed based on network events processor, this processor is called the document an event handler, file event handler. This file event processor, single-threaded, redis it is called single-threaded model, the IO multiplexing mechanism simultaneously monitor multiple socket, select the corresponding event handler according to the event on the socket to handle this event.

 

If the listening socket is ready for execution accept, read, write, close other operations when operating with the corresponding file event will generate, this time a good event associated processor to handle this event event handler is called before the file .

 

File event handler is single-threaded mode, but listening through the mechanism of IO multiplexing multiple socket, can achieve high-performance network communication model, and can be docked with other single-threaded internal modules to ensure that the internal redis threading model of simplicity.

 

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.

 

After the event is then processed in a socket, IO multiplexing program until the next queue to the event dispatcher socket. File event dispatcher for each event based on the current generated socket, the corresponding event handler is selected to handle.

 

2) file event

 

When the socket becomes readable (such as the client performs redis write operation or close operation), or when there is a new response can occur sccket (client performs operation to connect Redis), a socket is generated AE_READABLE event.

 

When (the client performs redis read operation) socket becomes writable, socket will produce a AE_WRITABLE event.

 

IO multiplexing can listen at the same time AE_REABLE and AE_WRITABLE both events, if a socket while producing AE_READABLE and AE_WRITABLE both events, the file event dispatcher priority AE_REABLE event, then the event is AE_WRITABLE.

 

3) File event handlers

 

If the client is connecting redis, then the answer would be connected to the processor socket association

If the client wishes to send data to redis, then the processor will request commands associated socket

If the client reads data from the redis, it will return the associated command processor socket

 

4) a process to communicate with the client redis

 

When redis start initialization, redis processor will connect response associated with AE_READABLE event, then if a client initiates a connection with redis, this time will produce a AE_READABLE event, then the response is handled by the processor to establish connection with client connection, create a corresponding client socket, while the socket of AE_READABLE events associated with the command requesting processor.

 

When the client sends a request to the redis (either a read request or write request, are the same), it will produce a AE_READABLE first event in socket, then the request by the corresponding command processor to handle. This command requests the data processor will read the request from the socket, and then the execution process.

Then redis here ready to respond after the client's data, it will reply to the socket of AE_WRITABLE events associated with the command processor, when the client side is ready to read the response data, it will generate a AE_WRITABLE on the socket event, will return to the processor by a corresponding command to deal with, is written into the prepared response data socket, for clients to read.

 

After the command processor written reply, it will delete the socket of AE_WRITABLE events and command responses association processor.

 

3. Why single-threaded memcached redis much higher than the efficiency of multi-threaded (redis Why is single-threaded, but can also support high concurrent)?

1) Pure memory operation

2) The core is based on the non-blocking IO multiplexing mechanism

3) single-threaded instead to avoid the frequent context switching multithreading issues (Baidu)

Guess you like

Origin www.cnblogs.com/qingmuchuanqi48/p/11129840.html