in reply to Thread::Queue vs Thread::Queue::Any
I'm very surprised at your results!
T::Q::A is a subcless of T:Q, so it does everything that TQ does, and some extra stuff on top, so how can it be quicker?
Especially as the 'extra' it does is to serialise the data passed into a mod//Storable::Freeze bytestring when enqueuing and unfreezing when dequeing. Neither of which is know to a an especially fast operation.
What puzzles me even more is that your benchmark is broken:
if($test_queue_any){ $queue_any->enqueue(%rec); }else{ $queue->enqueue(\%rec); }
For TQA,
For TQ, you queue a scalar (reference) directly to the queue, and the return that reference to the caller.
So both exchange a single scalar between the threads, but one does it directly; the other indirects through a subclass and flattens, freezes, thaws and reconstructs the hash on the way through.
How could the latter possibly be faster?
How could it possibly show fewer lock states--since the exact same underlying code is being used in both cases?
So I ran you code and got:
C:\test>TQ-TQA-b.pl START LOAD 1 START LOAD 2 ... START LOAD 15 START LOAD 16 START WORKER 17 START WORKER 18 ... START WORKER 31 START WORKER 32 STOP LOAD 6 STOP LOAD 1 ... STOP LOAD 12 STOP LOAD 16 STOP WORKER 23 STOP WORKER 19 ... STOP WORKER 20 STOP WORKER 26 ------------------------------------ TEST QUEUE:15(seconds) ------------------------------------ Enter an key to continue... START LOAD 33 START LOAD 34 ... START LOAD 47 START LOAD 48 START WORKER 49 START WORKER 50 ... START WORKER 63 START WORKER 64 STOP LOAD 33 STOP LOAD 35 ... STOP LOAD 48 Odd number of elements in hash assignment at C:\test\TQ-TQA-b.pl line +80, <STDIN> line 1. STOP WORKER 58 Odd number of elements in hash assignment at C:\test\TQ-TQA-b.pl line +80, <STDIN> line 1. Odd number of elements in hash assignment at C:\test\TQ-TQA-b.pl line +80, <STDIN> line 1. ... Odd number of elements in hash assignment at C:\test\TQ-TQA-b.pl line +80, <STDIN> line 1. STOP WORKER 53 STOP WORKER 63 ------------------------------------ TEST QUEUE ANY:20(seconds) ------------------------------------
Besides the warnings, which are essentially trivial compared to the other brokeness of the benchmark--more a sign of your lack of understanding of hashes than a serious problem--I get TQA taking 33% longer than TQ; which gels with my expectations!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Thread::Queue vs Thread::Queue::Any
by gulden (Monk) on Jul 14, 2009 at 21:48 UTC | |
by BrowserUk (Patriarch) on Jul 14, 2009 at 21:55 UTC | |
| |
| A reply falls below the community's threshold of quality. You may see it by logging in. |