Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 22:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found