Re: J2SE 5
Jean Morissette <[email protected]> Mon, 18 Oct 2004 12:01:59 -0400
| Newsgroups | gmane.comp.java.seda.user |
|---|---|
| Message-ID | <[email protected]> |
Quartz wrote:
> New prototype thread manager could be written, but once benchmarked, they might need tuning that
> concurrent.util may deny. FiniteQueue is a good example of fine tuned queue, since the queue
> elements wrappers (ssLinkedList) are pooled. Just proove it to yourself: ssLinkedList is MUCH
> faster than any jdk list.
Hi Quartz,
I have done some preliminary microbenchmarks and it's not clear that
FiniteQueue is MUCH faster.
The test (see below) have 1 producer and 1 consumer that respectively
enqueue and dequeue a QueueElement object. This object is reused to
just evaluate queue concurrency.
Here is the results:
______________________________________________________
| | offer-poll | offer-take | put-pool | put-take |
|----+------------+------------+-----------+----------|
|LBQ | 4 100 000 | 11 000 000 | 7 500 000 | 800 000 |
|ABQ | 35 000 | 490 000 | 487 000 | 507 000 |
|CLQ | 3 500 000 | - | - | - |
| FQ | 4 400 000 | 400 000 | - | - |
______________________________________________________
Legend:
LBQ -> LinkedBlockingQueue
ABQ -> ArrayBlockingQueue
CLQ -> ConcurrentLinkedQueue
FQ -> FiniteQueue
offer -> enqueue
pool -> dequeue
take -> blocking_dequeue
put -> blocking_enqueue (FiniteQueue don't have this method)
FiniteQueue have almost the same performance than LinkedBlockingQueue in
test 'offer-poll' (thus without waiting). But, LinkedBlockingQueue
outperform FiniteQueue more than an order of magnitude in test
'offer-take'. This is an important result because 'offer' and 'take'
are the mostly used operations in currently SandStorm ThreadManagers.
Also, I don't see a performance difference with pooled ssLinkedList nodes.
Do you have done some optimizations that I'm not aware to say that
FiniteQueue is faster?
Thank
Jean
Test sample:
public class ProducerConsumerQueueTest {
static QueueElementIF NULL_OBJECT = new QueueElementIF() {};
static int i = 0;
static void testLBQ() throws InterruptedException {
BlockingQueue q = new LinkedBlockingQueue();
Producer1 p = new Producer1(q);
Consumer1 c1 = new Consumer1(q);
new Thread(p).start();
new Thread(c1).start();
Thread.sleep(10000);
System.out.println(i);
}
static class Producer1 implements Runnable {
private final BlockingQueue queue;
Producer1(BlockingQueue q) { queue = q; }
public void run() {
try {
while(true) { queue.offer(produce()); }
} catch (Exception ex) { }
}
Object produce() { return NULL_OBJECT; }
}
static class Consumer1 implements Runnable {
private final BlockingQueue queue;
Consumer1(BlockingQueue q) { queue = q; }
public void run() {
try {
while(true) { consume(queue.poll()); }
} catch (Exception ex) { }
}
void consume(Object x) { if (x != null) i++; }
}
}
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl