[concurrency-interest] Performance of LinkedBlockingQueue.poll()

Baker, Anthony abaker at c-cor.com
Wed Jul 6 12:42:33 EDT 2005


Thanks for the info.  The profiling vendor is investigating the issue and suspects a potential vm thread state reporting problem.  I've included a test case, just in case anyone is interested:

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
//import EDU.oswego.cs.dl.util.concurrent.BoundedLinkedQueue;

public class QueueTest {

  private static final int _rate = 5;
  private LinkedBlockingQueue<Object> _queue = new LinkedBlockingQueue<Object>(100);
  //private BoundedLinkedQueue _queue = new BoundedLinkedQueue(100);

  public static void main(String[] args) {
    QueueTest test = new QueueTest();
    new Thread(test.new RatedProducer()).start();
    new Thread(test.new Consumer()).start();
  }

  private class RatedProducer implements Runnable {
    public void run() {
      while (!Thread.interrupted()) {
        try {
          _queue.put(new Object());
          Thread.sleep(_rate); // simulate request/reply

        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
        }
      }
    }
  }

  private class Consumer implements Runnable {

    public void run() {
      while (!Thread.interrupted()) {
        try {
          Object o = _queue.poll(1000, TimeUnit.MILLISECONDS);
//          Object o = _queue.poll(1000);

        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
        }
      }
    }
  }
}

Anthony



-----Original Message-----
From: Doug Lea [mailto:dl at cs.oswego.edu]
Sent: Thu 6/30/2005 8:27 AM
To: Baker, Anthony
Cc: concurrency-interest at altair.cs.oswego.edu
Subject: Re: [concurrency-interest] Performance of LinkedBlockingQueue.poll()
 
Baker, Anthony wrote:
> Hi,
> 
> During a recent profiling session, I was surprised to discover a 
> perfomance hotspot identified as LinkedBlockingQueue.poll().  The 
> profiler recorded about 39k invocations of poll() as accummulating 139s 
> of cpu time (that's an avg of about 3.5ms per invocation).  Is this a 
> known issue or perhaps a profiling artifact?  Switching back to Doug 
> Lea's BoundedLinkedQueue removed this hotspot.

LinkedBlockingQueue is faster than old BoundedLinkedQueue on
every test I have. If you can put something together that
we can use to replicate your results, we'd be happy to try to
help diagnose and further improve it.


-Doug


-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20050706/af9fdf1f/attachment.htm


More information about the Concurrency-interest mailing list