码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-05-31 14:18:01      阅读:2197      评论:0      收藏:0      [点我收藏+]

标签:redis cluster jedis 拥塞 耗时长

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驱动在高并发下的拥塞问题

标签:redis cluster jedis 拥塞 耗时长

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!