0
        RedisFuture<List<KeyValue<String, String>>> future = redisStatsConnection.hmget(key, 10);
if (!future.await(500, TimeUnit.MILLISECONDS)) {
                ....
            }

I used Redis with Java and Lettuce. For RedisAdvancedClusterAsyncCommands.hmget, I am trying to add a timeout for it. I think it should be done within 10 milliseconds or so, but it always times out till I am keeping increasing the number.

Could I know what is the average timeout for Redis? or is there any other suggestion?

Grant Foster
  • 722
  • 2
  • 11
  • 21
ewrwerwe
  • 45
  • 1
  • 4

1 Answers1

0

The time it takes for the request to complete is affected by the following things:

  1. The network roundtrip time (usually ~1ms with most cloud providers, less in dedicated LANs)

  2. Serialization/deserialization of the request - if you do HMGET of 1 million keys that can be a lot of time.

  3. Internal processing of the request inside redis. Again, usually not a lot (it can be a few microseconds in fast cases) of time, but it's O(n) for the number of elements in the HMGET.

  4. Serialization / deserializtion of the response. The larger the payload of the HMGET, the longer it takes. Redis needs to copy the data to the network buffers, and the client needs to parse the responses. If your response is large that can be a significant time spent in the client library or in redis.

  5. Network bandwidth - the larger the response, the more packets the network needs to send back. You don't expect a 1GB response to return in 10ms, right?

  6. Other requests processed by redis. That's rarely a problem, but if you have long running Lua scripts, KEYS commands, aggregate intersections or unions running - since redis is single threaded, every request delays all other requests.

What I'm saying is that it really depends on what you are doing and what other things you are doing. 10ms is probably too low. Also, remember that latency has a distribution, and you should plan for the average, median, 90th percentile and 99th percentile expected latencies of your app.

Not_a_Golfer
  • 47,012
  • 14
  • 126
  • 92