After Redis Cluster was released, we used cluster in the project, and the driver was Jedis, but during the stress test it was found that a certain number of Redis accesses were very slow up to dozens of seconds and a few minutes, After analysis Jedis drive Jedisclusterinfocache in the lock caused by
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 ();
}
}
Replace the map with Concurrenthashmap
Private map<string, jedispool> nodes = new concurrenthashmap<string, jedispool> ();
Private Map<integer, jedispool> slots = new Concurrenthashmap<integer, jedispool> ();
Remove lock
Public Jedispool getnode (String nodekey) {
Return Nodes.get (Nodekey);
}
Public Jedispool getslotpool (int slot) {
return Slots.get (slot);
}
After testing the comparison process is relatively smooth, there is no time for a visit to a very long situation.
This article is from "Tianya Time and Space" blog, please make sure to keep this source http://leshjmail.blog.51cto.com/629172/1784716
Solving the congestion problem of Redis cluster Jedis drive under high concurrency