title: Unexplained latency with ValueOperations using Jedis
body: <p>We have Spring Boot web services hosted on AWS. They make frequent calls to a Redis Cluster cache using Jedis.</p>
  <p>During load testing, we're seeing increased latency around ValueOperations that we're having trouble figuring out.</p>
  <p>The method we've zoomed in on does two operations, a get followed by an expire.</p>
  <pre><code>public MyObject get(String key) {
      var obj = (MyObject)valueOps.get(key);
      if (obj != null) {
          valueOps.getOperations().expire(key, TIMEOUT_S, TimeUnit.SECONDS)
      }
  }
  </code></pre>
  <p>Taking measurements on our environment, we see that it takes 200ms to call &quot;valueOps.get&quot; and another 160ms calling &quot;expire&quot;, which isn't an acceptable amount of latency.</p>
  <p>We've investigated these leads:</p>
  <ul>
  <li>Thread contention. We don't currently suspect this. To test, we configured our JedisConnectionFactory with a JedisPoolConfig that has blockWhenExhausted=true and maxWaitMs=100, which if I understand correctly, means that if the connection pool is empty, a thread will block for 100ms waiting for a connection to be released before it fails. We had 0 failures running a load test with these settings.</li>
  <li>Slow deserializer. We have our Redis client configured to use GenericJackson2JsonRedisSerializer. We see latency with the &quot;expire&quot; call, which we don't expect has to use the deserializer at all.</li>
  <li>Redis latency. We used Redis Insights to inspect our cluster, and it's not pegged on memory or CPU when the load test is running. We also examined slowlog, and our slowest commands are not related to this operation (our slowest commands are at 20ms, which we're going to investigate).</li>
  </ul>
  <p>Does anyone have any ideas? Even a &quot;it could be this&quot; would be appreciated.</p>