Question – Is Redis fast?

Redis is an open source memory based data storage system, and since it’s memory based, it’s not that bad.

Memory is designed for the CPU to read data quickly.

On a graph

This graph is not accurate enough, although it is Aida64de Benchmark. But I ran so many apps and services that I used 16 gigabytes of memory on the run

The first line of Memory is the memory-related benchmark data.

Read 51024MB/ s, can read nearly 50 G per second, response time 68.6 nanoseconds!! The response time is 68.6 nanoseconds, and the hit data is accurate enough to give the desired result.

Compared to ordinary hard disk, millisecond response time is not too fast.

This is my NVME solid state drive, and the mechanical drive is even slower.

Mechanical disk 8.3 milliseconds. You can see that hitting a piece of data from memory is a hundred times faster than hitting a piece of data from disk

.

This is the response speed of my Kingston SSD solid-state….

Is there any conclusion

  • Is Redis fast?
  • Is redis always fast
  • Is Redis necessarily fast in different environments?

Practice is the mother of wisdom

Using redis’s own benchmark test, 50 clients were simulated to request 100,000 3-byte data from Redis on the LAN.

Exe -h 192.168.3.21 -c 50

It’s intercepted, or it’s too long, 99% of the requests are answered, 1% are discarded.

====== PING_INLINE ====== 100000 requests completed in 12.99 seconds 12.99 seconds 50 Parallel clients --50 parallel clients 3 bytes Payload 3 bytes Payload Keep alive: 1 milliseconds 24.64% <= 2 milliseconds 32.21% <= 3 milliseconds 41.42% <= 4 milliseconds 56.16% <= 5 Milliseconds 70.02% <= 6 milliseconds 80.22% <= 7 milliseconds 83.89% <= 8 milliseconds 88.50% <= 9 milliseconds 93.95% <= 10 milliseconds 97.28% <= 11 milliseconds 99.65% <= 12 milliseconds 7700.01 requests per second ====== PING_BULK ====== 100000 requests completed in 13.96 seconds 50 Parallel clients 3 bytes Payload keep alive: 1 milliseconds 11.43% <= 2 milliseconds 25.74% <= 3 milliseconds 38.06% <= 4 milliseconds 53.93% <= 5 Milliseconds 68.64% <= 6 milliseconds 78.01% <= 7 milliseconds 86.27% <= 8 milliseconds 92.55% <= 9 milliseconds 94.83% <= 10 milliseconds 99.56% <= 11 milliseconds 99.90% <= 15 milliseconds 7164.86 requests per second ====== SET ====== 100000 requests completed in 13.96 seconds 50 PARALLEL clients 3 bytes Payload keep alive: 1 milliseconds 14.14% <= 2 milliseconds 29.57% <= 3 milliseconds 43.32% <= 4 milliseconds 59.30% <= 5 Milliseconds 72.35% <= 6 milliseconds 85.49% <= 7 milliseconds 96.92% <= 8 milliseconds 7161.78 requests per second ====== GET ====== 100000 requests completed in 14.59 seconds 50 Parallel clients 3 bytes Payload keep alive: 1 milliseconds 15.16% <= 2 milliseconds 30.32% <= 3 milliseconds 44.10% <= 4 milliseconds 58.19% <= 5 Milliseconds 72.53% <= 6 milliseconds 86.59% <= 7 milliseconds 93.48% <= 8 milliseconds 99.13% <= 9 milliseconds 99.36% <= 10 milliseconds 6855.89 requests per second ====== INCR ====== 100000 requests completed in 14.04 seconds 50 PARALLEL  clients 3 bytes payload keep alive: 1 0.18% <= 1 milliseconds 11.57% <= 2 milliseconds 30.22% <= 3 milliseconds 42.40% <= 4 milliseconds 56.65% <= 5 Milliseconds 66.35% <= 6 milliseconds 76.44% <= 7 milliseconds 93.92% <= 8 milliseconds 98.35% <= 9 milliseconds 7124.54 Requests per second ====== LRANGE_600 (First 600 Elements) ====== 100000 requests completed in 48.45 seconds 50 parallel clients 3 bytes payload keep alive: 1 0.00% <= 2 milliseconds <= 3 milliseconds 0.01% <= 4 milliseconds 0.01% <= 5 milliseconds 0.02% <= 6 Milliseconds 0.03% <= 7 milliseconds 0.03% <= 8 milliseconds 0.04% <= 9 milliseconds 0.05% <= 10 milliseconds 0.13% <= 11 milliseconds 0.47% <= 12 milliseconds 1.82% <= 13 milliseconds 5.16% <= 14 milliseconds 11.33% <= 15 milliseconds 17.60% <= 16 milliseconds 22.83% <= 17 milliseconds 27.77% <= 18 milliseconds 31.74% <= 19 milliseconds 35.32% <= 20 Milliseconds 39.16% <= 21 milliseconds 44.86% <= 22 milliseconds 94.72% <= 23 milliseconds 97.87% <= 24 milliseconds 98.74% <= 25 milliseconds 99.24% <= 26 milliseconds 2063.86 requests per second ====== MSET (10 keys) ====== 100000 Requests completed in 14.00 seconds 50 PARALLEL clients 3 bytes Payload keep alive: 1 0.03% <= 1 milliseconds 13.21% <= 2 milliseconds 32.76% <= 3 milliseconds 43.76% <= 4 milliseconds 58.45% <= 5 Milliseconds 75.08% <= 6 milliseconds 84.89% <= 7 milliseconds 94.41% <= 8 milliseconds 97.84% <= 9 milliseconds 99.13% <= 10 milliseconds 99.50% <= 11 milliseconds 99.56% <= 12 milliseconds 7141.84 requests per secondCopy the code

