[concurrency-interest] PooledLinkedBlockingQueue

Jeff Schultz jws@cs.mu.OZ.AU
Thu, 04 Nov 2004 11:27:40 +1100


> Thanks for your comments, it's appreciated.  I just want to believe you, 
> but how do you explain the test below.  I have modified Sun LinkedList 
> into MyPooledLinkedList.  This class is exacly like LinkedList, so its 
> not thread-safe.  The test show a huge performance difference between 
> the two lists: MyPooledLinkedList is a  an order of magnitude more fast! 
>   On my computer, LinkedList take 127400 ms and MyPooledLinkedList take 
> 16500 ms.  Could you explain this difference please?  Am-I missing 
> something?
> 
> Thanks
> Jean
> 
> import java.util.LinkedList;
> 
> public class Test {
> 
>    private static final int NUM_IT = 100000000;
>    private static final int WARM_UP_IT = NUM_IT / 100;
>    static Object NULL_OBJECT = new Object() {};
> 
>    /*
>    LinkedList:            time  = 127458  124624
>    MyPooledLinkedList     time  =  16555   16277
>    */
>    public static void main(String args[]) throws Exception {
>      main1(); // pooled list item objects, very fast
> //    main2();   // sun's linked list: very long
>    }
> 
>    public static void main1() {
>      MyPooledLinkedList ll = new MyPooledLinkedList();
>      long before, after;
> 
>      for (int i = 0; i < WARM_UP_IT; i++) {
>        ll.addFirst(NULL_OBJECT);
> //      ll.removeLast();
>      }
> 
>      before = System.currentTimeMillis();
>      for (int i = 0; i < NUM_IT; i++) {
>        ll.addFirst(NULL_OBJECT);
>        ll.removeLast();
>      }
>      after = System.currentTimeMillis();
>      System.out.print("MyPooledLinkedList: ");
>      printTime(before, after, NUM_IT);
>    }

Without wanting to look at what you've done to SUN's LinkedList, I'd
observe that you have 1 million nodes in use at any one time, and the
lifetime of each node is 1 million allocations.  These will not
usually fit in the nursery, so for the non-pooled case they're all
getting tenured (expensive) and then dying soon after.  Try it with a
smaller number of nodes in use, or change the GC parameters to
increase the size of the nursery and I'd expect you to see different
performance.


    Jeff Schultz