/usr/share/doc/libzeromq-perl/examples/thread_0mq.pl is in libzeromq-perl 0.23-1build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | use strict;
use warnings;
use Config;
use Time::HiRes qw/sleep time/;
use ZeroMQ qw/:all/;
BEGIN {
if ( $Config{useithreads} ) {
# We have threads
require threads;
}
else {
die 'Need threads to test ';
}
}
if (@ARGV != 3) {
die <<HERE;
usage: thread_0mq.pl <connect-to> <message-size> <roundtrip-count>
HERE
}
my $addr = shift @ARGV;
my $msg_size = shift @ARGV;
my $roundtrip_count = shift @ARGV;
my $local_thr = threads->create( \&local );
sub local {
my $cxt = ZeroMQ::Context->new(1);
my $sock = ZeroMQ::Socket->new( $cxt, ZMQ_REP );
print "[local] Trying to start at $addr \n";
$sock->bind($addr);
my $msg;
foreach ( 1 .. $roundtrip_count ) {
#warn "$_\n" if (not $_ % 1000);
$msg = $sock->recv();
die "Bad size" if $msg->size() != $msg_size;
$sock->send($msg);
}
}
sleep 0.1;
my $remote_thr = threads->create( \&remote );
sub remote {
my $cxt = ZeroMQ::Context->new(1);
my $sock = ZeroMQ::Socket->new( $cxt, ZMQ_REQ );
print "[remote] Trying to start at $addr \n";
$sock->connect($addr);
my $text = '0' x $msg_size;
my $msg = ZeroMQ::Message->new($text);
my $before = time();
foreach ( 1 .. $roundtrip_count ) {
#warn "$_\n" if (not $_ % 1000);
$sock->send($msg);
$msg = $sock->recv();
die "Bad size" if $msg->size() != $msg_size;
}
my $after = time();
my $latency = ($after - $before) / ( $roundtrip_count * 2 ) * 1.e6;
print "Latency: $latency us\n";
}
END {
$local_thr->join() if defined $local_thr;
$remote_thr->join() if defined $remote_thr;
}
|