Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis request latency

Tags:

php

redis

I'm using redis (2.6.8) with php-fpm and phpredis driver and have some trouble with redis latency issues. Under certain load first request to redis from our application takes about 1-1.5s and redis-cli --latency shows the same latency.

I've already checked the latency guide.

  • We use redis on the same host with Unix sockets
  • slowlog has no entries longer 5ms
  • we don't use AOF
  • redis takes about 3.5Gb memory of 16Gb available (i suppose it's not too much)
  • our system is not swapping
  • there is no other process doing disk I/O

I'm using persistent connections and amount of connected client is varying from 5 to 25 (sometimes strikes to 60-80).

Here is the graph.

It looks like problems starts when there are 20 or more simultaneously connected clients.

Can you help me to figure out where is the problem?

Update

I investigated the problem and it seemed like redis did not have enough processor time for some reason to operate properly.

I thoroughly checked communication between php-fpm and redis with the help of network sniffer. Redis received request over tcp but sent the answer back only after one and a half seconds. It obviously signified that the problem is inside redis, that it cannot process so many requests in the given conditions (possibly processor starvation as the processor was only 50% loaded for the whole system).

The problem was resolved by moving redis to other server that was nearly idle. I suppose that we should have played with linux scheduler to make it work on the same server, but have not done it yet.

like image 729
S3RK Avatar asked Jan 24 '13 09:01

S3RK


People also ask

Is Redis faster than HTTP?

In the end, it results in a performance boost of over 100x using Redis instead of HTTP.

How many requests can Redis handle per second?

For instance, using pipelining Redis running on an average Linux system can deliver even 1 million requests per second, so if your application mainly uses O(N) or O(log(N)) commands, it is hardly going to use too much CPU.

How fast Redis is?

For instance a benchmark setting 4 KB strings in Redis at 100000 q/s, would actually consume 3.2 Gbit/s of bandwidth and probably fit within a 10 Gbit/s link, but not a 1 Gbit/s one. In many real world scenarios, Redis throughput is limited by the network well before being limited by the CPU.

Is Redis as fast as memory?

Redis runs in-memory, which enables low-latency and high throughput. Running in-memory means requests for data do not require a trip to disk. This leads to an order of magnitude more operations and faster response times. Redis is one of the only databases that supports millions of operations per second.


1 Answers

Bear in mind that Redis is single-threaded. If the operations that you're doing err on the processor-intensive side, your requests could be blocking on each other. For instance, if you're doing HVALS against hashes with very large values, you're going to make all of your clients wait while you pull out all that data and copy it to the output buffer.

Part of what you need to do here (regardless if this is the issue) is to look at all of the commands that you're using and determine the complexity of each command. If you're doing a bunch of O(N) commands against very large amounts of data, it's not impossible that you're simply doing too much stuff at a time.

TL;DR Nobody on here can debug this issue with real certainty without knowing which commands you're using and what your data looks like. But you can look up the time complexity of each method you're using and make sure it's reasonable.

like image 180
mattbasta Avatar answered Sep 20 '22 16:09

mattbasta