【问题标题】:Jedis Get Data: JedisConnectionFailureException iterating a section of code over long period of timeJedis 获取数据:JedisConnectionFailureException 长时间迭代一段代码
【发布时间】:2016-08-20 16:04:48
【问题描述】:

所以我有一个使用 Jedis 客户端从 Redis 获取价值的代码。但是有一次,Redis 处于最大连接状态,并且抛出了这些异常:

org.springframework.data.redis.RedisConnectionFailureException
Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:140)
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:229)
...
org.springframework.data.redis.RedisConnectionFailureException
java.net.SocketTimeoutException: Read timed out; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
    at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:47)
    at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:36)
...
org.springframework.data.redis.RedisConnectionFailureException
Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:140)
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:229)

当我检查 AppDynamics 对此场景的分析时,我看到一些调用在很长一段时间内(1772 秒)进行了一些迭代。调用显示在片段中。

谁能解释这里发生了什么?为什么 Jedis 在 Timeout 设置(500 毫秒)后没有停止?我可以长期防止这种情况发生吗?

这就是我对 Jedis 的 Bean 定义的样子:

<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="100.90.80.70" p:port="6382" p:timeout="500" p:use-pool="true" p:poolConfig-ref="jedisPoolConfig" p:database="3" />

<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxTotal" value="1000" />
    <property name="maxIdle" value="10" />
    <property name="maxWaitMillis" value="500" />
    <property name="testOnBorrow" value="true" />
    <property name="testOnReturn" value="true" />
    <property name="testWhileIdle" value="true" />
    <property name="numTestsPerEvictionRun" value="10" />
</bean>

【问题讨论】:

    标签: java spring redis spring-data jedis


    【解决方案1】:

    我不熟悉 AppDynamics 输出。我认为这是线程及其睡眠时间的累积视图。所以线程被重用,所以睡眠时间加起来。在某些情况下,线程直接获得连接,无需任何等待,在另一个调用中,线程必须等待,直到可以提供连接。等待持续时间取决于连接何时可用或达到等待限制。

    让我们举个实际的例子:

    您的屏幕截图显示了一个等待172ms 的线程。假设 sleep 仅在 Jedis/Redis 调用路径中被调用,线程总共等待 172ms 获得连接。

    另一个等待530ms 的线程在我看来好像第一次尝试获得连接没有成功(这解释了第一次500ms),第二次尝试时,它不得不等待30ms .也可能是它为 265ms 等待了 2 倍。

    旁注:

    超过 1000 个连接可能会严重限制可扩展性。 Spring Data Redis 还支持其他不需要池但使用较少连接的驱动程序(请参阅Spring Data Redis Connectorshere)。

    【讨论】:

      猜你喜欢
      • 2021-11-18
      • 1970-01-01
      • 2018-12-02
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多