Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I've either found a bug, a quirk, or I'm stupid, but I've been banging my head against this issue for two days now, and I finally at least isolated the cause.

I have a server that allows you to connect and make multiple queries on a single socket connection the main loop decides which function to call, the function prints data to the sock and once we return the main loop basically does print {$client} "__END__\n";

Apparently this is bad, and I've created a simple echoing client server pair which illustrate...

#!/idcom/bin/perl use IO::Socket::INET; use Time::HiRes qw( gettimeofday tv_interval ); use strict; our $PORT = 9990; if(fork) { my $s = IO::Socket::INET->new( LocalPort => $PORT, Listen => 5, Re +use => 1 ); my $c = $s->accept(); while(<$c>) { print {$c} $_; } } else { sleep 1; my $s = IO::Socket::INET->new( PeerAddr => 'localhost:'.$PORT ); for(1..5) { my $t0 = [gettimeofday]; print {$s} "func=mbs_descriptive&type=&secid=313627KM2\n"; print "".<$s>; print tv_interval( $t0, [gettimeofday] ),"\n"; } }
When this runs all is great!
func=mbs_descriptive&type=&secid=313627KM2 0.000259 func=mbs_descriptive&type=&secid=313627KM2 5e-05 func=mbs_descriptive&type=&secid=313627KM2 4.3e-05 func=mbs_descriptive&type=&secid=313627KM2 4.2e-05 func=mbs_descriptive&type=&secid=313627KM2 4.2e-05
But if you change that print to the socket to be:
print {$s} "func=mbs_descriptive&type="; print {$s} "&secid=313627KM2\n";
Then sadness and woe befall the code!
func=mbs_descriptive&type=&secid=313627KM2 0.000181 func=mbs_descriptive&type=&secid=313627KM2 0.040125 func=mbs_descriptive&type=&secid=313627KM2 0.04009 func=mbs_descriptive&type=&secid=313627KM2 0.039891 func=mbs_descriptive&type=&secid=313627KM2 0.040025
ARGH! The first call is fast, and every subsequent one has about .4s tacked on for fun, multiply that by 5000 and it starts to really add up. What am I missing here?

                - Ant
                - Some of my best work - (1 2 3)

In reply to Socket slowdown when using two separate print statements by suaveant

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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (3)
    As of 2020-07-07 07:12 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found