Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hmmm... a crash-test told me it's still not so trustworthy... Still got lost signals and duplicated responses...

Summary
PID: LOST SIGNALS
5023: 3
5024: 12
5025: 12
5026: 3
5027: 6
5028: 5
5029: 6
5030: 1
5031: 4
5032: 8
parent: 9319
PID: MAX_TIME, MIN_TIME, COUNT, MED
5023: 0.0395898818969727, 2.00271606445312e-05, 997, 0.000217293066868452
5024: 0.0297799110412598, 2.98023223876953e-05, 988, 0.00015578627103736
5025: 0.0275199413299561, -0.00189995765686035, 988, 0.0001988222724513
5026: 0.0194199085235596, 2.98023223876953e-05, 997, 0.000203705599219534
5027: 0.0242300033569336, 2.00271606445312e-05, 994, 0.000233370053696201
5028: 0.0375699996948242, 2.98023223876953e-05, 995, 0.000291356609095281
5029: 0.0186100006103516, 2.98023223876953e-05, 994, 0.000193814636476083
5030: 0.0270700454711914, 2.98023223876953e-05, 999, 0.000180974498286739
5031: 0.0173900127410889, 1.97887420654297e-05, 996, 0.000126030071672187
5032: 0.0372300148010254, 2.98023223876953e-05, 992, 0.000203564522727843
parent: 0.0304899215698242, -0.016819953918457, 10551, 0.000104144584193703

The negative MIN_TIME means that a response was sent before the signal (in a stack)...

Follows the code to do the crash-test...

#!/usr/bin/perl use strict; use warnings; use Time::HiRes 'usleep'; my $num_processes = 10; my $signals_per_process = 1000; $| = 1; my @pids; $SIG{USR2} = sub { print "parent received ".Time::HiRes::time().$/ }; FORKS: while ($num_processes > 0) { my $parent = $$; if (my $pid = fork()) { push @pids, $pid; } else { $SIG{USR1} = sub { print $$." received ".Time::HiRes::time().$ +/; }; while (1) { usleep(rand(20)); print "parent signalled ".Time::HiRes::time().$/; kill('USR2',$parent) or exit; } exit; } $num_processes--; } for (1..$signals_per_process) { PROCESS: foreach my $id (@pids) { print $id." signalled ".Time::HiRes::time().$/; kill("USR1", $id); usleep(rand(20)); } } exit;

And the code to generate the summary:

#!/usr/bin/perl use warnings; use strict; my %data; my %report; while (<STDIN>) { chomp; my ($pid, $op, $time) = split /\s/; if ($op eq 'signalled') { push @{$data{$pid}}, $time; } else { my $sigtime = pop @{$data{$pid}}; push @{$report{$pid}}, $time - $sigtime; } } print "Summary".$/; print "Lost:".$/; foreach my $pid (sort keys %data) { print $pid.": ".scalar(@{$data{$pid}}).$/; } print "Received: ".$/; foreach my $pid (sort keys %report) { my ($min, $max, $count, $sum); foreach my $time (@{$report{$pid}}) { $min = $time if (not defined $min or $min > $time); $max = $time if (not defined $max or $max < $time); $count++; $sum += $time; } print $pid.": $max, $min, $count, ".$sum/$count.$/; }
daniel

In reply to Re^5: Setting signal handlers by ruoso
in thread Setting signal handlers by andyford

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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (3)
    As of 2021-01-24 07:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?