[concurrency-interest] ConcurrentLinkedQueue vs. ConcurrentLinkedDeque

Martin Buchholz martinrb at google.com
Fri Feb 26 11:38:15 EST 2016


It's not really expected.  The expectation is (as is written in the source)

     * Empirically, microbenchmarks suggest that this class adds about
     * 40% overhead relative to ConcurrentLinkedQueue, which feels as
     * good as we can hope for.

You're using "interior removes" (remove(Object), which the
implementations support, but we have sometimes regretted that.  If we
could outlaw interior removes, the code would be much simpler.

I'll poke at this a bit.

On Fri, Feb 26, 2016 at 4:58 AM, Christian Schudt
<christian.schudt at gmx.de> wrote:
> Hello,
>
> I've had performance problems (high CPU) in my app and after research I suspected ConcurrentLinkedQueue to be a possible source (due to [1], [2]).
>
> Although I am still not sure it's really the source for my problem, I discovered significant performance differences between ConcurrentLinkedQueue and ConcurrentLinkedDeque:
>
>     public static void main(String[] args) {
>
>         Queue<String> queue = new ConcurrentLinkedDeque<>();
>         String a = "a";
>         String b = "b";
>         queue.offer(a);
>         for (int i = 0; ; i++) {
>             if (i % 1024 == 0) {
>                 System.out.println("i = " + i);
>             }
>             queue.offer(b);
>             queue.remove(b);
>         }
>     }
>
> ConcurrentLinkedDeque is much faster! (Just replace it with ConcurrentLinkedQueue, the output becomes very slow)
>
> Not sure, if this is related to JDK-8054446 [2] or if it's "normal".
> Any comments?
>
> Is there any reason to prefer ConcurrentLinkedQueue over ConcurrentLinkedDeque?
>
> (I am using JDK 8u60.)
>
> Kind regards,
> Christian
>
> [1]: https://perfstories.wordpress.com/2012/08/01/why-does-cpu-utilization-happen-sometimes/
> [2]: https://bugs.openjdk.java.net/browse/JDK-8054446
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest


More information about the Concurrency-interest mailing list