HADOOP-10095. In CodecPool, synchronize pool and codecList separately in order to reduce lock contention. Contributed by Nicolas Liochon

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1541750 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2013-11-13 22:50:58 +00:00
parent 732dc44136
commit 3727ac9bde
2 changed files with 19 additions and 15 deletions

View File

@ -378,6 +378,9 @@ Release 2.3.0 - UNRELEASED
HADOOP-9594. Update apache commons math dependency (Timothy St. Clair via HADOOP-9594. Update apache commons math dependency (Timothy St. Clair via
stevel) stevel)
HADOOP-10095. In CodecPool, synchronize pool and codecList separately in
order to reduce lock contention. (Nicolas Liochon via szetszwo)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-9748. Reduce blocking on UGI.ensureInitialized (daryn) HADOOP-9748. Reduce blocking on UGI.ensureInitialized (daryn)

View File

@ -85,9 +85,10 @@ public class CodecPool {
T codec = null; T codec = null;
// Check if an appropriate codec is available // Check if an appropriate codec is available
List<T> codecList;
synchronized (pool) { synchronized (pool) {
if (pool.containsKey(codecClass)) { codecList = pool.get(codecClass);
List<T> codecList = pool.get(codecClass); }
if (codecList != null) { if (codecList != null) {
synchronized (codecList) { synchronized (codecList) {
@ -96,8 +97,6 @@ public class CodecPool {
} }
} }
} }
}
}
return codec; return codec;
} }
@ -105,18 +104,20 @@ public class CodecPool {
private static <T> void payback(Map<Class<T>, List<T>> pool, T codec) { private static <T> void payback(Map<Class<T>, List<T>> pool, T codec) {
if (codec != null) { if (codec != null) {
Class<T> codecClass = ReflectionUtils.getClass(codec); Class<T> codecClass = ReflectionUtils.getClass(codec);
List<T> codecList;
synchronized (pool) { synchronized (pool) {
if (!pool.containsKey(codecClass)) { codecList = pool.get(codecClass);
pool.put(codecClass, new ArrayList<T>()); if (codecList == null) {
codecList = new ArrayList<T>();
pool.put(codecClass, codecList);
}
} }
List<T> codecList = pool.get(codecClass);
synchronized (codecList) { synchronized (codecList) {
codecList.add(codec); codecList.add(codec);
} }
} }
} }
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <T> int getLeaseCount( private static <T> int getLeaseCount(