Redis Performance Guidelines – Part 1

Anup MarwadiSoftwareLeave a Comment

Redis High Performance Tips

Redis is an amazing, in-memory, data structure store that is used by many large applications as an underlying data store as well as a high performance Cache.

Redis is a single threaded client, which means only one request can be processed at a time. To facilitate better Redis development, there are several important items we need to consider:

1. Don’t make redis payloads too big. 100KB is considered to be a large payload in Redis.

2. Don’t make clients wait too long to get their data or else hundreds of requests will start piling up and timeout will occur if they are not serviced in a timely manner.

3. Make sure there isn’t a lot of latency between the calling application and Redis. In terms of Data Centers, the Redis Server and the calling application have to reside in the same Data Center. In terms of Amazon/Azure, this means they have to reside in the same Region under the same Resource Groups (for Azure)

4. Make sure calling Clients have the bandwidth capacity to process incoming information rapidly. The last thing you want is the inability of a client to process an incoming request in a timely fashion thereby delaying other requests.

5. Try to pipeline multiple requests. Let’s say you have a method that needs a few items from the Redis. The right way of programming involves writing a method that checks Redis first, if the entry is available, it returns the value, else the record is fetched from the database. That way the logic to get a particular item is centralized behind one method. This comes with its own drawbacks because if you have 4 such methods that you need make 4 different round-trips to Redis.

The new way of thinking involves pipelining multiple Redis Requests into a single batch so that multiple round-trips are eliminated. Once the Redis responses come through, decisions can be made to invoke the Database to fetch records that were not available in Redis. It makes writing centralized code a little harder, but yields better outcomes. If you don’t think this is a big deal, your application probably isn’t getting the kind of traffic we see for some of the applications we make.

6. Stack Exchang C# Related – Treat the Redis Connection Multiplexer as a Singleton. This will save you a lot of frustration down the road. For a good implementation, check here: http://taswar.zeytinsoft.com/redis-for-net-developer-connecting-with-c/

7. Try using Hash data-structure instead of serializing JSON all the time for complex objects. This is again a departure from common-sense (or convenient) programming into a little bit more work but pays off huge dividends. We also know that Hashes are more performant so use them!

A couple of good reads here:

Leave a Reply

Your email address will not be published.