【问题标题】:How to check how many total redis connection , that a REDIS server can given to clients?如何检查 REDIS 服务器可以提供给客户端的总 redis 连接数?
【发布时间】:2018-09-06 16:41:02
【问题描述】:

我们正在使用 REDIS 缓存,并使用 Spring-Redis 模块,我们在应用程序配置中设置了 maxActiveConnections 10,但有时在我的应用程序中看到以下错误

Exception occurred while querying cache : 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

是因为在 Redis 服务器中他们没有更多的连接给我的应用程序或任何其他原因,有人可以就此提出建议吗?

注意:它们是 15 个应用程序,它们使用同一个 Redis 服务器来存储数据,我的意思是 15 个应用程序只需要来自这个单一的 Redis 服务器的连接,现在我们将每个应用程序的 maxActiveConnections 设置为 10 15 个应用程序

【问题讨论】:

  • 我不确定应用程序限制,但是如果 redis 获得的请求超过它可以处理的数量(请注意,这不是应用程序,它是请求的总数),它会将它们存储在队列中,并且如果redis队列满了,redis可以丢弃进一步的请求,直到队列未满。

标签: spring caching redis spring-data-redis


【解决方案1】:

要检查有多少客户端连接到redis,您可以使用redis-cli 并输入以下命令:redis> INFO 更具体地说是info Clients 命令。

192.168.8.176:8023> info Clients
# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

表单Jedis源码,貌似出现异常的原因如下:

  1. Exhausted cache: // 异常是由一个耗尽的池引起的
  2. 或 // 否则,异常是由实现的activateObject()ValidateObject() 引起的

这里是JedisgetResource方法的代码sn-p:

  public T getResource() {
    try {
      return internalPool.borrowObject();
    } catch (NoSuchElementException nse) {
      if (null == nse.getCause()) { // The exception was caused by an exhausted pool
        throw new JedisExhaustedPoolException(
            "Could not get a resource since the pool is exhausted", nse);
      }
      // Otherwise, the exception was caused by the implemented activateObject() or ValidateObject()
      throw new JedisException("Could not get a resource from the pool", nse);
    } catch (Exception e) {
      throw new JedisConnectionException("Could not get a resource from the pool", e);
    }
  }

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 2018-07-29
    • 2022-07-02
    • 2012-06-15
    • 1970-01-01
    • 2019-11-25
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多