For benchmarking 50,000 messages the following two scripts were made, based on the one found here.

$ diff hobo_test.pl threads_test.pl 5,6c5,6 < use MCE::Hobo; < use Foo::Inbox2; --- > use threads; > use Foo::Inbox4; 11c11 < my $inbox = Foo::Inbox2->new( @names ); --- > my $inbox = Foo::Inbox4->new( @names ); 38,39c38,39 < MCE::Hobo->create(\&foo, $_) for @names; < MCE::Hobo->waitall; --- > threads->create(\&foo, $_) for @names; > $_->join() for threads->list();

Foo::Inbox2 via MCE::Hobo + MCE::Shared->queue 50k test

use strict; use warnings; use MCE::Hobo; use Foo::Inbox2; use List::Util qw( shuffle ); use Time::HiRes qw( time ); my @names = shuffle qw/ Barny Betty Fred Wilma /; my $inbox = Foo::Inbox2->new( @names ); my $start = time; $| = 1; sub foo { my $name = shift; my $count = 0; # remove my name from the list @names = grep { $_ ne $name } shuffle @names; # send greeting $inbox->send($name, \@names, 'Hello'); while ( my ($from, $data) = $inbox->recv($name) ) { # display the message received printf "%-5s received %s from %s\n", $name, $data->[0], $from; # send greeting again $inbox->send($name, \@names, 'Hello') if $count < 4167; # eventually stop benchmarking last if ++$count == 12500; } } MCE::Hobo->create(\&foo, $_) for @names; MCE::Hobo->waitall; printf {*STDERR} "duration: %0.03f seconds\n", time - $start;

Foo::Inbox4 via threads + Thread::Queue 50k test

use strict; use warnings; use threads; use Foo::Inbox4; use List::Util qw( shuffle ); use Time::HiRes qw( time ); my @names = shuffle qw/ Barny Betty Fred Wilma /; my $inbox = Foo::Inbox4->new( @names ); my $start = time; $| = 1; sub foo { my $name = shift; my $count = 0; # remove my name from the list @names = grep { $_ ne $name } shuffle @names; # send greeting $inbox->send($name, \@names, 'Hello'); while ( my ($from, $data) = $inbox->recv($name) ) { # display the message received printf "%-5s received %s from %s\n", $name, $data->[0], $from; # send greeting again $inbox->send($name, \@names, 'Hello') if $count < 4167; # eventually stop benchmarking last if ++$count == 12500; } } threads->create(\&foo, $_) for @names; $_->join() for threads->list(); printf {*STDERR} "duration: %0.03f seconds\n", time - $start;

Update: Added results for MCE::Inbox which will ship with MCE::Shared 1.827 on release day. It is Inbox2 with optimizations.

Results from Mac OS X and Cent OS 7.

# Mac OS X ( Perl v5.18.2 ) $ perl foo1.pl | wc -l # Foo::Inbox duration: 0.690 seconds 50000 $ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability duration: 0.721 seconds 50000 $ perl foo2.pl | wc -l # MCE::Shared->queue duration: 0.789 seconds 50000 $ perl foo4.pl | wc -l # Thread::Queue duration: 5.735 seconds 50000 # CentOS 7 VM ( Perl v5.16.3 ) $ perl foo1.pl | wc -l # Foo::Inbox duration: 0.834 seconds 50000 $ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability duration: 0.726 seconds 50000 $ perl foo2.pl | wc -l # MCE::Shared->queue duration: 0.945 seconds 50000 $ perl foo4.pl | wc -l # Thread::Queue duration: 3.020 seconds 50000

Results from Cygwin and Strawberry Perl.

# Windows ( Cygwin Perl v5.22.3 ) $ perl foo1.pl | wc -l # Foo::Inbox duration: 1.825 seconds 50000 $ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability duration: 2.059 seconds 50000 $ perl foo2.pl | wc -l # MCE::Shared->queue duration: 2.387 seconds 50000 $ perl foo4.pl | wc -l # Thread::Queue duration: 24.086 seconds 50000 # Windows ( Strawberry Perl v5.22.2.1 ) $ perl foo1.pl > nul # Foo::Inbox duration: 1.570 seconds $ perl inbox.pl > nul # MCE::Inbox w/ blocking capability duration: 1.664 seconds $ perl foo2.pl > nul # MCE::Shared->queue duration: 2.120 seconds $ perl foo4.pl > nul # Thread::Queue duration: 2.886 seconds

Results from FreeBSD and Solaris.

# TrueOS 10.0 ( FreeBSD, Perl 5.16.3 ) $ perl foo1.pl | wc -l # Foo::Inbox duration: 0.910 seconds 50000 $ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability duration: 0.875 seconds 50000 $ perl foo2.pl | wc -l # MCE::Shared->queue duration: 1.107 seconds 50000 $ perl foo4.pl | wc -l # Thread::Queue duration: 0.797 seconds 50000 # Solaris 11.2 ( Perl 5.22.2 ) $ perl foo1.pl | wc -l # Foo::Inbox duration: 1.319 seconds 50000 $ perl inbox.pl | wc -l # MCE::Inbox w/ blocking capability duration: 1.344 seconds 50000 $ perl foo2.pl | wc -l # MCE::Shared->queue duration: 1.525 seconds 50000 $ perl foo4.pl | wc -l # Thread::Queue duration: 1.822 seconds 50000

From this testing, Threads + Thread::Queue runs better on FreeBSD and Solaris compared to others.

Foo::Inbox lacks blocking capability, thus has lower latency. However, it may run much slower when the Inbox isn't busy.

Regards, Mario


In reply to Re^2: Child process inter communication by marioroy
in thread Child process inter communication by smarthacker67

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.