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

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Dear Monks,
I am trying to write a script that will open a TCP socket, perform an HTTP get and display the server replay.
The script should fork and all the children should use the same socket (using HTTP version 1.1 and keep alive). The script below works fine but each process open a new socket which adds unnecessary delay (I am using Time::HiRes to calculate the total time to get 10 pages and save the content).
How can I improve the script so all the forked process wil use the same TCP socket?
Your help please…

#!/usr/bin/perl use LWP::Simple; use Time::HiRes qw(time); use Parallel::ForkManager; my $filename = "/tmp/result.log"; while ($z <=200) { $z++; my $i = 1; my $pm = new Parallel::ForkManager(20); my $t0 = time; my $num = 10; unlink("$filename"); open FH, ">:utf8", $filename; while ($i < $num) { $i++; $pm->start and next; $contents = get("$i"); print FH "$contents\?"; $pm->finish; } $pm->wait_all_children; $elapsed = time - $t0; print "$elapsed elapsed\n"; }

In reply to TCP socket and fork by adismaug

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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (5)
    As of 2018-04-22 07:55 GMT
    Find Nodes?
      Voting Booth?