首页 > 其他 > 详细

解决Redis cluster的jedis驱动在高并发下的拥塞问题

时间:2016-05-31 14:17:42      阅读:685      评论:0      收藏:0      [点我收藏+]

redis cluster发布后我们项目中使用了cluster,使用驱动是jedis,但是在压力测试过程中发现有一定数量的redis访问非常缓慢高达几十秒数分钟,经过分析jedis驱动JedisClusterInfoCache中加锁造成

 

private Map<String, JedisPool> nodes = new HashMap<String, JedisPool>();
  private Map<Integer, JedisPool> slots = new HashMap<Integer, JedisPool>();

 

 

public JedisPool getNode(String nodeKey) {
    r.lock();
    try {
      return nodes.get(nodeKey);
    } finally {
      r.unlock();
    }
  }

  public JedisPool getSlotPool(int slot) {
    r.lock();
    try {
      return slots.get(slot);
    } finally {
      r.unlock();
    }
  }

将map替换成ConcurrentHashMap

private Map<String, JedisPool> nodes = new ConcurrentHashMap<String, JedisPool>();
 private Map<Integer, JedisPool> slots = new ConcurrentHashMap<Integer, JedisPool>();

去除锁

public JedisPool getNode(String nodeKey) {
    return nodes.get(nodeKey);
  }

 public JedisPool getSlotPool(int slot) {
    return slots.get(slot);
  }

 

测试后比较处理比较平稳,未出现某一个访问耗时非常长得的情况。

 

 

 

 

本文出自 “天涯时空” 博客,请务必保留此出处http://leshjmail.blog.51cto.com/629172/1784716

解决Redis cluster的jedis驱动在高并发下的拥塞问题

原文:http://leshjmail.blog.51cto.com/629172/1784716

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!