Most requests were completed within 10 ms, but some were slow, such as LRANGE_600 (First 600 Elements), which at one point reached over 300 ms (due to increased redis service pressure).

One memory request took 300 milliseconds.

So is Redis really faster than MySQL?

An ID query from mysql takes 14 milliseconds.

So why?

While the memory response is nanosecond, network IO consumes time.

The network I/O delay is determined by: server response delay + bandwidth limit + network delay + forward route delay + local receive delay. (Usually tens to thousands of milliseconds, greatly affected by environmental interference)

Therefore, nanosecond redis is still used in milliseconds and even tens of milliseconds.

Mysql is not necessarily slower than Redis in some index queries, just one ID query was only a few milliseconds slower.

Is the meaning of redis to be so fastA few milliseconds?

The answer must be no.

  1. Redis is noSQL. It gives us another way to access our data.
  2. Let’s get our data, in another way, quickly into the hands of the program.
  3. Let’s give mysql and disk a break.
  4. Some mysql queries don’t complete in tens of milliseconds, but redis queries don’t vary much in response time.
  5. For frequently accessed content, I don’t have to repeat the following process
    Program preparation SQL -> JDBC pool obtain links (none or core links need to be created)-> Set up network IO Send SQL commands ->mysql receives requests, parses optimized statements ->mysql uses storage engines to query data -> Collate data, uses network IO to respond to query content -> One request endsCopy the code

    We can cache the results of a series of mysql operations in memory. Reduce server CPU, hard disk, memory used by mysql, network bandwidth, etcResource overhead.

conclusion

Redis is fast?

  • Redis fast, but Redis is not a cure-all. It’s okay to dump everything to Redis, but remember that the same amount of memory costs a lot more than a hard drive.
  • The content should also be appropriate. This can give full play to the role of cache.
  • Use redis in the right environment. Be aware that Redis also has network IO that limits its speed.

Clean up the hardware data response time.

CPU Cache level 1 tenths of a nanosecond level 2 nanoseconds of a nanosecond level 3 Tens of a nanosecond level 4 tens of a nanosecond level Memory Dozens of a nanosecond nic millisecond - second, affected by the network environment Hard disk MillisecondCopy the code