Fixes #1342 - Improve ByteBufferPool scalability.

Replaced Lock+ArrayDeque with ConcurrentLinkedDeque.
This commit is contained in:
Simone Bordet 2017-02-20 12:06:08 +01:00
parent 8fe94cd110
commit db7d89a5c9
1 changed files with 8 additions and 56 deletions

View File

@ -19,13 +19,11 @@
package org.eclipse.jetty.io;
import java.nio.ByteBuffer;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.eclipse.jetty.util.BufferUtil;
@ -128,8 +126,7 @@ public interface ByteBufferPool
class Bucket
{
private final Lock _lock = new ReentrantLock();
private final Queue<ByteBuffer> _queue = new ArrayDeque<>();
private final Deque<ByteBuffer> _queue = new ConcurrentLinkedDeque<>();
private final ByteBufferPool _pool;
private final int _capacity;
private final AtomicInteger _space;
@ -181,72 +178,27 @@ public interface ByteBufferPool
private void queueOffer(ByteBuffer buffer)
{
Lock lock = _lock;
lock.lock();
try
{
_queue.offer(buffer);
}
finally
{
lock.unlock();
}
_queue.offerFirst(buffer);
}
private ByteBuffer queuePoll()
{
Lock lock = _lock;
lock.lock();
try
{
return _queue.poll();
}
finally
{
lock.unlock();
}
return _queue.poll();
}
private void queueClear()
{
Lock lock = _lock;
lock.lock();
try
{
_queue.clear();
}
finally
{
lock.unlock();
}
_queue.clear();
}
boolean isEmpty()
{
Lock lock = _lock;
lock.lock();
try
{
return _queue.isEmpty();
}
finally
{
lock.unlock();
}
return _queue.isEmpty();
}
int size()
{
Lock lock = _lock;
lock.lock();
try
{
return _queue.size();
}
finally
{
lock.unlock();
}
return _queue.size();
}
@Override