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:
parent
732dc44136
commit
3727ac9bde
@ -378,6 +378,9 @@ Release 2.3.0 - UNRELEASED
|
||||
HADOOP-9594. Update apache commons math dependency (Timothy St. Clair via
|
||||
stevel)
|
||||
|
||||
HADOOP-10095. In CodecPool, synchronize pool and codecList separately in
|
||||
order to reduce lock contention. (Nicolas Liochon via szetszwo)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
HADOOP-9748. Reduce blocking on UGI.ensureInitialized (daryn)
|
||||
|
@ -85,16 +85,15 @@ private static <T> T borrow(Map<Class<T>, List<T>> pool,
|
||||
T codec = null;
|
||||
|
||||
// Check if an appropriate codec is available
|
||||
List<T> codecList;
|
||||
synchronized (pool) {
|
||||
if (pool.containsKey(codecClass)) {
|
||||
List<T> codecList = pool.get(codecClass);
|
||||
codecList = pool.get(codecClass);
|
||||
}
|
||||
|
||||
if (codecList != null) {
|
||||
synchronized (codecList) {
|
||||
if (!codecList.isEmpty()) {
|
||||
codec = codecList.remove(codecList.size()-1);
|
||||
}
|
||||
}
|
||||
if (codecList != null) {
|
||||
synchronized (codecList) {
|
||||
if (!codecList.isEmpty()) {
|
||||
codec = codecList.remove(codecList.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -105,15 +104,17 @@ private static <T> T borrow(Map<Class<T>, List<T>> pool,
|
||||
private static <T> void payback(Map<Class<T>, List<T>> pool, T codec) {
|
||||
if (codec != null) {
|
||||
Class<T> codecClass = ReflectionUtils.getClass(codec);
|
||||
List<T> codecList;
|
||||
synchronized (pool) {
|
||||
if (!pool.containsKey(codecClass)) {
|
||||
pool.put(codecClass, new ArrayList<T>());
|
||||
codecList = pool.get(codecClass);
|
||||
if (codecList == null) {
|
||||
codecList = new ArrayList<T>();
|
||||
pool.put(codecClass, codecList);
|
||||
}
|
||||
}
|
||||
|
||||
List<T> codecList = pool.get(codecClass);
|
||||
synchronized (codecList) {
|
||||
codecList.add(codec);
|
||||
}
|
||||
synchronized (codecList) {
|
||||
codecList.add(codec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user