[Reserved] single-threaded performance Redis Why so high?

Redis advantage

High performance is not only related with the threading model, it has many reasons, mainly the following three points:

  1. Based on memory;
  2. Single thread, but the high utilization IO multiplexing;
  3. Data structure is optimized for high performance.

The following were elaborated.

Redis advantages: Memory-based

The level of performance is relative, Redis is a memory-based database, the relative comparison we take the traditional disk-based database, as shown:

Wherein, based on the Redis database memory, the scene points as follows:

  1. Data Query class scene: the memory had the full amount of data can be obtained directly from memory;
  2. Data is written like Scene: If you are configuring synchronization persistence, written to memory, it would also be written to disk, reduced performance, but because Redis using IO multiplexing, and there is no thread contention, therefore IO high utilization.
  3. Data is written like Scene: If you are configuring asynchronous persistence, successfully written to memory, that a successful response, without waiting for written to disk, and high performance.

Traditional disk databases, sub-scenario is as follows:

  1. Scene data query categories: index data from the disk, and returns the response to the query;
  2. Data is written like Scene: From the data written to disk, and update the index file on disk.

As can be seen above: Redis is a memory-based database, most of the operations done in memory, IO memory efficiency is much higher than the disk. So this is a reason for the high Redis performance.

Redis advantages: single-threaded, high IO IO utilization multiplexed

Redis is single-threaded, single-threaded process usually if not efficient, multi-threaded processing are open, but here Why Redis high back to the efficiency of it?

  1. Multithreading thread contention exist, and there is a lock problem, multi-threaded code logic complicated, complex logic usually bring some performance loss;
  2. Although Redis single-threaded, but it's "I / O multiplexer (multiplexing)" high utilization IO model.

Redis the "I / O multiplexing" is the most efficient epoll model used, but to achieve a single-threaded multi-client access, and high IO utilization. As shown below:

Redis advantage: optimized data structures for high performance

Optimized data structures are mainly the following two points (limited space, here is not started):

  1. Hash Redis full use of the structure, thus the access efficiency is very high;
  2. For storage of content data has been compressed, saving space occupied, but also reduce the io bandwidth.

Source: Wukong Q & A

Guess you like

Origin www.cnblogs.com/bjkandy/p/12055845.html